mikemiles86 / bazaarvoice-request
用于向 Bazaarvoice API 发送请求的 PHP 库。
1.0.4
2022-08-24 17:41 UTC
Requires
- php: >=5.5
- guzzlehttp/guzzle: ~6.0 || ~7.0
Requires (Dev)
- ext-curl: *
- phpunit/phpunit: ^4.0 || ^5.0
This package is auto-updated.
Last update: 2024-09-24 22:06:17 UTC
README
用于向 Bazaarvoice API 发送请求的 PHP 库
Bazaarvoice 请求库
用于向 Bazaarvoice API 发送请求和处理响应的 PHP 库。
安装
通过 Composer
$ composer require mikemiles86/bazaarvoice-request
用法
创建请求
$client = new \GuzzleHttp\Client(); $api_key = '12345abcd'; $bazaarvoice_request = new \BazaarvoiceRequest\BazaarvoiceRequest($client, $api_key);
发送请求
$client = new \GuzzleHttp\Client(); $api_key = '12345abcd'; $bazaarvoice_request = new \BazaarvoiceRequest\BazaarvoiceRequest($client, $api_key); $reviews = $bazaarvoice_request->apiRequest('data/reviews');
发送测试请求
$client = new \GuzzleHttp\Client(); $api_key = '12345abcd'; $bazaarvoice_request = new \BazaarvoiceRequest\BazaarvoiceRequest($client, $api_key); $reviews = $bazaarvoice_request->useStage()->apiRequest('data/reviews');
发送带额外配置的请求
$client = new \GuzzleHttp\Client(); $api_key = '12345abcd'; $bazaarvoice_request = new \BazaarvoiceRequest\BazaarvoiceRequest($client, $api_key); $configuration = [ 'method' => 'POST', 'options' => [ 'headers' => [ 'X-Forwarded-For' => '127.0.0.1', ], ], ]; $reviews = $bazaarvoice_request->apiRequest('data/reviews', $configuration);
$client = new \GuzzleHttp\Client(); $api_key = '12345abcd'; $bazaarvoice_request = new \BazaarvoiceRequest\BazaarvoiceRequest($client, $api_key); $configuration = [ 'arguments' => [ 'ProductId' => 'my_product_123', ], ]; $product_reviews = $bazaarvoice_request->->apiRequest('data/reviews', $configuration);
从响应中获取值
$client = new \GuzzleHttp\Client(); $api_key = '12345abcd'; $bazaarvoice_request = new \BazaarvoiceRequest\BazaarvoiceRequest($client, $api_key); $response = $bazaarvoice_request->useStage()->apiRequest('data/reviews'); $reviews = $response->getResponse('Results');
从响应中获取错误
$client = new \GuzzleHttp\Client(); $api_key = '12345abcd'; $bazaarvoice_request = new \BazaarvoiceRequest\BazaarvoiceRequest($client, $api_key); $response = $bazaarvoice_request->useStage()->apiRequest('data/reviews'); if ($response->getStatusCode() != '200' || $response->hasErrors()) { $errors = $response->getErrors(); }
测试
$ composer test
致谢
许可协议
MIT 许可协议 (MIT)。更多信息请参阅 许可文件。