public function testUri() { $client = new Zend_Rest_Client('http://framework.zend.com/rest/'); $uri = $client->getUri(); $this->assertTrue($uri instanceof Zend_Uri_Http); $this->assertEquals('http://framework.zend.com/rest/', $uri->getUri()); $client->setUri(Zend_Uri::factory('http://framework.zend.com/soap/')); $uri = $client->getUri(); $this->assertTrue($uri instanceof Zend_Uri_Http); $this->assertEquals('http://framework.zend.com/soap/', $uri->getUri()); $client->setUri('http://framework.zend.com/xmlrpc/'); $uri = $client->getUri(); $this->assertTrue($uri instanceof Zend_Uri_Http); $this->assertEquals('http://framework.zend.com/xmlrpc/', $uri->getUri()); }
/** * Perform a web content search on search.yahoo.com. A basic query * consists simply of a text query. Additional options that can be * specified consist of: * 'results' => int How many results to return, max is 50 * 'start' => int The start offset for search results * 'language' => lang The target document language to match * 'type' => (all|any|phrase) How the query should be parsed * 'site' => string A site to which your search should be restricted * 'format' => (any|html|msword|pdf|ppt|rss|txt|xls) * 'adult_ok' => bool permit 'adult' content in the search results * 'similar_ok' => bool permit similar results in the result set * 'country' => string The country code for the content searched * 'license' => (any|cc_any|cc_commercial|cc_modifiable) The license of content being searched * 'region' => The regional search engine on which the service performs the search. default us. * * @param string $query the query being run * @param array $options any optional parameters * @return Zend_Service_Yahoo_WebResultSet The return set * @throws Zend\Service\Exception */ public function webSearch($query, array $options = array()) { static $defaultOptions = array('type' => 'all', 'start' => 1, 'results' => 10, 'format' => 'any'); $options = $this->_prepareOptions($query, $options, $defaultOptions); $this->_validateWebSearch($options); $this->_rest->getHttpClient()->resetParameters(); $this->_rest->setUri('http://search.yahooapis.com'); $response = $this->_rest->restGet('/WebSearchService/V1/webSearch', $options); if ($response->isError()) { throw new Zend\Service\Exception('An error occurred sending request. Status code: ' . $response->getStatus()); } $dom = new DOMDocument(); $dom->loadXML($response->getBody()); self::_checkErrors($dom); return new Zend_Service_Yahoo_WebResultSet($dom); }
public function testUri() { if (!defined('TESTS_ZEND_REST_ONLINE_ENABLED') || !constant('TESTS_ZEND_REST_ONLINE_ENABLED')) { $this->markTestSkipped('Define TESTS_ZEND_REST_ONLINE_ENABLED to test Zend_Rest_ClientTest online.'); } $client = new Zend_Rest_Client('http://framework.zend.com/rest/'); $uri = $client->getUri(); $this->assertTrue($uri instanceof Zend_Uri_Http); $this->assertEquals('http://framework.zend.com/rest/', $uri->getUri()); $client->setUri(Zend_Uri::factory('http://framework.zend.com/soap/')); $uri = $client->getUri(); $this->assertTrue($uri instanceof Zend_Uri_Http); $this->assertEquals('http://framework.zend.com/soap/', $uri->getUri()); $client->setUri('http://framework.zend.com/xmlrpc/'); $uri = $client->getUri(); $this->assertTrue($uri instanceof Zend_Uri_Http); $this->assertEquals('http://framework.zend.com/xmlrpc/', $uri->getUri()); }
/** * Perform a web content search on search.yahoo.com. A basic query * consists simply of a text query. Additional options that can be * specified consist of: * 'results' => int How many results to return, max is 50 * 'start' => int The start offset for search results * 'language' => lang The target document language to match * 'type' => (all|any|phrase) How the query should be parsed * 'site' => string A site to which your search should be restricted * 'format' => (any|html|msword|pdf|ppt|rss|txt|xls) * 'adult_ok' => bool permit 'adult' content in the search results * 'similar_ok' => bool permit similar results in the result set * 'country' => string The country code for the content searched * 'license' => (any|cc_any|cc_commercial|cc_modifiable) The license of content being searched * 'region' => The regional search engine on which the service performs the search. default us. * * @param string $query the query being run * @param array $options any optional parameters * @return Zend_Service_Yahoo_WebResultSet The return set * @throws Zend_Service_Exception */ public function webSearch($query, array $options = array()) { static $defaultOptions = array('type' => 'all', 'start' => 1, 'results' => 10, 'format' => 'any'); $options = $this->_prepareOptions($query, $options, $defaultOptions); $this->_validateWebSearch($options); $this->_rest->getHttpClient()->resetParameters(); $this->_rest->setUri('http://search.yahooapis.com'); $response = $this->_rest->restGet('/WebSearchService/V1/webSearch', $options); if ($response->isError()) { /** * @see Zend_Service_Exception */ require_once LIB_DIR . '/Zend/Service/Exception.php'; throw new Zend_Service_Exception('An error occurred sending request. Status code: ' . $response->getStatus()); } $dom = new DOMDocument(); $dom = Zend_Xml_Security::scan($response->getBody(), $dom); self::_checkErrors($dom); /** * @see Zend_Service_Yahoo_WebResultSet */ require_once LIB_DIR . '/Zend/Service/Yahoo/WebResultSet.php'; return new Zend_Service_Yahoo_WebResultSet($dom); }
/** * Handles all GET requests to a web service * * @param string $method Requested API method * @param array $params Array of GET parameters * @return mixed decoded response from web service * @throws Bgy_Service_Geonames_Exception */ public function makeRequest($method, $params = array()) { $this->_rest->setUri(self::API_URI); $path = $method; $type = self::$_supportedMethods[$path]['output']; // Construct the path accordingly to the output type switch ($type) { case 'json': $path = $path . 'JSON'; break; case 'xml': $params += array('type' => 'xml'); break; default: /** * @see Bgy_Service_Geonames_Exception */ require_once 'Bgy/Service/Geonames/Exception.php'; throw new Bgy_Service_Geonames_Exception('Unknown request type'); } if (null !== $this->getUsername()) { $params['username'] = $this->getUsername(); } if (null !== $this->getToken()) { $params['token'] = $this->getToken(); } $response = $this->_rest->restGet($path, $params); if (!$response->isSuccessful()) { /** * @see Bgy_Service_Geonames_Exception */ require_once 'Bgy/Service/Geonames/Exception.php'; throw new Bgy_Service_Geonames_Exception("Http client reported an error: '{$response->getMessage()}'"); } $responseBody = $response->getBody(); switch ($type) { case 'xml': $dom = new DOMDocument(); if (!@$dom->loadXML($responseBody)) { /** * @see Bgy_Service_Geonames_Exception */ require_once 'Bgy/Service/Geonames/Exception.php'; throw new Bgy_Service_Geonames_Exception('Malformed XML'); } $jsonResult = Zend_Json::fromXml($dom->saveXML()); break; case 'json': $jsonResult = $responseBody; break; } $arrayFromJson = Zend_Json::decode($jsonResult); if (isset(self::$_supportedMethods[$method]['root']) && null !== ($root = self::$_supportedMethods[$method]['root']) && isset($arrayFromJson[$root])) { $arrayFromJson = $arrayFromJson[$root]; } return $arrayFromJson; }
/** * Set URI to REST client * * @param string $uri * @return Dhl_Account_Model_Rest_Adapter */ public function setUri($uri) { parent::setUri($uri); $this->client->setUri($this->uri); return $this; }