Hotpepper API
- 追è¨
Services_Hotpepperãéçºããã¦ããæ¹ããã¾ãã®ã§ãä½ããµã¼ãã¹ãä½æããéã¯ãã¡ãã使ãããäºããå§ããã¾ãã
過去と他人はかえられないが、未来と自分はかえられる - Services_Hotpepper
GANCHIKU.com » とりあえず、ソースコード吐いていいかね。Services_HotPepper-0.1.0?(訂正)
-
-
- -
-
æ¸ãã¦ã¿ãã
http://api.hotpepper.jp/reference.html
使ãæ¹
$req = new Hotpepper; $req->setKey('guest'); // ç¾æç¹ã§ã¯guestã§åºå® $res=$req->GourmetSearch();
ããã ãã
$optionsã«è²ã
ã»ããããã¨è²ã
åºæ¥ããããã
require_once 'HTTP/Request.php'; require_once 'XML/Unserializer.php'; define('HOTPEPPER_API_URL', 'http://api.hotpepper.jp/'); define('HOTPEPPER_API_VERSION', 'V1'); class Hotpepper { var $queryType = array('GourmetSearch', 'LargeServiceArea', 'ServiceArea', 'LargeArea', 'MiddleArea', 'SmallArea', 'Genre', 'Budget'); var $key; function Hotpepper(){} function GourmetSearch($options=array()) { $options['queryType'] = 'GourmetSearch'; $res=$this->_sendRequest($options); if (PEAR::isError($res)) { return $res; } return $this->_bindResult($res); } function LargeServiceArea() { $options = array('queryType' => 'LargeServiceArea'); $res=$this->_sendRequest($options); if (PEAR::isError($res)) { return $res; } return $this->_bindResult($res); } function ServiceArea() { $options = array('queryType' => 'ServiceArea'); $res=$this->_sendRequest($options); if (PEAR::isError($res)) { return $res; } return $this->_bindResult($res); } function LargeArea() { $options = array('queryType' => 'LargeArea'); $res=$this->_sendRequest($options); if (PEAR::isError($res)) { return $res; } return $this->_bindResult($res); } function MiddleArea() { $options = array('queryType' => 'MiddleArea'); $res=$this->_sendRequest($options); if (PEAR::isError($res)) { return $res; } return $this->_bindResult($res); } function SmallArea() { $options = array('queryType' => 'SmallArea'); $res=$this->_sendRequest($options); if (PEAR::isError($res)) { return $res; } return $this->_bindResult($res); } function Genre() { $options = array('queryType' => 'Genre'); $res=$this->_sendRequest($options); if (PEAR::isError($res)) { return $res; } return $this->_bindResult($res); } function Budget() { $options = array('queryType' => 'Budget'); $res=$this->_sendRequest($options); if (PEAR::isError($res)) { return $res; } return $this->_bindResult($res); } function _bindResult($result) { $obj = new StdClass(); foreach ($result as $key => $val) { $obj->{$key} = $val; } return $obj; } function _sendRequest($options) { if (!isset($options['queryType']) || !in_array($options['queryType'], $this->queryType)) { return PEAR::raiseError('queryType not set'); } $reqUrl = HOTPEPPER_API_URL . $options['queryType'] . '/' . HOTPEPPER_API_VERSION . '/'; $req = new HTTP_Request($reqUrl); $req->setMethod('GET'); $req->addQueryString('key', $this->key); foreach ($options as $param => $value) { $req->addQueryString($param, $value); } $res=$req->sendRequest(); if (PEAR::isError($res)) { return $res; } if ($req->getResponseCode() != '200') { return PEAR::raiseError('Hotpepper API Error'); } $res=$req->getResponseBody(); if (!$res) { return PEAR::raiseError('Hotpepper returns Empty Body'); } $xml = new XML_Unserializer(); if (!$xml->unserialize($res)) { return PEAR::raiseError('XML Unserialize Error'); } return $xml->getUnserializedData(); } function setKey($key) { $this->key = $key; } }