You are here

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

Gets information about an item, or array of items, from Amazon.

Parameters

array|string $items: A string containing a single ASIN, or an array of ASINs, to look up.

Return value

array An array of SimpleXMLElement objects representing the response from Amazon.

File

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

Class

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

Namespace

Drupal\amazon

Code

public function lookup($items) {
  if (empty($items)) {
    throw new \InvalidArgumentException('Calling lookup without anything to lookup!');
  }
  if (!is_array($items)) {
    $items = [
      $items,
    ];
  }
  $results = [];

  // Cannot ask for info from more than 10 items in a single call.
  foreach (array_chunk($items, 10) as $asins) {
    $lookup = new Lookup();
    $lookup
      ->setItemIds($asins);
    $lookup
      ->setResponseGroup([
      'Small',
      'Images',
    ]);
    $results = array_merge($results, $this->apaiIO
      ->runOperation($lookup));
  }
  return $results;
}