Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"name": "marcl/amazonproductapi",
"description": "PHP library to perform product lookup and searches using the Amazon Product API.",
"version": "3.0.1",
"description":
"PHP library to perform product lookup and searches using the Amazon Product API.",
"version": "3.0.2",
"type": "library",
"keywords": ["amazon", "product", "api"],
"homepage": "https://github.com/MarcL/AmazonProductAPI/",
Expand Down Expand Up @@ -31,4 +32,5 @@
"MarcL\\": "src/",
"tests\\": "tests/"
}
}}
}
}
9 changes: 9 additions & 0 deletions examples.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,13 @@
$items = $amazonAPI->ItemLookUp('B01GAGVIE4', true);
print('>> Look up specific ASIN\n');
var_dump($items);

sleep($sleepTime);

// Amazon echo, lookup with incorrect ASIN array
$asinIds = array('INVALID', 'INVALIDASIN', 'NOTANASIN');
$items = $amazonAPI->ItemLookUp($asinIds, true);
print('>> Look up specific ASIN\n');
var_dump($items);
var_dump($amazonAPI->GetErrors());
?>
11 changes: 6 additions & 5 deletions src/AmazonAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,16 @@ private function MakeAndParseRequest($params) {
$response = $request->execute($signedUrl);

$parsedXml = simplexml_load_string($response);

if ($parsedXml === false) {
return false;
}

return $this->dataTransformer->execute($parsedXml);
} catch(\Exception $error) {
$this->AddError("Error downloading data : $signedUrl : " . $error->getMessage());
}

if ($parsedXml === false) {
return false;
}

return $this->dataTransformer->execute($parsedXml);
}
}
?>
12 changes: 5 additions & 7 deletions src/Transformers/SimpleArrayTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,18 @@ class SimpleArrayTransformer implements IDataTransformer {
public function execute($xmlData) {
$items = array();
if (empty($xmlData)) {
$this->AddError("No XML response found from AWS.");
return($items);
throw new \Exception("No XML response found from AWS.");
}

if (empty($xmlData->Items)) {
$this->AddError("No items found.");
return($items);
}

if ($xmlData->Items->Request->IsValid != 'True') {
$errorCode = $xmlData->Items->Request->Errors->Error->Code;
$errorMessage = $xmlData->Items->Request->Errors->Error->Message;
$error = "API ERROR ($errorCode) : $errorMessage";
$this->AddError($error);
return($items);
throw new \Exception($error);
}

// Get each item
Expand All @@ -48,7 +45,8 @@ public function execute($xmlData) {
array_push($items, $item);
}

return($items); }
return($items);
}
}

?>
?>