View Source

<ac:macro ac:name="unmigrated-inline-wiki-markup"><ac:plain-text-body><![CDATA[{zone-template-instance:ZFDEV:Zend Proposal Zone Template}

{zone-data:component-name}
ZendX_Service_Rakuten
{zone-data}

{zone-data:proposer-list}
[Satoru Yoshida|mailto:yoshida@zend.co.jp]
[~ralph], Zend liaison
{zone-data}

{zone-data:revision}
------31 Dec:Name change from Zend_ to ZendX_
------11 Dec:add explanation of method parameters.
0.8 - 28 Nov 2008:I made APIs correspond from version 1.10 to 1.12 and I implemented the checking of the required parameters.
0.7 - 26 Dec: update References, Use Cases and Class Skeletons.
0.6 - 19 Dec: update References, Class Index, Use Cases and Class Skeletons.
0.5 - 11 Dec: update References, Use Cases and Class Skeletons.
0.4 - 22 Nov: update all except Dependencies and Milestones.
0.3 - 21 May: update class skeletons.
0.2 - 15 March 2007: add class skeletons.
{zone-data}

{zone-data:overview}
ZendX_Service_Rakuten is a interface to use the "Rakuten Web service" that is provided by [the Rakuten, Inc.|http://www.rakuten.co.jp/info/] .
{zone-data}

{zone-data:references}
The following links are API references written in Japanese. I write method names and brief description for each API.
* [Rakuten Web Service|http://webservice.rakuten.co.jp/document/index.html]
** for the Rakuten Market
*** searchItem() - Search items. Uses [ItemSearch API|http://webservice.rakuten.co.jp/api/itemsearch/]
||parameter||type||min||max||required||default||explanation||
|- |- |- |- |- |- |following in params array|
|affiliateId|string|- |- |- |null|affiliate id|
|callBack|string|- |- |- |null|function name of Json call back|
|keyword|string|- |- |may required|null|key word. One of keyword, genreId or catalogCode is required|
|shopCode|string|- |- |- |null|shop code|
|genreId|int|0|- |may required|0|genre id. One of keyword, genreId or catalogCode is required.|
|catalogCode|string|- |- |may required|null|catalog code. One of keyword, genreId or catalogCode is required|
|hits|int|1|30|- |30|items per page.|
|page|int|1|100|- |1|page limits.|
|sort|string|- |- |- |standard|sort type. (mark)affiliateRate, (mark)reviewCount, (mark)itemPrice, (mark)updateTimestamp or standard. (mark) means plus or minus mark, each mark means Ascend and Descend. For example, +itemPrice|
|minPrice|int|0|- |- |null|minimum price|
|maxPrice|int|0|- |- |null|maximum price. It must be grater than minPrice|
|availability|int|0|1|- |1|0:all items, 1:only items that can be bought|
|field|int|0|1|- |1|0:search widely, 1:search narrowly|
|carrier|int|0|1|- |0|0:PC, 1:mobile|
|imageFlag|int|0|1|- |0|0:all item, 1:only items that has image|
|orFlag|int|0|1|- |0|0:AND keywords, 1:OR keywords|
|NGKeyword|string|- |- |- |null|keyword that you want to omit|
|genreInformationFlag|int|0|1|- |0|No Use. 0:not get count of items that are in the same genre, 1:get count. This method supports only 0.|
*** searchGenre() - Retrieve genre's information. Uses [GenreSearch API|http://webservice.rakuten.co.jp/api/genresearch/]
||parameter||type||min||max||required||default||explanation||
|type|string|- |- |required|child|information type. child, parent or current|
|genreId|int|0|- |required|0|genre id. If parent is specified, genre id must be grater than 0.|
|- |- |- |- |- |- |following in optparams array|
|affiliateId|string|- |- |- |null|affiliate id|
|callBack|string|- |- |- |null|function name of Json call back|
|genrePath|int|0|1|- |- |No Use. genrePath is auto controlled in this method.|
*** searchItemCode() - Retrieve item's information by item code. Uses [ItemCodeSearch API|http://webservice.rakuten.co.jp/api/itemcodesearch/]
||parameter||type||min||max||required||default||explanation||
|code|string|- |- |required|- |item code|
|- |- |- |- |- |- |following in optparams array|
|affiliateId|string|- |- |- |null|affiliate id|
|callBack|string|- |- |- |null|function name of Json call back|
|carrier|int|0|1|- |0|0:PC, 1:mobile|
*** searchCatalog() - Search items by catalog. Uses [CatalogSearch API|http://webservice.rakuten.co.jp/api/catalogsearch/]
||parameter||type||min||max||required||default||explanation||
|- |- |- |- |- |- |following in params array|
|affiliateId|string|- |- |- |null|affiliate id|
|callBack|string|- |- |- |null|function name of Json call back|
|keyword|string|- |- |may required|null|key word. One of keyword or genreId is required|
|genreId|int|0|- |may required|0|genre id. One of keyword or genreId is required.|
|hits|int|1|30|- |30|items per page.|
|page|int|1|100|- |1|page limits.|
|sort|string|- |- |- |-registerDate |sort type. (mark)registerDate,(mark)releaseDate, (mark)reviewNum or random. (mark) means plus or minus mark, each mark means Ascend and Descend. For example, +reviewNum|
|field|int|0|1|- |1|0:search widely, 1:search narrowly|
|imageFlag|int|0|1|- |0|0:all item, 1:only items that has image|
|releaseRange|int|0|12|- |0|0:no limit, 1-12:search only sold in specified months|
|orFlag|int|0|1|- |0|0:AND keywords, 1:OR keywords|
|NGKeyword|string|- |- |- |null|keyword that you want to omit|
|genreInformationFlag|int|0|1|- |0|No use. cf. searchItem()|
*** itemRanking() - Retrieve item ranking. Uses [ItemRanking API|http://webservice.rakuten.co.jp/api/itemranking/]
||parameter||type||min||max||required||default||explanation||
|- |- |- |- |- |- |following in optparams array|
|affiliateId|string|- |- |- |null|affiliate id|
|callBack|string|- |- |- |null|function name of Json call back|
|genreId|int|0|- |- |null|genre id.|
|age|int|10|50|- |null|age zone. 10:teen agers, 20:20 agers, 30:30 agers, 40:40 agers, 50:50 over|
|sex|int|0|1|- |null|sex. 0:men, 1:women|
** for the Rakuten Books
*** searchBook() - search books. Uses [BookSearch API|http://webservice.rakuten.co.jp/api/booksearch/]
||parameter||type||min||max||required||default||explanation||
|- |- |- |- |- |- |following in params array|
|affiliateId|string|- |- |- |null|affiliate id|
|callBack|string|- |- |- |null|function name of Json call back|
|keyword|string|- |- |may required|null|key word. One of keyword or genreId is required|
|genreId|int|0|- |may required|0|genre id. One of keyword or genreId is required. The root id of the genreId must be 200162(books, magazine and comic).|
|hits|int|1|30|- |30|items per page.|
|page|int|1|100|- |1|page limits.|
|sort|string|- |- |- |standard|sort type. (mark)affiliateRate, (mark)reviewCount, (mark)itemPrice, (mark)updateTimestamp or random. (mark) means plus or minus mark, each mark means Ascend and Descend. For example, +itemPrice|
|minPrice|int|0|- |- |null|minimum price|
|maxPrice|int|0|- |- |null|maximum price. It must be grater than minPrice.|
|availability|int|0|1|- |1|0:all items, 1:only items that you can buy.|
|field|int|0|1|- |1|0:search widely, 1:search narrowly|
|carrier|int|0|1|- |0|0:PC, 1:mobile|
|imageFlag|int|0|1|- |0|0:all item, 1:only items that has image|
|orFlag|int|0|1|- |0|0:AND keywords, 1:OR keywords|
|NGKeyword|string|- |- |- |null|keyword that you want to omit|
|genreInformationFlag|int|0|1|- |0|No use. cf. searchItem()|
*** searchCd() - search CDs. Uses [CDSearch API|http://webservice.rakuten.co.jp/api/cdsearch/]
This method has same parameters like searchBook(). But the root id of the genreId must be 101311(CD).
*** searchDvd() - search DVDs. Uses [DVDSearch API|http://webservice.rakuten.co.jp/api/dvdsearch/]
This method has same parameters like searchBook(). But the root id of the genreId must be 101354(DVD).
** for the Rakuten Auction
*** searchAuctionItem() - Search items. Uses [AuctionItemSearch API|http://webservice.rakuten.co.jp/api/auctionitemsearch/]
||parameter||type||min||max||required||default||explanation||
|- |- |- |- |- |- |following in params array|
|affiliateId|string|- |- |- |null|affiliate id|
|callBack|string|- |- |- |null|function name of Json call back|
|keyword|string|- |- |may required|null|key word. One of keyword or genreId is required|
|genreId|int|0|- |may required|0|genre id. One of keyword or genreId is required.|
|hits|int|1|30|- |30|items per page.|
|page|int|1|100|- |1|page limits.|
|minPrice|int|0|- |- |null|minimum price|
|maxPrice|int|0|- |- |null|maximum price. It must be grater than minPrice.|
|sort|string|- |- |- |+endTime|sort type. (mark)endTime, (mark)itemPrice, (mark)bidCount or (mark)affiliateRate. (mark) means plus or minus mark, each mark means Ascend and Descend. For example, +itemPrice|
|blowFlag|int|0|1|- |0|0:all items, 1:only items that you can buy without waiting auction's end.|
|itemType|int|0|3|- |0|0:all items, 1:only items that are sold by personal seller, 2:only items that are sold by shops, 3:only items that are sold by auction shops|
|newFlag|int|0|2|- |0|0:all items, 1:only used items, 2:only unused items|
|field|int|0|1|- |1|0:search widely, 1:search narrowly|
|carrier|int|0|1|- |0|0:PC, 1:mobile|
|imageFlag|int|0|1|- |0|0:all item, 1:only items that has image|
|orFlag|int|0|1|- |0|0:AND keywords, 1:OR keywords|
|NGKeyword|string|- |- |- |null|keyword that you want to omit|
*** searchAuctionItemCode() - Retrieve item's information by item code. Uses [AuctionItemCodeSearch API|http://webservice.rakuten.co.jp/api/auctionitemcodesearch/]
||parameter||type||min||max||required||default||explanation||
|code|string|- |- |required|- |item code|
|- |- |- |- |- |- |following in optparams array|
|affiliateId|string|- |- |- |null|affiliate id|
|callBack|string|- |- |- |null|function name of Json call back|
|carrier|int|0|1|- |0|0:PC, 1:mobile|
** for the Rakuten Travel
*** searchSimpleHotel() - Search hotels. Uses [SimpleHotelSearch API|http://webservice.rakuten.co.jp/api/simplehotelsearch/]
||parameter||type||min||max||required||default||explanation||
|- |- |- |- |- |- |following in params array|
|affiliateId|string|- |- |- |null|affiliate id|
|callBack|string|- |- |- |null|function name of Json call back|
|largeClassCode|string|- |- |may required|null|area code. It specifies most wide area. For example, country. You can get the class codes list with getAreaClass(). One of the class codes set, hotelNo or latitude/longitude pair is required.|
|middleClassCode|string|- |- |may required|null|area code. It is children of largeClassCode.|
|smallClassCode|string|- |- |may required|null|area code. It is children of middleClassCode.|
|detailClassCode|string|- |- |may required|null|area code. It is children of smallClassCode.|
|hotelNo|integer|- |- |may required|null|hotel number. One of the class codes set, hotelNo or latitude/longitude pair is required.|
|latitude|float|- |- |may required|null|latitude. One of the class codes set, hotelNo or latitude/longitude pair is required. Unit is specified with datumType.|
|longitude|float|- |- |may required|null|longitude. Unit is specified with datumType.|
|searchRadius|float|0.1|3.0|- |1.0|radius in searching. enable if you use the latitude/longitude pair. Unit is Km.|
|squeezeCondition|string|- |- |- |null|condition of hotel. kinen?only hotels that have no smoking rooms, internet?only hotels where you can enjoy internet, daiyoku?only hotels that have swimming bath, onsen?only hotels that have hot springs.|
|carrier|int|0|1|- |0|0:PC, 1:mobile|
|hits|int|- |- |- |null|limit hit counts. enable if you use the latitude/longitude pair.|
|datumType|int|1|2|- |2|1:Unit is degree, 2:Unit is second.|
*** searchHotelDetail() - Retrieve hotel's information by hotel number. Uses [HotelDetailSearch API|http://webservice.rakuten.co.jp/api/hoteldetailsearch/]
||parameter||type||min||max||required||default||explanation||
|hotelNo|integer|- |- |required|- |hotel number|
|- |- |- |- |- |- |following in optparams array|
|affiliateId|string|- |- |- |null|affiliate id|
|callBack|string|- |- |- |null|function name of Json call back|
|carrier|int|0|1|- |0|0:PC, 1:mobile|
|datumType|int|1|2|- |2|1:Unit is degree, 2:Unit is second.|
*** searchVacantHotel() - Search hotels that have vacant room. Uses [VacantHotelSearch|http://webservice.rakuten.co.jp/api/vacanthotelsearch/]
||parameter||type||min||max||required||default||explanation||
|type|string|- |- |required|hotel|information type. hotel or room.|
|checkinDate|date|- |- |required|null|YYYY-MM-DD in Asia/Tokyo time zone.|
|checkoutDate|date|- |- |required|null|YYYY-MM-DD in Asia/Tokyo time zone.|
|- |- |- |- |- |- |following in optparams array|
|affiliateId|string|- |- |- |null|affiliate id|
|callBack|string|- |- |- |null|function name of Json call back|
|largeClassCode|string|- |- |may required|null|area code. It specifies most wide area. For example, country. You can get the class codes list with getAreaClass(). One of the class codes set, hotelNo or latitude/longitude pair is required.|
|middleClassCode|string|- |- |may required|null|area code. It is children of largeClassCode.|
|smallClassCode|string|- |- |may required|null|area code. It is children of middleClassCode.|
|detailClassCode|string|- |- |may required|null|area code. It is children of smallClassCode.|
|hotelNo|integer|- |- |may required|null|hotel number. One of the class codes set, hotelNo or latitude/longitude pair is required.|
|adultNum|int|1|99|- |1|adult members count|
|upClassNum|int|0|99|- |0|members count. The members are over elementary school higher students.|
|lowClassNum|int|0|99|- |0|members count. The members are under elementary school lower students.|
|infantWithMBNum|int|0|99|- |0|infant members count. They need foods and blankets.|
|infantWithMNum|int|0|99|- |0|infant members count. They need only blankets.|
|infantWithBNum|int|0|99|- |0|infant members count. They need only foods.|
|infantWithoutMBNum|int|0|99|- |0|infant members count. They no need foods and blankets.|
|roomNum|int|1|999|- |1|required room count|
|maxCharge|int|0|9999999999|- |null|0:PC, 1:mobile. It must be grater than minCharge.|
|minCharge|int|0|9999999999|- |null|0:PC, 1:mobile|
|latitude|float|- |- |may required|null|latitude. One of the class codes set, hotelNo or latitude/longitude pair is required. Unit is specified with datumType.|
|longitude|float|- |- |may required|null|longitude. Unit is specified with datumType.|
|searchRadius|float|0.1|3.0|- |1.0|radius in searching. enable if you use the latitude/longitude pair. Unit is Km.|
|squeezeCondition|string|- |- |- |null|condition of hotel. kinen?only hotels that have no smoking rooms, internet?only hotels where you can enjoy internet, daiyoku?only hotels that have swimming bath, onsen?only hotels that have hot springs, breakfast:only hotels where you can take breakfast, dinner:only hotels where you can take dinner.|
|carrier|int|0|1|- |0|0:PC, 1:mobile|
|datumType|int|1|2|- |2|1:Unit is degree, 2:Unit is second.|
|hits|int|- |- |- |null|limit hit counts. enable if you use the latitude/longitude pair.|
*** getAreaClass() - Retrieve choices of area. Uses [GetAreaClass API|http://webservice.rakuten.co.jp/api/getareaclass/]
||parameter||type||min||max||required||default||explanation||
|- |- |- |- |- |- |following in optparams array|
|affiliateId|string|- |- |- |null|affiliate id|
|callBack|string|- |- |- |null|function name of Json call back|
*** searchKeywordHotel() - Search hotels by word. Uses [KeywordHotelSearch API|http://webservice.rakuten.co.jp/api/keywordhotelsearch/]
||parameter||type||min||max||required||default||explanation||
|keyword|string|- |- |required|- |key word.|
|- |- |- |- |- |- |following in optparams array|
|affiliateId|string|- |- |- |null|affiliate id|
|callBack|string|- |- |- |null|function name of Json call back|
|carrier|int|0|1|- |0|0:PC, 1:mobile|
|page|int|- |- |- |1|page limits.|
|hits|int|1|100|- |20|items per page.|
|sumDisplayFlag|int|0|1|- |0|0:not display features about the area and the hotel, 1:display.|
|middleClassCode|string|- |- |- |null|area code. You can get the list with getAreaClass().|
** Other purpose
*** dynamicAd() - Retrieve dynamic advertisements that is suitable for content in URL that you specify. Uses [DynamicAd API|http://webservice.rakuten.co.jp/api/dynamicad/] and [DynamicAd API (travel)|http://webservice.rakuten.co.jp/api/dynamicad_travel/]
||parameter||type||min||max||required||default||explanation||
|type|string|- |- |required|item|advertisement type. item or travel.|
|affiliateId|string|- |- |required|- |affiliate id|
|url|string|- |- |required|- |URL|
|- |- |- |- |- |- |following in optparams array|
|carrier|int|0|1|- |0|0:PC, 1:mobile|
|callBack|string|- |- |- |null|function name of Json call back|
{zone-data}

{zone-data:requirements}
* Implements the "Rakuten Web Service" APIs.
* Returns server responses as lightweight data objects.
{zone-data}

{zone-data:dependencies}
* Zend_Rest_Client
* Zend_Service_Exception
{zone-data}

{zone-data:operation}
Returns server response as the SimpleXMLElement.
{zone-data}

{zone-data:milestones}
* Milestone 1: Class development and write proposal : Finished!
* Milestone 2: Unit tests and debugging : Now working.
* Milestone 3: Documentation : Now working
{zone-data}

{zone-data:class-list}
* ZendX_Service_Rakuten
{zone-data}

{zone-data:use-cases}
||UC-01||
Search 3 items by word, "Zend Studio". Its case is most simple case.
{code}
<?php
require_once 'ZendX/Service/Rakuten.php';

$rakuten = new ZendX_Service_Rakuten(YOUR_DEVELOPER_ID);

$params = array('keyword' => 'Zend Studio', 'hits' => 3);

try {
$results = $rakuten->searchItem($params);
} catch (Zend_Service_Exception $e) {
echo $e->getMessage();
$results = array();
}

foreach ($results as $item) {
echo '<ul>';
echo '<li>Item : ' . $item->itemName;
echo '<li>Code : ' . $item->itemCode;
echo '<li>Price: ' . $item->itemPrice .'JPY';
echo '<li><a href="' . $item->itemUrl . '" target="_blanc">';
echo '<img src="' . $item->mediumImageUrl . '">';
echo 'Click to show detail in new window';
echo '</a>';
echo '<li>Caption:'. $item->itemCaption;
echo '</ul>';
echo '<hr>';
}
{code}

||UC-02||
Retrieve hotels that have vacant room for 1 adult person in the kasukabe city from today to tommorow.
The kasukabe city is in the saitama ward, and the saitama ward is in japan.
The checkinDate and checkoutDate are in Asia/Tokyo (GMT +9) time zone.
{code}
<?php
require_once 'ZendX/Service/Rakuten.php';

$rakuten = new ZendX_Service_Rakuten(YOUR_DEVELOPER_ID);

$checkinDate = date('Y-m-d', strtotime('today'));
$checkoutDate = date('Y-m-d', strtotime('+1 day'));
$optparams = array('largeClassCode' => 'japan',
'middleClassCode' => 'saitama',
'smallClassCode' => 'kasukabe',
'adultNum' => 1);

try {
$results = $this->searchVacantHotel('hotel', $checkinDate, $checkoutDate, $optparams);
} catch (Zend_Service_Exception $e) {
echo $e->getMessage();
$results = array();
}

foreach ($results as $item) {
echo '<ul>';
echo '<li>Name : ' . $item->hotelName;
echo '<li>Address: ' . $item->address1;
echo '<li>Tel :' . $item->telephoneNo;
echo '</ul>';
}
{code}

||UC-03||
Display advertisements that is suitable for www.zend.com .
*dynamicAd()* needs your affiliate ID from the Rakuten web service.
{code}
<?php
require_once 'ZendX/Service/Rakuten.php';

$rakuten = new ZendX_Service_Rakuten(YOUR_DEVELOPER_ID);

try {
$results = $this->dynamicAd('item', YOUR_AFFILIATE_ID, 'http://www.zend.com/');
} catch (Zend_Service_Exception $e) {
echo $e->getMessage();
$results = array();
}

foreach ($results as $item) {
echo '<ul>';
echo '<li>Name : ' . $item->ItemName;
echo '<li>Url : ' . $item->AffiliateItemUrl;
echo '<li>Rev : ' . $item->ReviewCount;
echo '</ul>';
}
{code}
{zone-data}

{zone-data:skeletons}
{code}
<?php
class ZendX_Service_Rakuten
{
/**
* Status from the Rakuten Web Service in success
*
* @var string
*/
const STATUS_OK = 'Success';

/**
* Error message
*
* @var string
*/
const INVALID_OPERATION = 'Invalid operation provided.';
const KEYWORD_OR_GENREID_REQUIRED = '"keyword" or "genreId" is required.';
const HOTELNO_OR_LOCATION_REQUIRED
= '"hotelNo", classcodes set or "latitude"/"longitude" pair is required.';

/**
* Developer's ID in the Rakuten Web Service
*
* @var string
*/
protected $_devId;

/**
* API Version
*
* @var array
*/
protected $_apiVer;

/**
* Instantiation
*
* @param string $devId developer's ID
* @return void
*/
public function __construct($devId)
{
$this->_devId = $devId;
$this->_apiVer = array('api_rws' => '1.12',
'ItemSearch' => '2008-09-01', 'ItemCodeSearch' => '2007-04-11',
'GenreSearch' => '2007-04-11', 'CatalogSearch' => '2007-10-25',
'BookSearch' => '2007-10-25', 'CDSearch' => '2007-10-25',
'DVDSearch' => '2007-10-25', 'ItemRanking' => '2008-09-01',
'AuctionItemSearch' => '2007-12-13', 'AuctionItemCodeSearch' => '2007-12-13',
'SimpleHotelSearch' => '2008-11-13', 'HotelDetailSearch' => '2008-11-13',
'VacantHotelSearch' => '2008-11-13', 'KeywordHotelSearch' => '2008-11-13',
'GetAreaClass' => '2008-02-14',
'DynamicAd' => '1.0'
);
}

/**
* Retrieve version
*
* @param string $operation API name
* @return string
* @throws Zend_Service_Exception
*/
public function getVersion($operation)
{
if (isset($this->_apiVer[$operation]) !== true)
{
require_once 'Zend/Service/Exception.php';
throw new Zend_Service_Exception(self::INVALID_OPERATION);
}

return $this->_apiVer[$operation];
}

/**
* Set the version
*
* @param string $operation API name
* @param string $version API version
* @return void
* @throws Zend_Service_Exception
*/
public function setVersion($operation, $version)
{
if (isset($this->_apiVer[$operation]) !== true)
{
require_once 'Zend/Service/Exception.php';
throw new Zend_Service_Exception(self::INVALID_OPERATION);
}

$this->_apiVer[$operation] = $version;
}

/**
* Execute on the Rakuten Web Service
*
* @param string $operation API name
* @param string $xquery xquery
* @param array $optparams API option parameters ( name => value )
* @return array(SimpleXMLElement)
* @throws Zend_Service_Exception
* @uses Rakuten Web Service requires UTF-8 encode.
*/
protected function _search($operation, $xquery, $optparams = array())
{
$path = '/rws/' . $this->_apiVer['api_rws'] . '/rest';

$params = array_merge(
array('developerId' => $this->_devId,
'operation' => $operation,
'version' => $this->_apiVer[$operation]),
$optparams
);

$xml = $this->_restClient('http://api.rakuten.co.jp', $path, $params);
foreach ($xml->getNamespaces(true) as $name => $uri)
{
$xml->registerXPathNamespace($name, $uri);
}

$statuses = $xml->xpath('//header:Header/Status');
$message = strval($statuses[0]);

if ($message !== self::STATUS_OK)
{
require_once 'Zend/Service/Exception.php';
throw new Zend_Service_Exception($message);
}

return $xml->xpath($xquery);
}

/**
* REST Client
*
* @param string $domain API domain
* @param string $path API path
* @param array $params API parameters ( name => value )
* @return SimpleXMLElement
* @throws Zend_Service_Exception
* @see Zend_Rest_Client
*/
protected function _restClient($domain, $path, $params)
{
require_once 'Zend/Rest/Client.php';
$rest = new Zend_Rest_Client($domain);

try {
$result = $rest->restGet($path, $params);
} catch (Zend_Rest_Client_Exception $e) {
require_once 'Zend/Service/Exception.php';
throw new Zend_Service_Exception($e->getMessage());
}

return new SimpleXMLElement($result->getBody());
}

/**
* Search items from the Rakuten Market.
*
* @see http://webservice.rakuten.co.jp/api/itemsearch/
* @param array $params parameters. "keyword", "genreId" or "catalogCode" is required.
* @return array array(SimpleXMLElement)
* @throws Zend_Service_Exception
*/
public function searchItem($params)
{
if ( isset($params['keyword'])
|| isset($params['genreId'])
|| isset($params['catalogCode'])
){
return $this->_search('ItemSearch', '//itemSearch:ItemSearch/Items/Item', $params);
}else{
require_once 'Zend/Service/Exception.php';
throw new Zend_Service_Exception('"keyword", "genreId" or "catalogCode" is required.');
}
}

/**
* Retrieve genre's information from the Rakuten Market.
*
* @see http://webservice.rakuten.co.jp/api/genresearch/
* @param string $type type of return value. (child = children's id, current = current id , parent = parent's id)
* @param integer $genreId genre ID
* @param array $optparams option parameters
* @return array array(SimpleXMLElement)
*/
public function searchGenre($type = 'child', $genreId = 0, $optparams = array())
{
if ($genreId < 0){
require_once 'Zend/Service/Exception.php';
throw new Zend_Service_Exception('"genreID" must not be minus integer.');
}
switch ($type) {
case 'child':
case 'current':
$genrePath = 0;//no need parent's information
break;
case 'parent':
if ($genreId == 0){
require_once 'Zend/Service/Exception.php';
throw new Zend_Service_Exception('"genreID" must not be zero when "type" is "parent".');
}
$genrePath = 1;//request parent's information
break;
default:
require_once 'Zend/Service/Exception.php';
throw new Zend_Service_Exception(self::INVALID_OPERATION);
break;
}

$params = array_merge(
array('genreId' => $genreId,
'genrePath' => $genrePath),
$optparams
);

return $this->_search('GenreSearch', '//genreSearch:GenreSearch/' . $type, $params);
}

/**
* Retrieve item's information by the item code from the Rakuten Market.
*
* @see http://webservice.rakuten.co.jp/api/itemcodesearch/
* @param string $code item code
* @param array $optparams option parameters
* @return array array(SimpleXMLElement)
*/
public function searchItemCode($code, $optparams = array())
{
$params = array_merge(
array('itemCode' => $code),
$optparams
);

return $this->_search('ItemCodeSearch', '//itemCodeSearch:ItemCodeSearch/Item', $params);
}

/**
* Search items by catalog from the Rakuten Market.
*
* @see http://webservice.rakuten.co.jp/api/catalogsearch/
* @param array $params parameters. "keyword" or "genreId" is required.
* @return array array(SimpleXMLElement)
* @throws Zend_Service_Exception
*/
public function searchCatalog($params)
{
if ( isset($params['keyword'])
|| isset($params['genreId'])
){
return $this->_search('CatalogSearch', '//catalogSearch:CatalogSearch/Catalogs/Catalog', $params);
}else{
require_once 'Zend/Service/Exception.php';
throw new Zend_Service_Exception(self::KEYWORD_OR_GENREID_REQUIRED);
}
}

/**
* Retrieve ranking.
*
* @see http://webservice.rakuten.co.jp/api/itemranking/
*
* @param array $optparams option parameters.
* @return array array(SimpleXMLElement)
*/
public function itemRanking($optparams = array())
{
return $this->_search('ItemRanking', '//itemRanking:ItemRanking/Item', $optparams);
}

/**
* Search books from the Rakuten books.
*
* @see http://webservice.rakuten.co.jp/api/booksearch/
* @param array $params parameters. "keyword" or "genreId" is required.
* @return array array(SimpleXMLElement)
* @throws Zend_Service_Exception
*/
public function searchBook($params)
{
if ( isset($params['keyword'])
|| isset($params['genreId'])
){
return $this->_search('BookSearch', '//bookSearch:BookSearch/Items/Item', $params);
}else{
require_once 'Zend/Service/Exception.php';
throw new Zend_Service_Exception(self::KEYWORD_OR_GENREID_REQUIRED);
}
}

/**
* Search CompactDiscs from the Rakuten books.
*
* @see http://webservice.rakuten.co.jp/api/cdsearch/
* @param array $params parameters. "keyword" or "genreId" is required.
* @return array array(SimpleXMLElement)
* @throws Zend_Service_Exception
*/
public function searchCd($params)
{
if ( isset($params['keyword'])
|| isset($params['genreId'])
){
return $this->_search('CDSearch', '//cdSearch:CDSearch/Items/Item', $params);
}else{
require_once 'Zend/Service/Exception.php';
throw new Zend_Service_Exception(self::KEYWORD_OR_GENREID_REQUIRED);
}
}

/**
* Search DVDs from the Rakuten books.
*
* @see http://webservice.rakuten.co.jp/api/dvdsearch/
* @param array $params parameters. "keyword" or "genreId" is required.
* @return array array(SimpleXMLElement)
* @throws Zend_Service_Exception
*/
public function searchDvd($params)
{
if ( isset($params['keyword'])
|| isset($params['genreId'])
){
return $this->_search('DVDSearch', '//dvdSearch:DVDSearch/Items/Item', $params);
}else{
require_once 'Zend/Service/Exception.php';
throw new Zend_Service_Exception(self::KEYWORD_OR_GENREID_REQUIRED);
}
}

/**
* Search items from the Rakuten auction.
*
* @see http://webservice.rakuten.co.jp/api/auctionitemsearch/
* @param array $params parameters. "keyword" or "genreId" is required.
* @return array array(SimpleXMLElement)
* @throws Zend_Service_Exception
*/
public function searchAuctionItem($params)
{
if ( isset($params['keyword'])
|| isset($params['genreId'])
){
return $this->_search('AuctionItemSearch', '//auctionItemSearch:AuctionItemSearch/Items/Item', $params);
}else{
require_once 'Zend/Service/Exception.php';
throw new Zend_Service_Exception(self::KEYWORD_OR_GENREID_REQUIRED);
}
}

/**
* Retrieve item's information by the item code from the Rakuten auction.
*
* @see http://webservice.rakuten.co.jp/api/auctionitemcodesearch/
* @param string $code item code
* @param array $optparams option parameters
* @return array array(SimpleXMLElement)
*/
public function searchAuctionItemCode($code, $optparams = array())
{
$params = array_merge(
array('itemCode' => $code),
$optparams
);

return $this->_search('AuctionItemCodeSearch', '//auctionItemCodeSearch:AuctionItemCodeSearch/Item', $params);
}

/**
* Search hotels from the Rakuten travel.
*
* @see http://webservice.rakuten.co.jp/api/simplehotelsearch/
* @param array $params parameters. One of following key pairs is required.
* 1:hotelNo.
* 2:largeClassCode, middleClassCode(if defined), smallClassCode(if defined) and detailClassCode(if defined).
* 3:latitude, longitude.
* @return array array(SimpleXMLElement)
* @throws Zend_Service_Exception
*/
public function searchSimpleHotel($params)
{
if ( isset($params['hotelNo'])
|| isset($params['largeClassCode'])
|| (isset($params['latitude']) && isset($params['longitude']))
){
return $this->_search('SimpleHotelSearch', '//simpleHotelSearch:SimpleHotelSearch/hotel', $params);
}else{
require_once 'Zend/Service/Exception.php';
throw new Zend_Service_Exception(self::HOTELNO_OR_LOCATION_REQUIRED);
}
}

/**
* Retrieve hotel's information by the hotel number from the Rakuten travel.
*
* @see http://webservice.rakuten.co.jp/api/hoteldetailsearch/
* @param integer $hotelNo hotel number
* @param array $optparams option parameters
* @return array array(SimpleXMLElement)
*/
public function searchHotelDetail($hotelNo, $optparams = array())
{
$params = array_merge(
array('hotelNo' => $hotelNo),
$optparams
);

return $this->_search('HotelDetailSearch', '//hotelDetailSearch:HotelDetailSearch', $params);
}

/**
* Search hotels that have vacant room from the Rakuten travel.
*
* @see http://webservice.rakuten.co.jp/api/vacanthotelsearch/
* @param string $type search type. (hotel = search Hotel that has vacant rooms, room = search vacant Rooms)
* @param date $checkinDate check in date in Asia/Tokyo (GMT +9) time zone. For example, date('Y-m-d', strtotime('today')).
* @param date $checkoutDate check out date in Asia/Tokyo (GMT +9) time zone. For example, date('Y-m-d', strtotime('+1 day')).
* @param array $optparams option parameters. One of following key pairs is required.
* 1:hotelNo.
* 2:largeClassCode, middleClassCode(if defined), smallClassCode(if defined) and detailClassCode(if defined).
* 3:latitude, longitude.
* @return array array(SimpleXMLElement)
* @throws Zend_Service_Exception
*/
public function searchVacantHotel($type = 'hotel', $checkinDate, $checkoutDate, $optparams = array())
{
if (!in_array($type, array('hotel','room')))
{
require_once 'Zend/Service/Exception.php';
throw new Zend_Service_Exception(self::INVALID_OPERATION);
}
if ( isset($optparams['hotelNo'])
|| isset($optparams['largeClassCode'])
|| (isset($optparams['latitude']) && isset($optparams['longitude']))
){
$params = array_merge(
array('checkinDate' => $checkinDate,
'checkoutDate' => $checkoutDate),
$optparams
);

return $this->_search('VacantHotelSearch',
'//vacantHotelSearch:VacantHotelSearch/' . $type,
$params);
}else{
require_once 'Zend/Service/Exception.php';
throw new Zend_Service_Exception(self::HOTELNO_OR_LOCATION_REQUIRED);
}
}

/**
* Retrieve choices of area from the Rakuten travel.
*
* @see http://webservice.rakuten.co.jp/api/getareaclass/
* @param array $optparams API option parameters ( name => value )
* @return array array(SimpleXMLElement)
*/
public function getAreaClass($optparams = array())
{
return $this->_search('GetAreaClass', '//getAreaClass:GetAreaClass/largeClass', $optparams);
}

/**
* Search hotels by the word from the Rakuten travel.
*
* @see http://webservice.rakuten.co.jp/api/keywordhotelsearch/
* @param string $keyword keyword
* @param array $optparams option parameters
* @return array array(SimpleXMLElement)
*/
public function searchKeywordHotel($keyword, $optparams = array())
{
$params = array_merge(
array('keyword' => $keyword),
$optparams
);

return $this->_search('KeywordHotelSearch', '//keywordHotelSearch:KeywordHotelSearch/hotelSimple', $params);
}

/**
* Retrieve advertisements that is suitable for the url.
*
* @see http://webservice.rakuten.co.jp/api/dynamicad/
* @param string $type advertisement type. ("item" or "travel")
* @param string $affiliateId affiliate ID
* @param string $url url
* @param array $optparams API option parameters ( name => value )
* @return array(SimpleXMLElement)
* @throws Zend_Service_Exception
* @link _search()
*/
public function dynamicAd($type = 'item', $affiliateId, $url, $optparams = array())
{
switch ($type) {
case 'item':
$type = 'i';
break;
case 'travel':
$type = 't';
break;
default:
require_once 'Zend/Service/Exception.php';
throw new Zend_Service_Exception(self::INVALID_OPERATION);
break;
}

$path = '/rcm/' . $this->_apiVer['DynamicAd'] . '/' . $type . '/rest';

$params = array_merge(
array('developerId' => $this->_devId,
'affiliateId' => $affiliateId,
'url' => $url),
$optparams
);

$xml = $this->_restClient('http://dynamic.rakuten.co.jp', $path, $params);

$statuses = $xml->Header->Status;
$message = strval($statuses[0]);

if ($message !== self::STATUS_OK)
{
require_once 'Zend/Service/Exception.php';
throw new Zend_Service_Exception($message);
}

return $xml->Body->Ads->Ad;
}
}
{code}

{zone-data}

{zone-template-instance}]]></ac:plain-text-body></ac:macro>