compared with
Current by Andries Seutens
on Sep 16, 2006 08:16.

(show comment)
Key
This line was removed.
This word was removed. This word was added.
This line was added.

Changes (79)

View Page History

{toc:style=none|indent=25px}
<ac:macro ac:name="toc"><ac:parameter ac:name="style">none</ac:parameter><ac:parameter ac:name="indent">25px</ac:parameter></ac:macro>


h1. Zend_Service_Amazon


h2. Introduction
_Zend_Service_Amazon_ is a simple API for using Amazon web services. _Zend_Service_Amazon_ has two APIs: a more traditional one that follows Amazon's own API, and a simpler "Query API" for constructing even complex search queries easily.
\\

_Zend_Service_Amazon_ enables developers to retrieve information appearing throughout Amazon.com web sites directly through the Amazon Web Services API. Examples include:
* Store item information, such as images, descriptions, pricing, and more
* Customer and editorial reviews
* Similar products and accessories
* Amazon.com offers
* ListMania lists
\\ <h1>Zend_Service_Amazon</h1>

In order to use _Zend_Service_Amazon_, you should already have an Amazon developer API key. To get a key and for more information, please visit the Amazon Web Services web site.
\\

<h2>Introduction</h2>
<p> <em>Zend_Service_Amazon</em> is a simple API for using Amazon web services. <em>Zend_Service_Amazon</em> has two APIs: a more traditional one that follows Amazon's own API, and a simpler &quot;Query API&quot; for constructing even complex search queries easily.
<br class="atl-forced-newline" /></p>

<p> <em>Zend_Service_Amazon</em> enables developers to retrieve information appearing throughout Amazon.com web sites directly through the Amazon Web Services API. Examples include: </p>
{note} <ul>
Your Amazon developer API key is linked to your Amazon identity, so take appropriate measures to keep your API key private.
<li>Store item information, such as images, descriptions, pricing, and more</li>
<li>Customer and editorial reviews</li>
<li>Similar products and accessories</li>
<li>Amazon.com offers</li>
<li>ListMania lists
<br class="atl-forced-newline" /></li>
{note} </ul>




*Search Amazon Using the Traditional API*
<p> In order to use <em>Zend_Service_Amazon</em>, you should already have an Amazon developer API key. To get a key and for more information, please visit the Amazon Web Services web site.
<br class="atl-forced-newline" /></p>


In this example, we search for PHP books at Amazon and loop through the results, printing them.
\\

<ac:macro ac:name="note"><ac:rich-text-body>
<p> Your Amazon developer API key is linked to your Amazon identity, so take appropriate measures to keep your API key private. </p></ac:rich-text-body></ac:macro>

{code}


<p><strong>Search Amazon Using the Traditional API</strong></p>


<p> In this example, we search for PHP books at Amazon and loop through the results, printing them.
<br class="atl-forced-newline" /></p>


<ac:macro ac:name="code"><ac:plain-text-body><![CDATA[
<?php
require_once 'Zend/Service/Amazon.php';
}
?>
{code}
]]></ac:plain-text-body></ac:macro>




*Search Amazon Using the Query API*


Here, we also search for PHP books at Amazon, but we instead use the Query API, which resembles the Fluent Interface design pattern.
\\

<p><strong>Search Amazon Using the Query API</strong></p>

{code}
<p> Here, we also search for PHP books at Amazon, but we instead use the Query API, which resembles the Fluent Interface design pattern.
<br class="atl-forced-newline" /></p>


<ac:macro ac:name="code"><ac:plain-text-body><![CDATA[
<?php
require_once 'Zend/Service/Amazon/Query.php';
}
?>
{code}
]]></ac:plain-text-body></ac:macro>





h2. Country Codes
By default, _Zend_Service_Amazon_ connects to the United States ("_US_") Amazon web service. To connect from a different country, simply specify the appropriate country code string as the second parameter to the constructor:
\\



*Choosing an Amazon Web Service Country*



<h2>Country Codes</h2>
<p> By default, <em>Zend_Service_Amazon</em> connects to the United States (&quot;<em>US</em>&quot;) Amazon web service. To connect from a different country, simply specify the appropriate country code string as the second parameter to the constructor:
<br class="atl-forced-newline" /></p>
{code}


<p><strong>Choosing an Amazon Web Service Country</strong></p>



<ac:macro ac:name="code"><ac:plain-text-body><![CDATA[
<?php
// Connect to Amazon in Japan
$amazon = new Zend_Service_Amazon('AMAZON_API_KEY', 'JP');
?>
{code}
]]></ac:plain-text-body></ac:macro>



{note}
Valid country codes are: CA, DE, FR, JP, UK, and US.
{note}

