mikemiles86/bazaarvoice-request

PHP library for making requests to Bazaarvoice API.

1.0.3 2017-07-11 12:18 UTC

This package is auto-updated.

Last update: 2020-05-04 14:46:39 UTC


README

PHP library for making requests to Bazaarvoice APIs

Bazaarvoice Request Library

Latest Version on Packagist Software License Total Downloads

PHP library for making requests to Bazaarvoice APIs and handling responses.

Install

Via Composer

$ composer require mikemiles86/bazaarvoice-request

Usage

Creating a Request

$client = new \GuzzleHttp\Client();
$api_key = '12345abcd';
$bazaarvoice_request = new \BazaarvoiceRequest\BazaarvoiceRequest($client, $api_key);

Making a request


$client = new \GuzzleHttp\Client();
$api_key = '12345abcd';
$bazaarvoice_request = new \BazaarvoiceRequest\BazaarvoiceRequest($client, $api_key);

$reviews = $bazaarvoice_request->apiRequest('data/reviews');

Making a staging request


$client = new \GuzzleHttp\Client();
$api_key = '12345abcd';
$bazaarvoice_request = new \BazaarvoiceRequest\BazaarvoiceRequest($client, $api_key);

$reviews = $bazaarvoice_request->useStage()->apiRequest('data/reviews');

Making a request with additional configurations

$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);

Get values from a response


$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');

Get errors from a response


$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();
}

Testing

$ composer test

Credits

License

The MIT License (MIT). Please see License File for more information.