You are here

public function Amazon::__construct in Amazon Product Advertisement API 8.2

Provides an Amazon object for calling the Amazon API.

Parameters

string $associatesId: The Amazon Associates ID (a.k.a. tag).

string $accessKey: (optional) Access key to use for all API requests. If not specified, the access key is determined from other system variables.

string $accessSecret: (optional) Access secret to use for all API requests. If not specified, the access key is determined from other system variables.

string $locale: (optional) Which locale to run queries against. Valid values include: de, com, co.uk, ca, fr, co.jp, it, cn, es, in.

File

src/Amazon.php, line 49
Contains Drupal\amazon\Amazon

Class

Amazon
Provides methods that interfaces with the Amazon Product Advertising API.

Namespace

Drupal\amazon

Code

public function __construct($associatesId, $accessKey = '', $accessSecret = '', $locale = 'com') {
  if (empty($accessKey)) {
    $accessKey = self::getAccessKey();
    if (!$accessKey) {
      throw new \InvalidArgumentException('Configuration missing: Amazon access key.');
    }
  }
  if (empty($accessSecret)) {
    $accessSecret = self::getAccessSecret();
    if (!$accessSecret) {
      throw new \InvalidArgumentException('Configuration missing: Amazon access secret.');
    }
  }
  $conf = new GenericConfiguration();
  $conf
    ->setCountry($locale)
    ->setAccessKey($accessKey)
    ->setSecretKey($accessSecret)
    ->setAssociateTag($associatesId)
    ->setResponseTransformer('\\Drupal\\amazon\\LookupXmlToItemsArray');
  $this->apaiIO = new ApaiIO($conf);
}