当前位置: 首页>>代码示例>>PHP>>正文


PHP Zend_Rest_Client::restGet方法代码示例

本文整理汇总了PHP中Zend_Rest_Client::restGet方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Rest_Client::restGet方法的具体用法?PHP Zend_Rest_Client::restGet怎么用?PHP Zend_Rest_Client::restGet使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Zend_Rest_Client的用法示例。


在下文中一共展示了Zend_Rest_Client::restGet方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: webSearch

    /**
     * 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);
    }
开发者ID:niallmccrudden,项目名称:zf2,代码行数:47,代码来源:Yahoo.php

示例2: itemLookup

 /**
  * Look up item(s) by ASIN
  *
  * @param  string $asin    Amazon ASIN ID
  * @param  array  $options Query Options
  * @see http://www.amazon.com/gp/aws/sdk/main.html/102-9041115-9057709?s=AWSEcommerceService&v=2005-10-05&p=ApiReference/ItemLookupOperation
  * @throws Zend_Service_Exception
  * @return Zend_Service_Amazon_Item|Zend_Service_Amazon_ResultSet
  */
 public function itemLookup($asin, array $options = array())
 {
     $defaultOptions = array('IdType' => 'ASIN', 'ResponseGroup' => 'Small');
     $options['ItemId'] = (string) $asin;
     $options = $this->_prepareOptions('ItemLookup', $options, $defaultOptions);
     $this->_rest->getHttpClient()->resetParameters();
     $response = $this->_rest->restGet('/onca/xml', $options);
     if ($response->isError()) {
         /**
          * @see Zend_Service_Exception
          */
         require_once 'Zend/Service/Exception.php';
         throw new Zend_Service_Exception('An error occurred sending request. Status code: ' . $response->getStatus());
     }
     $dom = new DOMDocument();
     $dom->loadXML($response->getBody());
     self::_checkErrors($dom);
     $xpath = new DOMXPath($dom);
     $xpath->registerNamespace('az', 'http://webservices.amazon.com/AWSECommerceService/2005-10-05');
     $items = $xpath->query('//az:Items/az:Item');
     if ($items->length == 1) {
         /**
          * @see Zend_Service_Amazon_Item
          */
         require_once 'Zend/Service/Amazon/Item.php';
         return new Zend_Service_Amazon_Item($items->item(0));
     }
     /**
      * @see Zend_Service_Amazon_ResultSet
      */
     require_once 'Zend/Service/Amazon/ResultSet.php';
     return new Zend_Service_Amazon_ResultSet($dom);
 }
开发者ID:Mendim,项目名称:gtv-resources,代码行数:42,代码来源:Amazon.php

示例3: getRecommendations

 /**
  * Get recommendations from recommender API
  * @param string $type
  * @param array  $parameters
  * @return array
  */
 public function getRecommendations($type, $parameters)
 {
     try {
         $response = $this->_client->restGet(sprintf('/recommend/%s', $type), $parameters);
         $this->_recommendLogger->logApiCall($this->_client, $response);
         if ($response->getStatus() !== 200) {
             throw new \Zend_Http_Client_Exception('Recommender failed to respond');
         }
         $recommendations = json_decode($response->getRawBody(), true);
         if (is_array($recommendations)) {
             return $recommendations;
         }
     } catch (\Zend_Http_Client_Exception $e) {
         $this->_recommendLogger->logApiCallException($this->_client, $e);
     }
     return [];
 }
开发者ID:halk,项目名称:recowise-magento2-demo,代码行数:23,代码来源:Client.php

示例4: testRestFixesPathWithMissingSlashes

 public function testRestFixesPathWithMissingSlashes()
 {
     $expXml = file_get_contents($this->path . 'returnString.xml');
     $response = "HTTP/1.0 200 OK\r\n" . "X-powered-by: PHP/5.2.0\r\n" . "Content-type: text/xml\r\n" . "Content-length: " . strlen($expXml) . "\r\n" . "Server: Apache/1.3.34 (Unix) PHP/5.2.0)\r\n" . "Date: Tue, 06 Feb 2007 15:01:47 GMT\r\n" . "Connection: close\r\n" . "\r\n" . $expXml;
     $this->adapter->setResponse($response);
     $rest = new Zend_Rest_Client('http://framework.zend.com');
     $response = $rest->restGet('rest');
     $this->assertTrue($response instanceof Zend_Http_Response);
     $this->assertContains($expXml, $response->getBody());
 }
开发者ID:travisj,项目名称:zf,代码行数:10,代码来源:ClientTest.php

示例5: getImageDetails

 /**
  * Utility function to find Flickr photo details by ID.
  * @param string $id the NSID
  * @return Zend_Service_Flickr_Image the details for the specified image
  */
 public function getImageDetails($id)
 {
     static $method = 'flickr.photos.getSizes';
     $options = array('api_key' => $this->apiKey, 'method' => $method, 'photo_id' => $id);
     if (!empty($id)) {
         $response = $this->_rest->restGet('/services/rest/', $options);
         $dom = new DOMDocument();
         $dom->loadXML($response->getBody());
         $xpath = new DOMXPath($dom);
         self::_checkErrors($dom);
         $return = array();
         foreach ($xpath->query('//size') as $size) {
             $label = (string) $size->getAttribute('label');
             $retval[$label] = new Zend_Service_Flickr_Image($size);
         }
     } else {
         throw new Zend_Service_Exception('You must supply a photo ID');
     }
     return $retval;
 }
开发者ID:jorgenils,项目名称:zend-framework,代码行数:25,代码来源:Flickr.php