<ac:macro ac:name="note"><ac:rich-text-body>
<p> Valid country codes are: CA, DE, FR, JP, UK, and US. </p></ac:rich-text-body></ac:macro>





h2. Looking up a Specific Amazon Item by ASIN
The _itemLookup()_ method provides the ability to fetch a particular Amazon item when the ASIN is known.
\\



*Looking up a Specific Amazon Item by ASIN*



{code}
<h2>Looking up a Specific Amazon Item by ASIN</h2>
<p> The <em>itemLookup()</em> method provides the ability to fetch a particular Amazon item when the ASIN is known.
<br class="atl-forced-newline" /></p>



<p><strong>Looking up a Specific Amazon Item by ASIN</strong></p>



<ac:macro ac:name="code"><ac:plain-text-body><![CDATA[
<?php
require_once 'Zend/Service/Amazon.php';
$item = $amazon->itemLookup('B0000A432X');
?>
{code}
]]></ac:plain-text-body></ac:macro>


The _itemLookup()_ method also accepts an optional second parameter for handling search options. For full details, including a list of available options, please see the relevant Amazon documentation.
\\




h2. Performing Amazon Item Searches
Searching for items based on any of various available criteria are made simple using the _itemSearch()_ method, as in the following example:
\\
<p> The <em>itemLookup()</em> method also accepts an optional second parameter for handling search options. For full details, including a list of available options, please see the relevant Amazon documentation.
<br class="atl-forced-newline" /></p>



*Performing Amazon Item Searches*



<h2>Performing Amazon Item Searches</h2>
<p> Searching for items based on any of various available criteria are made simple using the <em>itemSearch()</em> method, as in the following example:
<br class="atl-forced-newline" /></p>
{code}


<p><strong>Performing Amazon Item Searches</strong></p>



<ac:macro ac:name="code"><ac:plain-text-body><![CDATA[
<?php
require_once 'Zend/Service/Amazon.php';
}
?>
{code}
]]></ac:plain-text-body></ac:macro>


The _itemSearch()_ method accepts a single array parameter for handling search options. For full details, including a list of available options, please see the relevant Amazon documentation
\\


{tip}
The Zend_Service_Amazon_Query class is an easy to use wrapper around this method.
{tip}
<p> The <em>itemSearch()</em> method accepts a single array parameter for handling search options. For full details, including a list of available options, please see the relevant Amazon documentation
<br class="atl-forced-newline" /></p>




h2. Using the Alternative Query API


h3. Introduction
_Zend_Service_Amazon_Query_ provides an alternative API for using the Amazon Web Service. The alternative API uses the Fluent Interface pattern. That is, all calls can be made using chained method calls. (e.g., _$obj->method()->method2($arg)_)
\\

The _Zend_Service_Amazon_Query_ API uses overloading to easily set up an item search and then allows you to search based upon the criteria specified. Each of the options is provided as a method call, and each method's argument corresponds to the named option's value:
\\
<ac:macro ac:name="tip"><ac:rich-text-body>
<p> The Zend_Service_Amazon_Query class is an easy to use wrapper around this method. </p></ac:rich-text-body></ac:macro>



*Search Amazon Using the Alternative Query API*


In this example, the alternative query API is used as a fluent interface to specify options and their respective values:
\\

<h2>Using the Alternative Query API</h2>

{code}
<h3>Introduction</h3>
<p> <em>Zend_Service_Amazon_Query</em> provides an alternative API for using the Amazon Web Service. The alternative API uses the Fluent Interface pattern. That is, all calls can be made using chained method calls. (e.g., <em>$obj-&gt;method()-&gt;method2($arg)</em>)
<br class="atl-forced-newline" /></p>

<p> The <em>Zend_Service_Amazon_Query</em> API uses overloading to easily set up an item search and then allows you to search based upon the criteria specified. Each of the options is provided as a method call, and each method's argument corresponds to the named option's value:
<br class="atl-forced-newline" /></p>



<p><strong>Search Amazon Using the Alternative Query API</strong></p>


<p> In this example, the alternative query API is used as a fluent interface to specify options and their respective values:
<br class="atl-forced-newline" /></p>


<ac:macro ac:name="code"><ac:plain-text-body><![CDATA[
<?php
require_once 'Zend/Service/Amazon/Query.php';
}
?>
{code}
]]></ac:plain-text-body></ac:macro>

This sets the option _Category_ to "Books" and _Keywords_ to "PHP".
\\
<p> This sets the option <em>Category</em> to &quot;Books&quot; and <em>Keywords</em> to &quot;PHP&quot;.
<br class="atl-forced-newline" /></p>

<p> For more information on the available options, please refer to the relevant Amazon documentation.
\\
<br class="atl-forced-newline" /></p>


{toc-zone}
<ac:macro ac:name="toc-zone" />