Services_Amazon
[ class tree: Services_Amazon ] [ index: Services_Amazon ] [ all elements ]

Source for file AmazonECS4.php

Documentation is available at AmazonECS4.php

  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4: */
  3. /**
  4. * Implementation of a developers backend for accessing Amazon's retail and
  5. * assosciate services.
  6. *
  7. * PHP versions 4 and 5
  8. *
  9. * LICENSE: Copyright 2004 John Downey. All rights reserved.
  10. *
  11. * Redistribution and use in source and binary forms, with or without
  12. * modification, are permitted provided that the following conditions are met:
  13. *
  14. * o Redistributions of source code must retain the above copyright notice, this
  15. *   list of conditions and the following disclaimer.
  16. * o Redistributions in binary form must reproduce the above copyright notice,
  17. *   this list of conditions and the following disclaimer in the documentation
  18. *   and/or other materials provided with the distribution.
  19. *
  20. * THIS SOFTWARE IS PROVIDED BY THE FREEBSD PROJECT "AS IS" AND ANY EXPRESS OR
  21. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  22. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
  23. * EVENT SHALL THE FREEBSD PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  24. * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  25. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  26. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  27. * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  28. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  29. * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30. *
  31. * The views and conclusions contained in the software and documentation are
  32. * those of the authors and should not be interpreted as representing official
  33. * policies, either expressed or implied, of The PEAR Group.
  34. *
  35. @category  Web Services
  36. @package   Services_Amazon
  37. @author    John Downey <jdowney@gmail.com>
  38. @author    Tatsuya Tsuruoka <ttsuruoka@p4life.jp>
  39. @copyright 2004 John Downey
  40. @license   http://www.freebsd.org/copyright/freebsd-license.html 2 Clause BSD License
  41. @version   CVS: $Id:$
  42. @link      http://pear.php.net/package/Services_Amazon/
  43. @filesource
  44. */
  45.  
  46. /**
  47. * Uses PEAR class for error management
  48. */
  49. require_once 'PEAR.php';
  50.  
  51. /**
  52. * Uses HTTP_Request class to send and receive data from Amazon web servers
  53. */
  54. require_once 'HTTP/Request.php';
  55.  
  56. /**
  57. * Uses XML_Unserializer class to parse data received from Amazon
  58. */
  59. require_once 'XML/Unserializer.php';
  60.  
  61. /**
  62. * A default base URL that is specific to the locale
  63. *
  64. * - Amazon.com (US)
  65. *   http://webservices.amazon.com/onca/xml?Service=AWSECommerceService
  66. * - Amazon.co.uk (UK)
  67. *   http://webservices.amazon.co.uk/onca/xml?Service=AWSECommerceService
  68. * - Amazon.de (DE)
  69. *   http://webservices.amazon.de/onca/xml?Service=AWSECommerceService
  70. * - Amazon.co.jp (JP)
  71. *   http://webservices.amazon.co.jp/onca/xml?Service=AWSECommerceService
  72. * - Amazon.fr (FR)
  73. *   http://webservices.amazon.fr/onca/xml?Service=AWSECommerceService
  74. * - Amazon.ca (CA)
  75. *   http://webservices.amazon.ca/onca/xml?Service=AWSECommerceService
  76. */
  77. define('SERVICES_AMAZON_BASEURL''http://webservices.amazon.com/onca/xml?Service=AWSECommerceService');
  78.  
  79. /**
  80. * A service version
  81. *
  82. * Use this to retrieve a particular version of the Amazon ECS.
  83. */
  84. define('SERVICES_AMAZON_ECSVERSION''2005-07-26');
  85.  
  86. /**
  87. * Class for accessing and retrieving information from Amazon's Web Services
  88. *
  89. @package Services_Amazon
  90. @author  John Downey <jdowney@gmail.com>
  91. @author  Tatsuya Tsuruoka <ttsuruoka@p4life.jp>
  92. @access  public
  93. @version Release: @package_version@
  94. @uses    PEAR
  95. @uses    HTTP_Request
  96. @uses    XML_Unserializer
  97. */
  98. {
  99.     /**
  100.     * An Amazon Subscription ID used when quering Amazon servers
  101.     *
  102.     * @access private
  103.     * @var    string 
  104.     */
  105.     var $_subid = null;
  106.  
  107.     /**
  108.     * An Amazon Associate ID used in the URL's so a commision may be payed
  109.     *
  110.     * @access private
  111.     * @var    string 
  112.     */
  113.     var $_associd = null;
  114.  
  115.     /**
  116.     * A base URL used to build the query for the Amazon servers
  117.     *
  118.     * @access private
  119.     * @var    string 
  120.     */
  121.     var $_baseurl = SERVICES_AMAZON_BASEURL;
  122.  
  123.     /**
  124.     * A service version
  125.     *
  126.     * @access private
  127.     * @var    string 
  128.     */
  129.     var $_version = SERVICES_AMAZON_ECSVERSION;
  130.  
  131.     /**
  132.     * The time that the Amazon took to process the request
  133.     * 
  134.     * @access private
  135.     * @var    string 
  136.     */
  137.     var $_processing_time = null;
  138.  
  139.     /**
  140.     * The last URL accessed to the Amazon (for debugging)
  141.     *
  142.     * @access private
  143.     * @var    string 
  144.     */
  145.     var $_lasturl;
  146.  
  147.     /**
  148.     * Constructor
  149.     *
  150.     * @access public
  151.     * @param  string $subid An Amazon Subscription ID used when quering Amazon servers
  152.     * @param  string $associd An Amazon Associate ID used in the URL's so a commision may be payed
  153.     * @see    setSubscriptionID
  154.     * @see    setAssociateID
  155.     * @see    setBaseUrl
  156.     * @see    setVersion
  157.     */
  158.     function Services_AmazonECS4($subid$associd = null)
  159.     {
  160.         $this->_subid $subid;
  161.         $this->_associd $associd;
  162.     }
  163.  
  164.     /**
  165.     * Retrieves the current version of this classes API
  166.     *
  167.     * @access public
  168.     * @static
  169.     * @return string The API version
  170.     */
  171.     function getApiVersion()
  172.     {
  173.         return '0.3';
  174.     }
  175.  
  176.     /**
  177.     * Sets a Subscription ID
  178.     *
  179.     * @access public
  180.     * @param  string $subid A Subscription ID
  181.     * @return void 
  182.     */
  183.     function setSubscriptionID($subid)
  184.     {
  185.         $this->_subid $subid;
  186.     }
  187.  
  188.     /**
  189.     * Sets an Associate ID
  190.     *
  191.     * @access public
  192.     * @param  string $associd An Associate ID
  193.     * @return void 
  194.     */
  195.     function setAssociateID($associd)
  196.     {
  197.         $this->_associd $associd;
  198.     }
  199.  
  200.     /**
  201.     * Sets the base URL
  202.     *
  203.     * @access public
  204.     * @param  string $url The base url
  205.     * @return void 
  206.     */
  207.     function setBaseUrl($url)
  208.     {
  209.         $this->_baseurl $url;
  210.     }
  211.  
  212.     /**
  213.     * Sets the locale passed when making a query to Amazon
  214.     *
  215.     * Currently US, UK, DE, JP, FR, and CA are supported
  216.     *
  217.     * @access public
  218.     * @param  string $locale The new locale to use
  219.     * @return mixed A PEAR_Error on error, a true on success
  220.     */
  221.     function setLocale($locale)
  222.     {
  223.         $urls = array('US' => 'http://webservices.amazon.com/onca/xml?Service=AWSECommerceService',
  224.                       'UK' => 'http://webservices.amazon.co.uk/onca/xml?Service=AWSECommerceService',
  225.                       'DE' => 'http://webservices.amazon.de/onca/xml?Service=AWSECommerceService',
  226.                       'JP' => 'http://webservices.amazon.co.jp/onca/xml?Service=AWSECommerceService',
  227.                       'FR' => 'http://webservices.amazon.fr/onca/xml?Service=AWSECommerceService',
  228.                       'CA' => 'http://webservices.amazon.ca/onca/xml?Service=AWSECommerceService');
  229.         $locale strtoupper($locale);
  230.         if (empty($urls[$locale])) {
  231.             return PEAR::raiseError('Invalid locale');
  232.         }
  233.         $this->setBaseUrl($urls[$locale]);
  234.         return true;
  235.     }
  236.  
  237.     /**
  238.     * Sets a version
  239.     *
  240.     * @access public
  241.     * @param  string $version A service version
  242.     * @return void 
  243.     */
  244.     function setVersion($version)
  245.     {
  246.         $this->_version $version;
  247.     }
  248.  
  249.     /**
  250.     * Retrieves the processing time
  251.     *
  252.     * @access public
  253.     * @return string Processing time
  254.     */
  255.     function getProcessingTime()
  256.     {
  257.         return $this->_processing_time;
  258.     }
  259.  
  260.     /**
  261.     * Retrieves the last URL accessed to the Amazon (for debugging)
  262.     *
  263.     * @access public
  264.     * @return string The Last URL
  265.     */
  266.     function getLastUrl()
  267.     {
  268.         return $this->_lasturl;
  269.     }
  270.     
  271.  
  272.     /**
  273.     * Retrieves information about a browse node
  274.     *
  275.     * Example:
  276.     * <code>
  277.     * <?php
  278.     * $amazon = new Services_AmazonECS4('[your Subscription ID here]');
  279.     * $result = $amazon->BrowseNodeLookup('283155'); // 283155='Books'
  280.     * ?>
  281.     * </code>
  282.     *
  283.     * @access public
  284.     * @param  string $browsenode_id The browse node ID
  285.     * @param  array $options The optional parameters
  286.     * @return array The array of information returned by the query
  287.     */
  288.     function BrowseNodeLookup($browsenode_id$options = array())
  289.     {
  290.         $params $options;
  291.         $params['Operation''BrowseNodeLookup';
  292.         $params['BrowseNodeId'$browsenode_id;
  293.         return $this->_sendRequest($params);
  294.     }
  295.  
  296.     /**
  297.     * Adds items to an existing remote shopping cart
  298.     *
  299.     * Example:
  300.     * <code>
  301.     * <?php
  302.     * $amazon = new Services_AmazonECS4('[your Subscription ID here]');
  303.     * $item = array('ASIN' => 'aaaaaaaaaa', 'Quantity' => 1);
  304.     * // $item = array(array('ASIN' => 'aaaaaaaaaa', 'Quantity' => 1),
  305.     * //               array('OfferListingId' => 'bbbbbbbbbb', 'Quantity' => 10),
  306.     * //               array('ASIN' => 'cccccccccc', 'Quantity' => 20));
  307.     * $result = $amazon->CartAdd('[Cart ID]', '[HMAC]', $item);
  308.     * ?>
  309.     * </code>
  310.     *
  311.     * @access public
  312.     * @param  string $cart_id A unique identifier for a cart
  313.     * @param  string $hmac A unique security token
  314.     * @param  array $item Products and the quantities
  315.     * @param  array $options The optional parameters
  316.     * @return array The array of information returned by the query
  317.     * @see    CartClear(), CartCreate(), CartModify()
  318.     */
  319.     function CartAdd($cart_id$hmac$item$options = array())
  320.     {
  321.         $params $options;
  322.         $params['Operation''CartAdd';
  323.         $params['CartId'$cart_id;
  324.         $params['HMAC'$hmac;
  325.         $params += $this->_assembleItemParameter($item);
  326.         return $this->_sendRequest($params);
  327.     }
  328.  
  329.     /**
  330.     * Removes all the contents of a remote shopping cart
  331.     *
  332.     * @access public
  333.     * @param  string $cart_id A unique identifier for a cart
  334.     * @param  string $hmac A unique security token
  335.     * @param  array $options The optional parameters
  336.     * @return array The array of information returned by the query
  337.     * @see    CartAdd(), CartCreate(), CartGet(), CartModify()
  338.     */
  339.     function CartClear($cart_id$hmac$options = array())
  340.     {
  341.         $params $options;
  342.         $params['Operation''CartClear';
  343.         $params['CartId'$cart_id;
  344.         $params['HMAC'$hmac;
  345.         return $this->_sendRequest($params);
  346.     }
  347.  
  348.     /**
  349.     * Creates a new remote shopping cart
  350.     *
  351.     * Example:
  352.     * <code>
  353.     * <?php
  354.     * $amazon = new Services_AmazonECS4('[your Subscription ID here]');
  355.     * $item = array('ASIN' => 'aaaaaaaaaa', 'Quantity' => 1);
  356.     * // $item = array(array('ASIN' => 'aaaaaaaaaa', 'Quantity' => 1),
  357.     * //               array('ASIN' => 'cccccccccc', 'Quantity' => 20));
  358.     * $result = $amazon->CartCreate($item);
  359.     * ?>
  360.     * </code>
  361.     *
  362.     * @access public
  363.     * @param  array $item Products and the quantities
  364.     * @param  array $options The optional parameters
  365.     * @return array The array of information returned by the query
  366.     * @see    CartAdd(), CartClear(), CartGet(), CartModify()
  367.     */
  368.     function CartCreate($item$options = array())
  369.     {
  370.         $params $options;
  371.         $params['Operation''CartCreate';
  372.         $params += $this->_assembleItemParameter($item);
  373.         return $this->_sendRequest($params);
  374.     }
  375.  
  376.     /**
  377.     * Retrieves the contents of a remote shopping cart
  378.     *
  379.     * @access public
  380.     * @param  string $cart_id A unique identifier for a cart
  381.     * @param  string $hmac A unique security token
  382.     * @param  array $options The optional parameters
  383.     * @return array The array of information returned by the query
  384.     * @see    CartAdd(), CartClear(), CartCreate(), CartModify()
  385.     */
  386.     function CartGet($cart_id$hmac$options = array())
  387.     {
  388.         $params $options;
  389.         $params['Operation''CartGet';
  390.         $params['CartId'$cart_id;
  391.         $params['HMAC'$hmac;
  392.         return $this->_sendRequest($params);
  393.     }
  394.  
  395.     /**
  396.     * Modifies the quantity of items in a cart and changes cart items to saved items
  397.     *
  398.     * Example:
  399.     * <code>
  400.     * <?php
  401.     * $amazon = new Services_AmazonECS4('[your Subscription ID here]');
  402.     * $item = array('CartItemId' => 'aaaaaaaaaa', 'Quantity' => 1);
  403.     * // $item = array('CartItemId' => 'aaaaaaaaaa', 'Action' => 'SaveForLater');
  404.     * // $item = array(array('CartItemId' => 'aaaaaaaaaa', 'Quantity' => 1),
  405.     * //               array('CartItemId' => 'cccccccccc', 'Quantity' => 20));
  406.     * $result = $amazon->CartModify('[Cart ID]', '[HMAC]', $item);
  407.     * ?>
  408.     * </code>
  409.     *
  410.     * @access public
  411.     * @param  string $cart_id A unique identifier for a cart
  412.     * @param  string $hmac A unique security token
  413.     * @param  array $item The CartItemId and the quantities or the Action
  414.     * @param  array $options The optional parameters
  415.     * @return array The array of information returned by the query
  416.     * @see    CartAdd(), CartClear(), CartCreate(), CartGet()
  417.     */
  418.     function CartModify($cart_id$hmac$item$options = array())
  419.     {
  420.         $params $options;
  421.         $params['Operation''CartModify';
  422.         $params['CartId'$cart_id;
  423.         $params['HMAC'$hmac;
  424.         $params += $this->_assembleItemParameter($item);
  425.         return $this->_sendRequest($params);
  426.     }
  427.  
  428.     /**
  429.     * Retrieves publicly available content written by specific Amazon customers
  430.     *
  431.     * @access public
  432.     * @param  string $customer_id A customer ID
  433.     * @param  array $options The optional parameters
  434.     * @return array The array of information returned by the query
  435.     * @see    CustomerContentSearch()
  436.     */
  437.     function CustomerContentLookup($customer_id$options = array())
  438.     {
  439.         $params $options;
  440.         $params['Operation''CustomerContentLookup';
  441.         $params['CustomerId'$customer_id;
  442.         return $this->_sendRequest($params);
  443.     }
  444.  
  445.     /**
  446.     * Searches for Amazon customers by name or email address
  447.     *
  448.     * @access public
  449.     * @param  array $customer A customer's name or its email
  450.     * @param  array $options The optional parameters
  451.     * @return array The array of information returned by the query
  452.     * @see    CustomerContentLookup()
  453.     */
  454.     function CustomerContentSearch($customer = null$options = array())
  455.     {
  456.         $params $options;
  457.         $params['Operation''CustomerContentSearch';
  458.         $params += $customer;
  459.         return $this->_sendRequest($params);
  460.     }
  461.  
  462.     /**
  463.     * Retrieves information about operations and response groups
  464.     *
  465.     * Example:
  466.     * <code>
  467.     * <?php
  468.     * $amazon = new Services_AmazonECS4('[your Subscription ID here]');
  469.     * $result = $amazon->Help('Operation', 'ItemLookup');
  470.     * ?>
  471.     * </code>
  472.     *
  473.     * @access public
  474.     * @param  string $help_type The type of information
  475.     * @param  string $about The name of an operation or a response group
  476.     * @param  array $options The optional parameters
  477.     * @return array The array of information returned by the query
  478.     */
  479.     function Help($help_type$about$options = array())
  480.     {
  481.         $params $options;
  482.         $params['Operation''Help';
  483.         $params['HelpType'$help_type;
  484.         $params['About'$about;
  485.         return $this->_sendRequest($params);
  486.     }
  487.         
  488.     /**
  489.     * Retrieves information for products
  490.     *
  491.     * Example:
  492.     * <code>
  493.     * <?php
  494.     * $amazon = new Services_AmazonECS4('[your Subscription ID here]');
  495.     * $options = array();
  496.     * $options['ResponseGroup'] = 'Large';
  497.     * $result = $amazon->ItemLookup('[ASIN(s)]', $options);
  498.     * ?>
  499.     * </code>
  500.     *
  501.     * @access public
  502.     * @param  string $item_id Product IDs
  503.     * @param  array $options The optional parameters
  504.     * @return array The array of information returned by the query
  505.     * @see    ItemSearch()
  506.     */
  507.     function ItemLookup($item_id$options = array())
  508.     {
  509.         $params $options;
  510.         $params['Operation''ItemLookup';
  511.         $params['ItemId'$item_id;
  512.         return $this->_sendRequest($params);
  513.     }
  514.  
  515.     /**
  516.     * Searches for products
  517.     *
  518.     * Example:
  519.     * <code>
  520.     * <?php
  521.     * $amazon = new Services_AmazonECS4('[your Subscription ID here]');
  522.     * $options = array();
  523.     * $options['Keywords'] = 'sushi';
  524.     * $options['Sort'] = 'salesrank';
  525.     * $options['ResponseGroup'] = 'ItemIds,ItemAttributes,Images';
  526.     * $result = $amazon->ItemSearch('Books', $options);
  527.     * ?>
  528.     * </code>
  529.     *
  530.     * @access public
  531.     * @param  string $search_index A search index
  532.     * @param  array $options The optional parameters
  533.     * @return array The array of information returned by the query
  534.     * @see    ItemLookup()
  535.     */
  536.     function ItemSearch($search_index$options = array())
  537.     {
  538.         $params $options;
  539.         $params['Operation''ItemSearch';
  540.         $params['SearchIndex'$search_index;
  541.         return $this->_sendRequest($params);
  542.     }
  543.  
  544.     /**
  545.     * Retrieves products in a specific list
  546.     *
  547.     * @access public
  548.     * @param  string $list_type The type of list
  549.     * @param  string $list_id A list ID
  550.     * @param  array $options The optional parameters
  551.     * @return array The array of information returned by the query
  552.     * @see    ListSearch()
  553.     */
  554.     function ListLookup($list_type$list_id$options = array())
  555.     {
  556.         $params $options;
  557.         $params['Operation''ListLookup';
  558.         $params['ListType'$list_type;
  559.         $params['ListId'$list_id;
  560.         return $this->_sendRequest($params);
  561.     }
  562.  
  563.     /**
  564.     * Searches for a wish list, baby registry, or wedding registry
  565.     *
  566.     * Example:
  567.     * <code>
  568.     * <?php
  569.     * $amazon = new Services_AmazonECS4('[your Subscription ID here]');
  570.     * $keywords = array('Name' => 'hoge');
  571.     * $result = $amazon->ListSearch('WishList', $keywords);
  572.     * ?>
  573.     * </code>
  574.     *
  575.     * @access public
  576.     * @param  string $list_type The type of list
  577.     * @param  array $keywords Parameters to search for
  578.     * @param  array $options The optional parameters
  579.     * @return array The array of information returned by the query
  580.     * @see    ListLookup()
  581.     */
  582.     function ListSearch($list_type$keywords$options = array())
  583.     {
  584.         $params $options;
  585.         $params['Operation''ListSearch';
  586.         $params['ListType'$list_type;
  587.         $params += $keywords;
  588.         return $this->_sendRequest($params);
  589.     }
  590.  
  591.     /**
  592.     * Retrieves information about Amazon zShops and Marketplace products
  593.     *
  594.     * @access public
  595.     * @param  string $id_type The type of ID
  596.     * @param  string $id The exchange ID or the listing ID
  597.     * @param  array $options The optional parameters
  598.     * @return array The array of information returned by the query
  599.     * @see    SellerListingSearch()
  600.     */
  601.     function SellerListingLookup($id_type$id$options = array())
  602.     {
  603.         $params $options;
  604.         $params['Operation''SellerListingLookup';
  605.         $params['IdType'$id_type;
  606.         $params['Id'$id;
  607.         return $this->_sendRequest($params);
  608.     }
  609.  
  610.     /**
  611.     * Searches for Amazon zShops and Marketplace products
  612.     *
  613.     * Example:
  614.     * <code>
  615.     * <?php
  616.     * $amazon = new Services_AmazonECS4('[your Subscription ID here]');
  617.     * $keywords = array('Keywords' => 'pizza');
  618.     * $result = $amazon->SellerListingSearch('zShops', $keywords);
  619.     * ?>
  620.     * </code>
  621.     *
  622.     * @access public
  623.     * @param  string $search_index The type of seller listings
  624.     * @param  array $options The optional parameters
  625.     * @return array The array of information returned by the query
  626.     * @see    SellerListingLookup()
  627.     */
  628.     function SellerListingSearch($search_index$options = array())
  629.     {
  630.         $params $options;
  631.         $params['Operation''SellerListingSearch';
  632.         $params['SearchIndex'$search_index;
  633.         return $this->_sendRequest($params);
  634.     }
  635.  
  636.     /**
  637.     * Retrieves information about specific sellers
  638.     *
  639.     * @access public
  640.     * @param  string $seller_id IDs for Amazon sellers
  641.     * @param  array $options The optional parameters
  642.     * @return array The array of information returned by the query
  643.     */
  644.     function SellerLookup($seller_id$options = array())
  645.     {
  646.         $params $options;
  647.         $params['Operation''SellerLookup';
  648.         $params['SellerId'$seller_id;
  649.         return $this->_sendRequest($params);
  650.     }
  651.  
  652.     /**
  653.     * Retrieves products that are similar to Amazon products
  654.     *
  655.     * @access public
  656.     * @param  string $item_id Product IDs
  657.     * @param  array $options The optional parameters
  658.     * @return array The array of information returned by the query
  659.     */
  660.     function SimilarityLookup($item_id$options = array())
  661.     {
  662.         $params $options;
  663.         $params['Operation''SimilarityLookup';
  664.         $params['ItemId'$item_id;
  665.         return $this->_sendRequest($params);
  666.     }
  667.  
  668.     /**
  669.     * Retrieves information about the status of financial transactions
  670.     *
  671.     * @access public
  672.     * @param  string $transaction_id Transaction IDs
  673.     * @param  array $options The optional parameters
  674.     * @return array The array of information returned by the query
  675.     */
  676.     function TransactionLookup($transaction_id$options = array())
  677.     {
  678.         $params $options;
  679.         $params['Operation''SimilarityLookup';
  680.         $params['TransactionId'$transaction_id;
  681.         return $this->_sendRequest($params);
  682.     }
  683.  
  684.     /**
  685.     * Combines requests for the same operation into a single request
  686.     *
  687.     * Example:
  688.     * <code>
  689.     * <?php
  690.     * $amazon = new Services_AmazonECS4('[your Subscription ID here]');
  691.     * $shared = array('SearchIndex' => 'Books',
  692.     *                 'Keywords' => 'php');
  693.     * $params1 = array('ItemPage' => '1');
  694.     * $params2 = array('ItemPage' => '2');
  695.     * $result = $amazon->doBatch('ItemSearch', $shared, $params1, $params2);
  696.     * ?>
  697.     * </code>
  698.     *
  699.     * @access public
  700.     * @param  string $operation The operation
  701.     * @param  array $shared Shared parameters
  702.     * @param  array $params1 The parameters specific to the first request
  703.     * @param  array $params2 The parameters specific to the second request
  704.     * @return array The array of information returned by the query
  705.     */
  706.     function doBatch($operation$shared$params1$params2)
  707.     {
  708.         $params = array();
  709.         $params['Operation'$operation;
  710.         foreach ($shared as $k => $v{
  711.             $params[$operation '.Shared.' $k$v;
  712.         }
  713.         foreach ($params1 as $k => $v{
  714.             $params[$operation '.1.' $k$v;
  715.         }
  716.         foreach ($params2 as $k => $v{
  717.             $params[$operation '.2.' $k$v;
  718.         }
  719.         return $this->_sendRequest($params);
  720.     }
  721.  
  722.     /**
  723.     * Combines the different operations into a single request
  724.     *
  725.     * Example:
  726.     * <code>
  727.     * <?php
  728.     * $amazon = new Services_AmazonECS4('[your Subscription ID here]');
  729.     * $params1 = array('SearchIndex' => 'Books',
  730.     *                  'Title' => 'sushi');
  731.     * $params2 = array('Keywords' => 'tempura');
  732.     * $result = $amazon->doMultiOperation('ItemSearch', $params1,
  733.     *                                     'SellerListingSearch', $params2);
  734.     * ?>
  735.     * </code>
  736.     *
  737.     * @access public
  738.     * @param  string $operation1 The first operation
  739.     * @param  array $params1 The parameters specific to the first request
  740.     * @param  string $operation2 The second operation
  741.     * @param  array $params2 The parameters specific to the second request
  742.     * @return array The array of information returned by the query
  743.     */
  744.     function doMultiOperation($operation1$params1$operation2$params2)
  745.     {
  746.         $params = array();
  747.         $params['Operation'$operation1 ',' $operation2;
  748.         foreach ($params1 as $k => $v{
  749.             $params[$operation1 '.1.' $k$v;
  750.         }
  751.         foreach ($params2 as $k => $v{
  752.             $params[$operation2 '.1.' $k$v;
  753.         }
  754.         return $this->_sendRequest($params);
  755.     }
  756.  
  757.     /**
  758.     * Assembles the Item parameters
  759.     *
  760.     * @access private
  761.     * @param  array $items The items
  762.     * @return array The item parameters
  763.     */
  764.     function _assembleItemParameter($items)
  765.     {
  766.         $params = array();
  767.         if (!is_array(current($items))) {
  768.             $items = array(0 => $items);
  769.         }
  770.         $i = 1;
  771.         foreach ($items as $item{
  772.             foreach ($item as $k => $v{
  773.                 $params['Item.' $i '.' $k$v;
  774.             }
  775.             $i++;
  776.         }
  777.         return $params;
  778.     }
  779.  
  780.     /**
  781.     * Sends the request to Amazons Web Services
  782.     *
  783.     * @access private
  784.     * @param  array $params The array of request parameters
  785.     * @return array The array of information returned by the query
  786.     */
  787.     function _sendRequest($params)
  788.     {
  789.         if (is_null($this->_subid)) {
  790.             return PEAR::raiseError('Subscription ID have not been set');
  791.         }
  792.  
  793.         $url $this->_baseurl;
  794.         $url .= '&SubscriptionId=' $this->_subid '&AssociateTag=' $this->_associd '&Version=' $this->_version;
  795.         foreach ($params as $k => $v{
  796.             $url .= '&' $k '=' urlencode($v);
  797.         }
  798.         $this->_lasturl $url;
  799.  
  800.         $http &new HTTP_Request($url);
  801.         $http->addHeader('User-Agent''Services_AmazonECS4/' $this->getApiVersion());
  802.         $http->sendRequest();
  803.  
  804.         if($http->getResponseCode(!= 200){
  805.             return PEAR::raiseError('Amazon returned invalid HTTP response code ' $http->getResponseCode());
  806.         }
  807.         $result $http->getResponseBody();
  808.  
  809.         $xml &new XML_Unserializer(array('parseAttributes' => true));
  810.         $xml->unserialize($resultfalse);
  811.         $data $xml->getUnserializedData();
  812.  
  813.         if (isset($data['Error'])) {
  814.             $errormsg $data['Error']['Code'': ' $data['Error']['Message'];
  815.             return PEAR::raiseError($errormsg);
  816.         }
  817.  
  818.         $this->_processing_time $data['OperationRequest']['RequestProcessingTime'];
  819.  
  820.         // Gets values of the second level content elements
  821.         unset($data['xmlns']);
  822.         unset($data['OperationRequest']);
  823.         $contents = array();
  824.         $keys array_keys($data);
  825.         foreach ($keys as $v{
  826.             if (strstr($v'Response')) {
  827.                 $key key($data[$v]);
  828.                 $data[$v$data[$v][$key];
  829.                 $contents[$v$data[$v];
  830.             else {
  831.                 $contents $data[$v];
  832.             }
  833.             $result $this->_checkContentError($data[$v]);
  834.             if (PEAR::isError($result)) {
  835.                 return $result;
  836.             }
  837.         }
  838.  
  839.         return $contents;
  840.     }
  841.  
  842.     /**
  843.     * Checks error codes at the content elements
  844.     *
  845.     * @access private
  846.     * @param  array $content Values of the content elements
  847.     * @return array mixed A PEAR_Error on error, a true on success
  848.     */
  849.     function _checkContentError($content)
  850.     {
  851.         $error $content['Request']['Errors']['Error'];
  852.         if (isset($error)) {
  853.             if (isset($error['Code'])) {
  854.                 $errormsg $error['Code'':' $error['Message'];
  855.             else {
  856.                 $errormsg '';
  857.                 foreach ($error as $v{
  858.                     $errormsg .= $v['Code'':' $v['Message'"\n";
  859.                 }
  860.             }
  861.             return PEAR::raiseError($errormsg);
  862.         }
  863.         return true;
  864.     }
  865. }
  866. ?>

Documentation generated on Mon, 11 Mar 2019 14:13:43 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.