-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit ddb6dbc
Showing
7 changed files
with
981 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
The BSD 3-Clause License | ||
|
||
Copyright (c) 2022 Leonid Sheikman (leonid74) All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without modification, | ||
are permitted provided that the following conditions are met: | ||
|
||
1. Redistributions of source code must retain the above copyright notice, this | ||
list of conditions and the following disclaimer. | ||
|
||
2. Redistributions in binary form must reproduce the above copyright notice, | ||
this list of conditions and the following disclaimer in the documentation | ||
and/or other materials provided with the distribution. | ||
|
||
3. Neither the name of the copyright holder nor the names of its contributors | ||
may be used to endorse or promote products derived from this software | ||
without specific prior written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | ||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | ||
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, | ||
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | ||
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE | ||
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
OF THE POSSIBILITY OF SUCH DAMAGE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
# (English) Wildberries REST API statistics client library with throttling requests | ||
## Русское описание ниже | ||
|
||
A simple Wildberries REST API statistics client library with throttling requests (for example, no more than 10 requests per second according to API rules) and an example for PHP. | ||
|
||
Statistics API Documentation [Wildberries REST API statistics Documentation](https://images.wbstatic.net/portal/education/Kak_rabotat'_s_servisom_statistiki.pdf) | ||
New API Documentation [Wildberries REST API Documentation](https://suppliers-api.wildberries.ru/swagger/index.html) | ||
|
||
### Installing | ||
|
||
Via Composer: | ||
|
||
```bash | ||
composer require Leonid74/wildberries-api-php | ||
``` | ||
|
||
### Usage | ||
|
||
```php | ||
<?php | ||
require 'vendor/autoload.php'; | ||
|
||
// Without Composer (and instead of "require 'vendor/autoload.php'"): | ||
// require("your-path/wildberries-api-php/src/WbApiInterface.php"); | ||
// require("your-path/wildberries-api-php/src/WbApiClient.php"); | ||
|
||
use Leonid74\Wildberries\WbApiClient; | ||
|
||
require_once 'vendor/autoload.php'; | ||
|
||
$token = '<you token x64>'; | ||
$dateFrom = '01-01-2022'; | ||
$dateTo = '19-01-2022'; | ||
|
||
try { | ||
// Create new client | ||
$WbApiClient = new WbApiClient( $token ); | ||
|
||
// DEBUG level can be one of: DEBUG_NONE (default) or DEBUG_URL, DEBUG_HEADERS, DEBUG_CONTENT | ||
// no debug | ||
// $WbApiClient->debugLevel = WbApiClient::DEBUG_NONE; | ||
// only URL level debug | ||
// $WbApiClient->debugLevel = WbApiClient::DEBUG_URL; | ||
// only HEADERS level debug | ||
// $WbApiClient->debugLevel = WbApiClient::DEBUG_HEADERS; | ||
// max level of debug messages to STDOUT | ||
// $WbApiClient->debugLevel = WbApiClient::DEBUG_CONTENT; | ||
$WbApiClient->debugLevel = WbApiClient::DEBUG_URL; | ||
|
||
// set the trottling of HTTP requests to 2 per second | ||
$WbApiClient->throttle = 2; | ||
} catch ( Exception $e ) { | ||
die( "Critical exception when creating ApiClient: ({$e->getCode()}) " . $e->getMessage() ); | ||
} | ||
|
||
/* | ||
* Example: Get the sales | ||
*/ | ||
$sales = $WbApiClient->sales( $dateFrom ); | ||
if ( isset( $sales->is_error ) ) { | ||
echo "\nError: " . implode( '; ', $sales->errors ); | ||
} else { | ||
var_dump( $sales ); | ||
} | ||
|
||
/* | ||
* Example: Get the report detail by period | ||
*/ | ||
$reportDetailByPeriod = $WbApiClient->reportDetailByPeriod( $dateFrom, $dateTo ); | ||
if ( isset( $reportDetailByPeriod->is_error ) ) { | ||
echo "\nError: " . implode( '; ', $reportDetailByPeriod->errors ); | ||
} else { | ||
var_dump( $reportDetailByPeriod ); | ||
} | ||
|
||
// You can set a common date (dateFrom) via the setDateFrom() function and then access other functions without passing the date | ||
$WbApiClient->setDateFrom( $dateFrom ); | ||
$sales = $WbApiClient->sales(); | ||
$incomes = $WbApiClient->incomes(); | ||
|
||
``` | ||
|
||
# (Russian) Клиентская REST API библиотека статистики Wildberries с регулированием запросов | ||
|
||
Простая клиентская REST API библиотека статистики Wildberries с регулированием запросов (например, не более 10 запросов в секунду в соответствии с правилами API) и примером для PHP. | ||
|
||
Описание API [Wildberries REST API statistics](https://images.wbstatic.net/portal/education/Kak_rabotat'_s_servisom_statistiki.pdf) | ||
Описание нового API [Wildberries REST API](https://suppliers-api.wildberries.ru/swagger/index.html) | ||
|
||
### Установка | ||
|
||
Через Composer: | ||
|
||
```bash | ||
composer require Leonid74/wildberries-api-php | ||
``` | ||
|
||
### Использование | ||
|
||
```php | ||
<?php | ||
require 'vendor/autoload.php'; | ||
|
||
// Без Composer можно подключить вот так (вместо "require 'vendor/autoload.php'"): | ||
// require("your-path/wildberries-api-php/src/WbApiInterface.php"); | ||
// require("your-path/wildberries-api-php/src/WbApiClient.php"); | ||
|
||
use Leonid74\Wildberries\WbApiClient; | ||
|
||
require_once 'vendor/autoload.php'; | ||
|
||
$token = '<Ваш токен партнера x64>'; | ||
$dateFrom = '01-01-2022'; | ||
$dateTo = '19-01-2022'; | ||
|
||
try { | ||
// Создаем новый клиент | ||
$WbApiClient = new WbApiClient( $token ); | ||
|
||
// Уровень DEBUG может быть одним из: DEBUG_NONE (по умолчанию) или DEBUG_URL, DEBUG_HEADERS, DEBUG_CONTENT | ||
// без вывода отладочной информации | ||
// $WbApiClient->debugLevel = WbApiClient::DEBUG_NONE; | ||
// выводим только URL запросов/ответов | ||
// $WbApiClient->debugLevel = WbApiClient::DEBUG_URL; | ||
// выводим только URL и заголовки запросов/ответов | ||
// $WbApiClient->debugLevel = WbApiClient::DEBUG_HEADERS; | ||
// выводим URL, заголовки и всю остальную информацию запросов/ответов в STDOUT | ||
// $WbApiClient->debugLevel = WbApiClient::DEBUG_CONTENT; | ||
$WbApiClient->debugLevel = WbApiClient::DEBUG_URL; | ||
|
||
// Устанавливаем троттлинг в 2 запроса в секунду | ||
$WbApiClient->throttle = 2; | ||
} catch ( Exception $e ) { | ||
die( "Критическая ошибка при создании ApiClient: ({$e->getCode()}) " . $e->getMessage() ); | ||
} | ||
|
||
/* | ||
* Пример: Получаем продажи | ||
*/ | ||
$sales = $WbApiClient->sales( $dateFrom ); | ||
if ( isset( $sales->is_error ) ) { | ||
echo "\nError: " . implode( '; ', $sales->errors ); | ||
} else { | ||
var_dump( $sales ); | ||
} | ||
|
||
/* | ||
* Пример: Получаем отчет о продажах по реализации | ||
*/ | ||
$reportDetailByPeriod = $WbApiClient->reportDetailByPeriod( $dateFrom, $dateTo ); | ||
if ( isset( $reportDetailByPeriod->is_error ) ) { | ||
echo "\nError: " . implode( '; ', $reportDetailByPeriod->errors ); | ||
} else { | ||
var_dump( $reportDetailByPeriod ); | ||
} | ||
|
||
// Можно задать общую дату (dateFrom) через функцию setDateFrom() и затем обращаться к другим функциям, не передавая дату | ||
$WbApiClient->setDateFrom( $dateFrom ); | ||
$sales = $WbApiClient->sales(); | ||
$incomes = $WbApiClient->incomes(); | ||
|
||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
{ | ||
"name": "leonid74/wildberries-api-php", | ||
"type": "library", | ||
"description": "Wildberries REST API statistics client library with throttling requests", | ||
"keywords": [ | ||
"Wildberries", | ||
"WB", | ||
"rest", | ||
"api", | ||
"sdk", | ||
"client", | ||
"stat", | ||
"statistics" | ||
], | ||
"homepage": "https://github.com/leonid74/wildberries-api-php", | ||
"license": "BSD-3-Clause", | ||
"authors": [ | ||
{ | ||
"name": "leonid74", | ||
"homepage": "https://github.com/leonid74/", | ||
"role": "Developer" | ||
} | ||
], | ||
"require": { | ||
"php": ">=7.4", | ||
"ext-curl": "*", | ||
"ext-json": "*", | ||
"josantonius/httpstatuscode": "^1.1" | ||
}, | ||
"require-dev": { | ||
"automattic/phpcs-neutron-standard": "^1.7", | ||
"dealerdirect/phpcodesniffer-composer-installer": "^0.7.1", | ||
"phpunit/phpunit": "^9", | ||
"squizlabs/php_codesniffer": "^3.5" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Leonid74\\Wildberries\\": "src/" | ||
} | ||
}, | ||
"scripts": { | ||
"post-update-cmd": [ | ||
"@composer dump-autoload" | ||
], | ||
"check-code": [ | ||
"phpcs -sp src/ tests/" | ||
], | ||
"tests": [ | ||
"@php vendor/bin/phpunit tests" | ||
] | ||
}, | ||
"config": { | ||
"process-timeout": 0, | ||
"sort-packages": true, | ||
"optimize-autoloader": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
/** | ||
* Wildberries REST API Client Usage Example | ||
* | ||
* @see Wildberries REST API statistics Documentation | ||
* (https://images.wbstatic.net/portal/education/Kak_rabotat'_s_servisom_statistiki.pdf) | ||
* @see Wildberries REST API Documentation | ||
* (https://suppliers-api.wildberries.ru/swagger/index.html) | ||
* | ||
* @author Leonid74 [email protected] | ||
*/ | ||
|
||
use Leonid74\Wildberries\WbApiClient; | ||
|
||
require_once 'vendor/autoload.php'; | ||
|
||
$token = '<you token x64>'; | ||
$dateFrom = '01-01-2022'; | ||
$dateTo = '19-01-2022'; | ||
|
||
try { | ||
$WbApiClient = new WbApiClient( $token ); | ||
$WbApiClient->debugLevel = WbApiClient::DEBUG_URL; | ||
$WbApiClient->throttle = 2; | ||
} catch ( Exception $e ) { | ||
die( "Критическая ошибка при создании ApiClient: ({$e->getCode()}) " . $e->getMessage() ); | ||
} | ||
|
||
$sales = $WbApiClient->sales( $dateFrom ); | ||
if ( isset( $sales->is_error ) ) { | ||
echo "\nError: " . implode( '; ', $sales->errors ); | ||
} else { | ||
var_dump( $sales ); | ||
} | ||
|
||
$reportDetailByPeriod = $WbApiClient->reportDetailByPeriod( $dateFrom, $dateTo ); | ||
if ( isset( $reportDetailByPeriod->is_error ) ) { | ||
echo "\nError: " . implode( '; ', $reportDetailByPeriod->errors ); | ||
} else { | ||
var_dump( $reportDetailByPeriod ); | ||
} | ||
|
||
// You can set a common date (dateFrom) via the setDateFrom() function and then access other functions without passing the date | ||
// Можно задать общую дату (dateFrom) через функцию setDateFrom() и затем обращаться к другим функциям, не передавая дату | ||
$WbApiClient->setDateFrom( $dateFrom ); | ||
$sales = $WbApiClient->sales(); | ||
$incomes = $WbApiClient->incomes(); |
Oops, something went wrong.