示例6: itemLookup

 /**
  * Look up for a Single Item
  *
  * @param string $asin Amazon ASIN ID
  * @param array $options Query Options
  * @see http://www.amazon.com/gp/aws/sdk/main.html/102-9041115-9057709?s=AWSEcommerceService&v=2005-10-05&p=ApiReference/ItemLookupOperation
  * @throws Zend_Service_Exception
  * @return Zend_Service_Amazon_Item|Zend_Service_Amazon_ResultSet|null
  */
 public function itemLookup($asin, $options = null)
 {
     if (!$options) {
         $options = array();
     }
     $defaultOptions = array('IdType' => 'ASIN', 'ResponseGroup' => 'Small');
     $options['ItemId'] = $asin;
     $options = $this->_prepareOptions('ItemLookup', $options, $defaultOptions);
     $this->_validateItemLookup($options);
     $response = $this->_rest->restGet('/onca/xml', $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);
     $xpath = new DOMXPath($dom);
     $xpath->registerNamespace('az', 'http://webservices.amazon.com/AWSECommerceService/2005-10-05');
     $items = $xpath->query('//az:Items/az:Item');
     if ($items->length == 1) {
         return new Zend_Service_Amazon_Item($items->item(0));
     } elseif ($items->length > 1) {
         return new Zend_Service_Amazon_ResultSet($items);
     }
     return null;
 }
开发者ID:jorgenils,项目名称:zend-framework,代码行数:35,代码来源:Amazon.php

示例7: array

require_once 'Zend/Rest/Client.php';
require_once 'Zend/Debug.php';
// client
$client = new Zend_Rest_Client('http://localhost:5984');
// compose document
$document = array();
$document['title'] = 'document title';
$document['content'] = 'document content';
// JSON-ize document
$document = Zend_Json::encode($document);
// add document (use POST here)
$response = $client->restPost('test', $document);
// print response
Zend_Debug::dump($response);
// get document
$response = $client->restGet('test/c447a8366d74d880f35720d92d68419e');
// un-Json-ize document
$document = Zend_Json::decode($response->getBody());
// print document
Zend_Debug::dump($document);
// change values
$document['title'] = '"updated title!"';
// update document
$response = $client->restPut('test/c447a8366d74d880f35720d92d68419e', Zend_Json::encode($document));
// print response
Zend_Debug::dump($response);
// get all documents
$response = $client->restGet('test/_all_docs');
// print all docs
Zend_Debug::dump($response);
// next: views
开发者ID:Rud5G,项目名称:couchdb-zend-rest,代码行数:31,代码来源:index.php

示例8: makeRequest

 /**
  * 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;
 }
开发者ID:exstas87,项目名称:bgylibrary,代码行数:65,代码来源:Geonames.php

示例9: getActiveState

 /**
  * check whether the bar is active
  *
  * @return array
  */
 public function getActiveState()
 {
     $csConfig = Mage::getModel("commercesciences_base/config")->load("1");
     if (!$csConfig) {
         //we must be already at least on step 1, so the DB record has to exist
         Mage::log("Error - no csConfig");
         return array('error' => $this->__("Error ocurred. Your updates weren't saved. Please contact ComemrceScience for support (error id: 005)"));
     }
     Mage::log("csConfig=" . print_r($csConfig, true), true);
     // TODO Ron Gross 2/1/2013 - refactor into a method
     $RESTClient = new Zend_Rest_Client($csConfig->getCsApiUrl());
     $httpClient = $RESTClient->getHttpClient();
     $httpClient->setConfig(array("timeout" => 30));
     try {
         $response = $RESTClient->restGet("/magento/getBarStatus", array('userID' => $csConfig->getUserId(), 'securityToken' => $csConfig->getSecurityToken()));
         $responseJson = $response->getBody();
         $parsedResponseArr = $this->stdObject2Array(json_decode($responseJson));
         if (!isset($parsedResponseArr['good'])) {
             Mage::log("Server busy");
             return array('error' => $this->__("The CommerceSciences server is currently busy, your updates weren't saved. Please try again later.  (error id: 006)"));
         }
         if ($parsedResponseArr['good'] == false) {
             if (isset($parsedResponseArr['fieldErrors']) && $parsedResponseArr['fieldErrors']) {
                 $fieldErrorsArr = $this->stdObject2Array($parsedResponseArr['fieldErrors']);
                 $errorMsg = '';
                 foreach ($fieldErrorsArr as $field => $fError) {
                     $errorMsg .= "<br />";
                     $errorMsg .= $this->__($field) . ": " . $this->__($fError);
                 }
                 $errorMsg = substr($errorMsg, 0, strlen($errorMsg) - 1);
                 Mage::log("Error (fieldErrors) - " . $errorMsg);
                 return array('error' => $errorMsg);
             } elseif (isset($parsedResponseArr['globalError']) && $parsedResponseArr['globalError']) {
                 Mage::log("Error (globalError) - " . $parsedResponseArr['globalError']);
                 return array('error' => $parsedResponseArr['globalError']);
             }
         }
         Mage::log("Returning data: " . $parsedResponseArr['data']);
         return array('error' => false, 'data' => $parsedResponseArr['data']);
     } catch (Exception $e) {
         Mage::log("Got error: " . print_r($e, true));
         return array('error' => $this->__($e->getMessage()));
     }
 }
开发者ID:jokusafet,项目名称:MagentoSource,代码行数:49,代码来源:Data.php


注:本文中的Zend_Rest_Client::restGet方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。