18 | * @link http://github.com/Exeu/Amazon-ECS-PHP-Library/wiki Wiki
19 | * @link http://github.com/Exeu/Amazon-ECS-PHP-Library Source
20 | */
21 | class AmazonECS
22 | {
23 | const RETURN_TYPE_ARRAY = 1;
24 | const RETURN_TYPE_OBJECT = 2;
25 |
26 | /**
27 | * Baseconfigurationstorage
28 | *
29 | * @var array
30 | */
31 | private $requestConfig = array(
32 | 'requestDelay' => false
33 | );
34 |
35 | /**
36 | * Responseconfigurationstorage
37 | *
38 | * @var array
39 | */
40 | private $responseConfig = array(
41 | 'returnType' => self::RETURN_TYPE_OBJECT,
42 | 'responseGroup' => 'Small',
43 | 'optionalParameters' => array()
44 | );
45 |
46 | /**
47 | * All possible locations
48 | *
49 | * @var array
50 | */
51 | private $possibleLocations = array('de', 'com', 'co.uk', 'ca', 'fr', 'co.jp', 'it', 'cn', 'es');
52 |
53 | /**
54 | * The WSDL File
55 | *
56 | * @var string
57 | */
58 | protected $webserviceWsdl = 'http://webservices.amazon.com/AWSECommerceService/AWSECommerceService.wsdl';
59 |
60 | /**
61 | * The SOAP Endpoint
62 | *
63 | * @var string
64 | */
65 | protected $webserviceEndpoint = 'https://webservices.amazon.%%COUNTRY%%/onca/soap?Service=AWSECommerceService';
66 |
67 | /**
68 | * @param string $accessKey
69 | * @param string $secretKey
70 | * @param string $country
71 | * @param string $associateTag
72 | */
73 | public function __construct($accessKey, $secretKey, $country, $associateTag)
74 | {
75 | if (empty($accessKey) || empty($secretKey))
76 | {
77 | throw new Exception('No Access Key or Secret Key has been set');
78 | }
79 |
80 | $this->requestConfig['accessKey'] = $accessKey;
81 | $this->requestConfig['secretKey'] = $secretKey;
82 | $this->associateTag($associateTag);
83 | $this->country($country);
84 | }
85 |
86 | /**
87 | * execute search
88 | *
89 | * @param string $pattern
90 | *
91 | * @return array|object return type depends on setting
92 | *
93 | * @see returnType()
94 | */
95 | public function search($pattern, $nodeId = null)
96 | {
97 | if (false === isset($this->requestConfig['category']))
98 | {
99 | throw new Exception('No Category given: Please set it up before');
100 | }
101 |
102 | $browseNode = array();
103 | if (null !== $nodeId && true === $this->validateNodeId($nodeId))
104 | {
105 | $browseNode = array('BrowseNode' => $nodeId);
106 | }
107 |
108 | $params = $this->buildRequestParams('ItemSearch', array_merge(
109 | array(
110 | 'Keywords' => $pattern,
111 | 'SearchIndex' => $this->requestConfig['category']
112 | ),
113 | $browseNode
114 | ));
115 |
116 | return $this->returnData(
117 | $this->performSoapRequest("ItemSearch", $params)
118 | );
119 | }
120 |
121 | /**
122 | * execute ItemLookup request
123 | *
124 | * @param string $asin
125 | *
126 | * @return array|object return type depends on setting
127 | *
128 | * @see returnType()
129 | */
130 | public function lookup($asin)
131 | {
132 | $params = $this->buildRequestParams('ItemLookup', array(
133 | 'ItemId' => $asin,
134 | ));
135 |
136 | return $this->returnData(
137 | $this->performSoapRequest("ItemLookup", $params)
138 | );
139 | }
140 |
141 | /**
142 | * Implementation of BrowseNodeLookup
143 | * This allows to fetch information about nodes (children anchestors, etc.)
144 | *
145 | * @param integer $nodeId
146 | */
147 | public function browseNodeLookup($nodeId)
148 | {
149 | $this->validateNodeId($nodeId);
150 |
151 | $params = $this->buildRequestParams('BrowseNodeLookup', array(
152 | 'BrowseNodeId' => $nodeId
153 | ));
154 |
155 | return $this->returnData(
156 | $this->performSoapRequest("BrowseNodeLookup", $params)
157 | );
158 | }
159 |
160 | /**
161 | * Implementation of SimilarityLookup
162 | * This allows to fetch information about product related to the parameter product
163 | *
164 | * @param string $asin
165 | */
166 | public function similarityLookup($asin)
167 | {
168 | $params = $this->buildRequestParams('SimilarityLookup', array(
169 | 'ItemId' => $asin
170 | ));
171 |
172 | return $this->returnData(
173 | $this->performSoapRequest("SimilarityLookup", $params)
174 | );
175 | }
176 |
177 | /**
178 | * Builds the request parameters
179 | *
180 | * @param string $function
181 | * @param array $params
182 | *
183 | * @return array
184 | */
185 | protected function buildRequestParams($function, array $params)
186 | {
187 | $associateTag = array();
188 |
189 | if(false === empty($this->requestConfig['associateTag']))
190 | {
191 | $associateTag = array('AssociateTag' => $this->requestConfig['associateTag']);
192 | }
193 |
194 | return array_merge(
195 | $associateTag,
196 | array(
197 | 'AWSAccessKeyId' => $this->requestConfig['accessKey'],
198 | 'Request' => array_merge(
199 | array('Operation' => $function),
200 | $params,
201 | $this->responseConfig['optionalParameters'],
202 | array('ResponseGroup' => $this->prepareResponseGroup())
203 | )));
204 | }
205 |
206 | /**
207 | * Prepares the responsegroups and returns them as array
208 | *
209 | * @return array|prepared responsegroups
210 | */
211 | protected function prepareResponseGroup()
212 | {
213 | if (false === strstr($this->responseConfig['responseGroup'], ','))
214 | return $this->responseConfig['responseGroup'];
215 |
216 | return explode(',', $this->responseConfig['responseGroup']);
217 | }
218 |
219 | /**
220 | * @param string $function Name of the function which should be called
221 | * @param array $params Requestparameters 'ParameterName' => 'ParameterValue'
222 | *
223 | * @return array The response as an array with stdClass objects
224 | */
225 | protected function performSoapRequest($function, $params)
226 | {
227 | if (true === $this->requestConfig['requestDelay']) {
228 | sleep(1);
229 | }
230 |
231 | $soapClient = new SoapClient(
232 | $this->webserviceWsdl,
233 | array('exceptions' => 1)
234 | );
235 |
236 | $soapClient->__setLocation(str_replace(
237 | '%%COUNTRY%%',
238 | $this->responseConfig['country'],
239 | $this->webserviceEndpoint
240 | ));
241 |
242 | $soapClient->__setSoapHeaders($this->buildSoapHeader($function));
243 |
244 | return $soapClient->__soapCall($function, array($params));
245 | }
246 |
247 | /**
248 | * Provides some necessary soap headers
249 | *
250 | * @param string $function
251 | *
252 | * @return array Each element is a concrete SoapHeader object
253 | */
254 | protected function buildSoapHeader($function)
255 | {
256 | $timeStamp = $this->getTimestamp();
257 | $signature = $this->buildSignature($function . $timeStamp);
258 |
259 | return array(
260 | new SoapHeader(
261 | 'http://security.amazonaws.com/doc/2007-01-01/',
262 | 'AWSAccessKeyId',
263 | $this->requestConfig['accessKey']
264 | ),
265 | new SoapHeader(
266 | 'http://security.amazonaws.com/doc/2007-01-01/',
267 | 'Timestamp',
268 | $timeStamp
269 | ),
270 | new SoapHeader(
271 | 'http://security.amazonaws.com/doc/2007-01-01/',
272 | 'Signature',
273 | $signature
274 | )
275 | );
276 | }
277 |
278 | /**
279 | * provides current gm date
280 | *
281 | * primary needed for the signature
282 | *
283 | * @return string
284 | */
285 | final protected function getTimestamp()
286 | {
287 | return gmdate("Y-m-d\TH:i:s\Z");
288 | }
289 |
290 | /**
291 | * provides the signature
292 | *
293 | * @return string
294 | */
295 | final protected function buildSignature($request)
296 | {
297 | return base64_encode(hash_hmac("sha256", $request, $this->requestConfig['secretKey'], true));
298 | }
299 |
300 | /**
301 | * Basic validation of the nodeId
302 | *
303 | * @param integer $nodeId
304 | *
305 | * @return boolean
306 | */
307 | final protected function validateNodeId($nodeId)
308 | {
309 | if (false === is_numeric($nodeId) || $nodeId <= 0)
310 | {
311 | throw new InvalidArgumentException(sprintf('Node has to be a positive Integer.'));
312 | }
313 |
314 | return true;
315 | }
316 |
317 | /**
318 | * Returns the response either as Array or Array/Object
319 | *
320 | * @param object $object
321 | *
322 | * @return mixed
323 | */
324 | protected function returnData($object)
325 | {
326 | switch ($this->responseConfig['returnType'])
327 | {
328 | case self::RETURN_TYPE_OBJECT:
329 | return $object;
330 | break;
331 |
332 | case self::RETURN_TYPE_ARRAY:
333 | return $this->objectToArray($object);
334 | break;
335 |
336 | default:
337 | throw new InvalidArgumentException(sprintf(
338 | "Unknwon return type %s", $this->responseConfig['returnType']
339 | ));
340 | break;
341 | }
342 | }
343 |
344 | /**
345 | * Transforms the responseobject to an array
346 | *
347 | * @param object $object
348 | *
349 | * @return array An arrayrepresentation of the given object
350 | */
351 | protected function objectToArray($object)
352 | {
353 | $out = array();
354 | foreach ($object as $key => $value)
355 | {
356 | switch (true)
357 | {
358 | case is_object($value):
359 | $out[$key] = $this->objectToArray($value);
360 | break;
361 |
362 | case is_array($value):
363 | $out[$key] = $this->objectToArray($value);
364 | break;
365 |
366 | default:
367 | $out[$key] = $value;
368 | break;
369 | }
370 | }
371 |
372 | return $out;
373 | }
374 |
375 | /**
376 | * set or get optional parameters
377 | *
378 | * if the argument params is null it will reutrn the current parameters,
379 | * otherwise it will set the params and return itself.
380 | *
381 | * @param array $params the optional parameters
382 | *
383 | * @return array|AmazonECS depends on params argument
384 | */
385 | public function optionalParameters($params = null)
386 | {
387 | if (null === $params)
388 | {
389 | return $this->responseConfig['optionalParameters'];
390 | }
391 |
392 | if (false === is_array($params))
393 | {
394 | throw new InvalidArgumentException(sprintf(
395 | "%s is no valid parameter: Use an array with Key => Value Pairs", $params
396 | ));
397 | }
398 |
399 | $this->responseConfig['optionalParameters'] = $params;
400 |
401 | return $this;
402 | }
403 |
404 | /**
405 | * Set or get the country
406 | *
407 | * if the country argument is null it will return the current
408 | * country, otherwise it will set the country and return itself.
409 | *
410 | * @param string|null $country
411 | *
412 | * @return string|AmazonECS depends on country argument
413 | */
414 | public function country($country = null)
415 | {
416 | if (null === $country)
417 | {
418 | return $this->responseConfig['country'];
419 | }
420 |
421 | if (false === in_array(strtolower($country), $this->possibleLocations))
422 | {
423 | throw new InvalidArgumentException(sprintf(
424 | "Invalid Country-Code: %s! Possible Country-Codes: %s",
425 | $country,
426 | implode(', ', $this->possibleLocations)
427 | ));
428 | }
429 |
430 | $this->responseConfig['country'] = strtolower($country);
431 |
432 | return $this;
433 | }
434 |
435 | /**
436 | * Setting/Getting the amazon category
437 | *
438 | * @param string $category
439 | *
440 | * @return string|AmazonECS depends on category argument
441 | */
442 | public function category($category = null)
443 | {
444 | if (null === $category)
445 | {
446 | return isset($this->requestConfig['category']) ? $this->requestConfig['category'] : null;
447 | }
448 |
449 | $this->requestConfig['category'] = $category;
450 |
451 | return $this;
452 | }
453 |
454 | /**
455 | * Setting/Getting the responsegroup
456 | *
457 | * @param string $responseGroup Comma separated groups
458 | *
459 | * @return string|AmazonECS depends on responseGroup argument
460 | */
461 | public function responseGroup($responseGroup = null)
462 | {
463 | if (null === $responseGroup)
464 | {
465 | return $this->responseConfig['responseGroup'];
466 | }
467 |
468 | $this->responseConfig['responseGroup'] = $responseGroup;
469 |
470 | return $this;
471 | }
472 |
473 | /**
474 | * Setting/Getting the returntype
475 | * It can be an object or an array
476 | *
477 | * @param integer $type Use the constants RETURN_TYPE_ARRAY or RETURN_TYPE_OBJECT
478 | *
479 | * @return integer|AmazonECS depends on type argument
480 | */
481 | public function returnType($type = null)
482 | {
483 | if (null === $type)
484 | {
485 | return $this->responseConfig['returnType'];
486 | }
487 |
488 | $this->responseConfig['returnType'] = $type;
489 |
490 | return $this;
491 | }
492 |
493 | /**
494 | * Setter/Getter of the AssociateTag.
495 | * This could be used for late bindings of this attribute
496 | *
497 | * @param string $associateTag
498 | *
499 | * @return string|AmazonECS depends on associateTag argument
500 | */
501 | public function associateTag($associateTag = null)
502 | {
503 | if (null === $associateTag)
504 | {
505 | return $this->requestConfig['associateTag'];
506 | }
507 |
508 | $this->requestConfig['associateTag'] = $associateTag;
509 |
510 | return $this;
511 | }
512 |
513 | /**
514 | * @deprecated use returnType() instead
515 | */
516 | public function setReturnType($type)
517 | {
518 | return $this->returnType($type);
519 | }
520 |
521 | /**
522 | * Setting the resultpage to a specified value.
523 | * Allows to browse resultsets which have more than one page.
524 | *
525 | * @param integer $page
526 | *
527 | * @return AmazonECS
528 | */
529 | public function page($page)
530 | {
531 | if (false === is_numeric($page) || $page <= 0)
532 | {
533 | throw new InvalidArgumentException(sprintf(
534 | '%s is an invalid page value. It has to be numeric and positive',
535 | $page
536 | ));
537 | }
538 |
539 | $this->responseConfig['optionalParameters'] = array_merge(
540 | $this->responseConfig['optionalParameters'],
541 | array("ItemPage" => $page)
542 | );
543 |
544 | return $this;
545 | }
546 |
547 | /**
548 | * Enables or disables the request delay.
549 | * If it is enabled (true) every request is delayed one second to get rid of the api request limit.
550 | *
551 | * Reasons for this you can read on this site:
552 | * https://affiliate-program.amazon.com/gp/advertising/api/detail/faq.html
553 | *
554 | * By default the requestdelay is disabled
555 | *
556 | * @param boolean $enable true = enabled, false = disabled
557 | *
558 | * @return boolean|AmazonECS depends on enable argument
559 | */
560 | public function requestDelay($enable = null)
561 | {
562 | if (false === is_null($enable) && true === is_bool($enable))
563 | {
564 | $this->requestConfig['requestDelay'] = $enable;
565 |
566 | return $this;
567 | }
568 |
569 | return $this->requestConfig['requestDelay'];
570 | }
571 | }
--------------------------------------------------------------------------------
/samples/sampleAssociateTag.php:
--------------------------------------------------------------------------------
1 | = 1.0 of the AmazonECS library
4 | */
5 |
6 | /**
7 | * For a running Search Demo see: http://amazonecs.pixel-web.org
8 | */
9 |
10 | if ("cli" !== PHP_SAPI)
11 | {
12 | echo "";
13 | }
14 |
15 | if (is_file('sampleSettings.php'))
16 | {
17 | include 'sampleSettings.php';
18 | }
19 |
20 | defined('AWS_API_KEY') or define('AWS_API_KEY', 'API KEY');
21 | defined('AWS_API_SECRET_KEY') or define('AWS_API_SECRET_KEY', 'SECRET KEY');
22 | defined('AWS_ASSOCIATE_TAG') or define('AWS_ASSOCIATE_TAG', 'ASSOCIATE TAG');
23 | defined('AWS_ANOTHER_ASSOCIATE_TAG') or define('AWS_ANOTHER_ASSOCIATE_TAG', 'ANOTHER ASSOCIATE TAG');
24 |
25 | require '../lib/AmazonECS.class.php';
26 |
27 | try
28 | {
29 | // get a new object with your API Key and secret key.
30 |
31 | // Added in version 1.0 is the new optional parameter to set up an AssociateTag (AssociateID)
32 | $amazonEcs = new AmazonECS(AWS_API_KEY, AWS_API_SECRET_KEY, 'DE', AWS_ASSOCIATE_TAG);
33 |
34 | /**
35 | * Now you can work the normal way with the class with the difference
36 | * that every URL in the response contains your AssociateTag
37 | */
38 |
39 | $response = $amazonEcs->category('DVD')->responseGroup('Large')->search("Matrix Revolutions");
40 | //var_dump($response);
41 |
42 | // searching again
43 | $response = $amazonEcs->search('Bud Spencer');
44 | //var_dump($response);
45 |
46 | // Use the new Setter to update your AssociateTag on the fly
47 | $response = $amazonEcs->associateTag(AWS_ANOTHER_ASSOCIATE_TAG)->search('Bud Spencer');
48 | //var_dump($response);
49 |
50 |
51 | // For more examples please look at testItemSearch.php and testItemLookup.php
52 | // These examples also could be used with the AssociateTag
53 | }
54 | catch(Exception $e)
55 | {
56 | echo $e->getMessage();
57 | }
58 |
59 | if ("cli" !== PHP_SAPI)
60 | {
61 | echo "
";
62 | }
63 |
--------------------------------------------------------------------------------
/samples/sampleBrowseNode.php:
--------------------------------------------------------------------------------
1 | ";
9 | }
10 |
11 |
12 | if (is_file('sampleSettings.php'))
13 | {
14 | include 'sampleSettings.php';
15 | }
16 |
17 | defined('AWS_API_KEY') or define('AWS_API_KEY', 'API KEY');
18 | defined('AWS_API_SECRET_KEY') or define('AWS_API_SECRET_KEY', 'SECRET KEY');
19 | defined('AWS_ASSOCIATE_TAG') or define('AWS_ASSOCIATE_TAG', 'ASSOCIATE TAG');
20 |
21 | require '../lib/AmazonECS.class.php';
22 |
23 | try
24 | {
25 | $amazonEcs = new AmazonECS(AWS_API_KEY, AWS_API_SECRET_KEY, 'DE', AWS_ASSOCIATE_TAG);
26 |
27 | // for the new version of the wsdl its required to provide a associate Tag
28 | // @see https://affiliate-program.amazon.com/gp/advertising/api/detail/api-changes.html?ie=UTF8&pf_rd_t=501&ref_=amb_link_83957571_2&pf_rd_m=ATVPDKIKX0DER&pf_rd_p=&pf_rd_s=assoc-center-1&pf_rd_r=&pf_rd_i=assoc-api-detail-2-v2
29 | // you can set it with the setter function or as the fourth paramameter of ther constructor above
30 | $amazonEcs->associateTag(AWS_ASSOCIATE_TAG);
31 |
32 | // First of all you have to set an another ResponseGroup. If not the request would not be successful
33 | // Possible Responsegroups: BrowseNodeInfo,MostGifted,NewReleases,MostWishedFor,TopSellers
34 | $amazonEcs->responseGroup('BrowseNodeInfo');
35 |
36 | // Then browse a node like this: nodeId (See: http://docs.amazonwebservices.com/AWSECommerceService/2010-09-01/DG/index.html?BrowseNodeIDs.html)
37 | // For example: 542064 on German Amazon is: Software
38 | $response = $amazonEcs->browseNodeLookup(542064);
39 | //var_dump($response);
40 |
41 | // The response contains now some information about this Node and its children, ancestors etc.
42 | // So we picked out one noteId of the childelements: 408306 -> Programmierung (Programming).
43 | // Now we want to browse this node
44 | $response = $amazonEcs->browseNodeLookup(408306);
45 | //var_dump($response);
46 |
47 | // Picking out one childNodeId again
48 | // 466484 -> Programmiersprachen (Programming languages)
49 | $response = $amazonEcs->browseNodeLookup(466484);
50 | //var_dump($response);
51 |
52 | // I think its enough now.. the basics should be clear. You can browse deeper and deeper this way.
53 | // Now we want to display the TopSellers in this node.
54 | // So we have to change the responseGroup.
55 | $response = $amazonEcs->responseGroup('BrowseNodeInfo,TopSellers')->browseNodeLookup(466484);
56 | //var_dump($response);
57 |
58 | // This is compatible with the associateTag feature. Feel free to use it here.
59 | $response = $amazonEcs->associateTag(AWS_ASSOCIATE_TAG)->browseNodeLookup(466484);
60 | //var_dump($response);
61 |
62 | // At this moment when i'm writing this this ASIN: 383621640X is the TopSeller in this Node
63 | // So i want to fetch all Infos about it.
64 | // I have to set back my responseGroup to e.g. Large then starting the lookup request:
65 | $response = $amazonEcs->responseGroup('Large')->lookup('383621640X');
66 | //var_dump($response);
67 |
68 | // If you want to use a nodeId combined with your search operation you can add the nodeId as parameter:
69 | // It is necessary to provide a category first.
70 | $response = $amazonEcs->category('Software')->responseGroup('Large')->search('PHP 5', 466484);
71 | //var_dump($response);
72 |
73 | // Searching something and returning some nodes found for this keyword.
74 | $response = $amazonEcs->responseGroup('BrowseNodes')->search('Visual Studio');
75 | //var_dump($response);
76 | }
77 | catch(Exception $e)
78 | {
79 | echo $e->getMessage();
80 | }
81 |
82 | if ("cli" !== PHP_SAPI)
83 | {
84 | echo "";
85 | }
86 |
--------------------------------------------------------------------------------
/samples/sampleItemLookup.php:
--------------------------------------------------------------------------------
1 | ";
9 | }
10 |
11 |
12 | if (is_file('sampleSettings.php'))
13 | {
14 | include 'sampleSettings.php';
15 | }
16 |
17 | defined('AWS_API_KEY') or define('AWS_API_KEY', 'API KEY');
18 | defined('AWS_API_SECRET_KEY') or define('AWS_API_SECRET_KEY', 'SECRET KEY');
19 | defined('AWS_ASSOCIATE_TAG') or define('AWS_ASSOCIATE_TAG', 'ASSOCIATE TAG');
20 |
21 | require '../lib/AmazonECS.class.php';
22 |
23 | try
24 | {
25 | $amazonEcs = new AmazonECS(AWS_API_KEY, AWS_API_SECRET_KEY, 'DE', AWS_ASSOCIATE_TAG);
26 |
27 | // for the new version of the wsdl its required to provide a associate Tag
28 | // @see https://affiliate-program.amazon.com/gp/advertising/api/detail/api-changes.html?ie=UTF8&pf_rd_t=501&ref_=amb_link_83957571_2&pf_rd_m=ATVPDKIKX0DER&pf_rd_p=&pf_rd_s=assoc-center-1&pf_rd_r=&pf_rd_i=assoc-api-detail-2-v2
29 | // you can set it with the setter function or as the fourth paramameter of ther constructor above
30 | $amazonEcs->associateTag(AWS_ASSOCIATE_TAG);
31 |
32 | // Looking up multiple items
33 | $response = $amazonEcs->responseGroup('Large')->optionalParameters(array('Condition' => 'New'))->lookup('B0017TZY5Y, B004DULNPY');
34 | //var_dump($response);
35 |
36 | $response = $amazonEcs->responseGroup('Images')->lookup('B0017TZY5Y');
37 | //var_dump($response);
38 |
39 | }
40 | catch(Exception $e)
41 | {
42 | echo $e->getMessage();
43 | }
44 |
45 | if ("cli" !== PHP_SAPI)
46 | {
47 | echo "";
48 | }
49 |
--------------------------------------------------------------------------------
/samples/sampleItemSearch.php:
--------------------------------------------------------------------------------
1 | ";
9 | }
10 |
11 | if (is_file('sampleSettings.php'))
12 | {
13 | include 'sampleSettings.php';
14 | }
15 |
16 | defined('AWS_API_KEY') or define('AWS_API_KEY', 'API KEY');
17 | defined('AWS_API_SECRET_KEY') or define('AWS_API_SECRET_KEY', 'SECRET KEY');
18 | defined('AWS_ASSOCIATE_TAG') or define('AWS_ASSOCIATE_TAG', 'ASSOCIATE TAG');
19 |
20 | require '../lib/AmazonECS.class.php';
21 |
22 | try
23 | {
24 | // get a new object with your API Key and secret key. Lang is optional.
25 | // if you leave lang blank it will be US.
26 | $amazonEcs = new AmazonECS(AWS_API_KEY, AWS_API_SECRET_KEY, 'de', AWS_ASSOCIATE_TAG);
27 |
28 | // If you are at min version 1.3.3 you can enable the requestdelay.
29 | // This is usefull to get rid of the api requestlimit.
30 | // It depends on your current associate status and it is disabled by default.
31 | // $amazonEcs->requestDelay(true);
32 |
33 | // for the new version of the wsdl its required to provide a associate Tag
34 | // @see https://affiliate-program.amazon.com/gp/advertising/api/detail/api-changes.html?ie=UTF8&pf_rd_t=501&ref_=amb_link_83957571_2&pf_rd_m=ATVPDKIKX0DER&pf_rd_p=&pf_rd_s=assoc-center-1&pf_rd_r=&pf_rd_i=assoc-api-detail-2-v2
35 | // you can set it with the setter function or as the fourth paramameter of ther constructor above
36 | $amazonEcs->associateTag(AWS_ASSOCIATE_TAG);
37 |
38 | // changing the category to DVD and the response to only images and looking for some matrix stuff.
39 | $response = $amazonEcs->category('DVD')->responseGroup('Large')->search("Matrix Revolutions");
40 | //var_dump($response);
41 |
42 | // from now on you want to have pure arrays as response
43 | $amazonEcs->returnType(AmazonECS::RETURN_TYPE_ARRAY);
44 |
45 | // searching again
46 | $response = $amazonEcs->search('Bud Spencer');
47 | //var_dump($response);
48 |
49 | // and again... Changing the responsegroup and category before
50 | $response = $amazonEcs->responseGroup('Small')->category('Books')->search('PHP 5');
51 | //var_dump($response);
52 |
53 | // category has been set so lets have a look for another book
54 | $response = $amazonEcs->search('MySql');
55 | //var_dump($response);
56 |
57 | // want to look in the US Database? No Problem
58 | $response = $amazonEcs->country('com')->search('MySql');
59 | //var_dump($response);
60 |
61 | // or Japan?
62 | $response = $amazonEcs->country('co.jp')->search('MySql');
63 | //var_dump($response);
64 |
65 | // Back to DE and looking for some Music !! Warning "Large" produces a lot of Response
66 | $response = $amazonEcs->country('de')->category('Music')->responseGroup('Small')->search('The Beatles');
67 | //var_dump($response);
68 |
69 | // Or doing searchs in a loop?
70 | for ($i = 1; $i < 4; $i++)
71 | {
72 | $response = $amazonEcs->search('Matrix ' . $i);
73 | //var_dump($response);
74 | }
75 |
76 | // Want to have more Repsonsegroups? And Maybe you want to start with resultpage 2?
77 | $response = $amazonEcs->responseGroup('Small,Images')->optionalParameters(array('ItemPage' => 2))->search('Bruce Willis');
78 | //var_dump($response);
79 |
80 | // With version 1.2 you can use the page function to set up the page of the resultset
81 | $response = $amazonEcs->responseGroup('Small,Images')->page(3)->search('Bruce Willis');
82 | //var_dump($response);
83 | }
84 | catch(Exception $e)
85 | {
86 | echo $e->getMessage();
87 | }
88 |
89 | if ("cli" !== PHP_SAPI)
90 | {
91 | echo "";
92 | }
93 |
--------------------------------------------------------------------------------
/samples/sampleSettings.php-dist:
--------------------------------------------------------------------------------
1 | ";
9 | }
10 |
11 | if (is_file('sampleSettings.php'))
12 | {
13 | include 'sampleSettings.php';
14 | }
15 |
16 | defined('AWS_API_KEY') or define('AWS_API_KEY', 'API KEY');
17 | defined('AWS_API_SECRET_KEY') or define('AWS_API_SECRET_KEY', 'SECRET KEY');
18 | defined('AWS_ASSOCIATE_TAG') or define('AWS_ASSOCIATE_TAG', 'ASSOCIATE TAG');
19 |
20 | require '../lib/AmazonECS.class.php';
21 |
22 | try
23 | {
24 | $amazonEcs = new AmazonECS(AWS_API_KEY, AWS_API_SECRET_KEY, 'DE', AWS_ASSOCIATE_TAG);
25 |
26 | // for the new version of the wsdl its required to provide a associate Tag
27 | // @see https://affiliate-program.amazon.com/gp/advertising/api/detail/api-changes.html?ie=UTF8&pf_rd_t=501&ref_=amb_link_83957571_2&pf_rd_m=ATVPDKIKX0DER&pf_rd_p=&pf_rd_s=assoc-center-1&pf_rd_r=&pf_rd_i=assoc-api-detail-2-v2
28 | // you can set it with the setter function or as the fourth paramameter of ther constructor above
29 | $amazonEcs->associateTag(AWS_ASSOCIATE_TAG);
30 |
31 | $response = $amazonEcs->responseGroup('Large')->similarityLookup('B0017TZY5Y');
32 | //var_dump($response);
33 |
34 | $response = $amazonEcs->responseGroup('Images')->similarityLookup('B0017TZY5Y');
35 | //var_dump($response);
36 | }
37 | catch(Exception $e)
38 | {
39 | echo $e->getMessage();
40 | }
41 |
42 | if ("cli" !== PHP_SAPI)
43 | {
44 | echo "";
45 | }
46 |
--------------------------------------------------------------------------------