Exemple #1
0
 /**
  * Zend_Service_Flickr Constructor, setup character encoding
  *
  * @param string $apiKey Your Flickr API key
  */
 public function __construct($apiKey)
 {
     iconv_set_encoding('output_encoding', 'UTF-8');
     iconv_set_encoding('input_encoding', 'UTF-8');
     iconv_set_encoding('internal_encoding', 'UTF-8');
     $this->apiKey = $apiKey;
     $this->_rest = new Zend_Service_Rest();
     $this->_rest->setUri('http://www.flickr.com');
     $this->_array = array();
 }
 /**
  * Zend_Service_Audioscrobbler Constructor, setup character encoding
  */
 public function __construct()
 {
     $this->set('version', '1.0');
     iconv_set_encoding('output_encoding', 'UTF-8');
     iconv_set_encoding('input_encoding', 'UTF-8');
     iconv_set_encoding('internal_encoding', 'UTF-8');
     try {
         $this->_rest = new Zend_Service_Rest();
         $this->_rest->setUri('http://ws.audioscrobbler.com');
     } catch (Zend_Http_Client_Exception $e) {
         throw $e;
     }
 }
Exemple #3
0
 /**
  * Constructs a new Simpy (free) REST API Client
  *
  * @param  string $username Username for the Simpy user account
  * @param  string $password Password for the Simpy user account
  * @return void
  */
 public function __construct($username, $password)
 {
     $this->_rest = new Zend_Rest_Client();
     $this->_rest->setUri(Zend_Uri::factory($this->_baseUri));
     $http = $this->_rest->getHttpClient();
     $http->setAuth($username, $password);
 }
Exemple #4
0
 /**
  * Handles all GET requests to a web service
  *
  * @param   string $path  Path
  * @param   array  $parms Array of GET parameters
  * @param   string $type  Type of a request ("xml"|"json")
  * @return  mixed  decoded response from web service
  * @throws  Zend_Service_Delicious_Exception
  */
 public function makeRequest($path, array $parms = array(), $type = 'xml')
 {
     // if previous request was made less then 1 sec ago
     // wait until we can make a new request
     $timeDiff = microtime(true) - self::$_lastRequestTime;
     if ($timeDiff < 1) {
         //TODO:trouver
         //usleep((1 - $timeDiff) * 1000000);
     }
     $this->_rest->getHttpClient()->setAuth($this->_authUname, $this->_authPass);
     switch ($type) {
         case 'xml':
             $this->_rest->setUri(self::API_URI);
             break;
         case 'json':
             $parms['raw'] = true;
             $this->_rest->setUri(self::JSON_URI);
             break;
         default:
             /**
              * @see Zend_Service_Delicious_Exception
              */
             require_once PHP_LIBRARY_PATH . 'Zend/Service/Delicious/Exception.php';
             throw new Zend_Service_Delicious_Exception('Unknown request type');
     }
     self::$_lastRequestTime = microtime(true);
     $response = $this->_rest->restGet($path, $parms);
     if (!$response->isSuccessful()) {
         /**
          * @see Zend_Service_Delicious_Exception
          */
         require_once PHP_LIBRARY_PATH . 'Zend/Service/Delicious/Exception.php';
         throw new Zend_Service_Delicious_Exception("Http client reported an error: '{$response->getMessage()}'");
     }
     $responseBody = $response->getBody();
     switch ($type) {
         case 'xml':
             $dom = new DOMDocument();
             if (!@$dom->loadXML($responseBody)) {
                 /**
                  * @see Zend_Service_Delicious_Exception
                  */
                 require_once PHP_LIBRARY_PATH . 'Zend/Service/Delicious/Exception.php';
                 throw new Zend_Service_Delicious_Exception('XML Error');
             }
             return $dom;
         case 'json':
             return Zend_Json_Decoder::decode($responseBody);
     }
 }
Exemple #5
0
 /**
  * Constructs a new Simpy (free) REST API Client
  *
  * @param string $username Username for the Simpy user account
  * @param string $password Password for the Simpy user account
  * @return Zend_Service_Simpy
  */
 public function __construct($username, $password)
 {
     /**
      * If the incubator version of Zend_Http_Client is being used, call its
      * HTTP authentication method, or else just use a temporary shorthand
      */
     $this->_rest = new Zend_Service_Rest();
     $this->_rest->setUri(Zend_Uri::factory($this->_baseUri));
     $http = $this->_rest->getHttpClient();
     if (in_array('setAuth', get_class_methods('Zend_Http_Client'))) {
         $http->setAuth($username, $password);
     } else {
         $headerValue = 'Basic ' . base64_encode($username . ':' . $password);
         $http->setHeaders(array('Authorization: ' . $headerValue));
     }
 }
Exemple #6
0
 /**
  * Perform a search of images.  The most basic query consists simply
  * of a plain text search, but you can also specify the type of
  * image, the format, color, etc.
  *
  * The specific options are:
  * 'type'       => (all|any|phrase)  How to parse the query terms
  * 'results'    => int  How many results to return, max is 50
  * 'start'      => int  The start offset for search results
  * 'format'     => (any|bmp|gif|jpeg|png)  The type of images to search for
  * 'coloration' => (any|color|bw)  The coloration of images to search for
  * 'adult_ok'   => bool  Flag to allow 'adult' images.
  *
  * @param string $query the query to be run
  * @param array $options an optional array of query options.
  * @return Zend_Service_Yahoo_ImageResultSet the search results
  */
 public function imageSearch($query, $options = NULL)
 {
     static $default_options = array('type' => 'all', 'results' => 10, 'start' => 1, 'format' => 'any', 'coloration' => 'any');
     $options = $this->_prepareOptions($query, $options, $default_options);
     $this->_validateImageSearch($options);
     $this->_rest = new Zend_Service_Rest();
     $this->_rest->setUri('api.search.yahoo.com');
     $response = $this->_rest->restGet('/ImageSearchService/V1/imageSearch', $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_ImageResultSet($dom);
 }
Exemple #7
0
 /**
  * Constructs a new Amazon Web Services Client
  *
  * @param string $appId Developer's Amazon appid
  * @param string $countryCode Country code for Amazon service to connect to.
  * Defaults to US, can be US, UK, DE, JP, FR, CA
  * @throws Zend_Service_Exception
  * @return Zend_Service_Amazon
  */
 public function __construct($appId, $countryCode = 'US')
 {
     $this->appId = $appId;
     if (!isset($this->_baseUriList[$countryCode])) {
         throw new Zend_Service_Exception("Amazon Web Service: Unknown country code: {$countryCode}");
     }
     $this->_array = array();
     $this->_rest = new Zend_Service_Rest();
     $this->_rest->setUri($this->_baseUriList[$countryCode]);
 }