Ejemplo n.º 1
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)
 {
     /**
      * @see Zend_Service_Rest
      */
     require_once 'Zend/Rest/Client.php';
     $this->_rest = new Zend_Rest_Client($this->_baseUri);
     $this->_rest->getHttpClient()->setAuth($username, $password);
 }
Ejemplo n.º 2
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);
 }
Ejemplo n.º 3
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);
     }
 }
Ejemplo n.º 4
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));
     }
 }
Ejemplo n.º 5
0
 /**
  * 
  * @return void
  */
 public function setUp()
 {
     Zend_Service_Rest::getHttpClient()->setConfig(array('useragent' => 'Zend_Service_Delicious - Unit tests/0.01', 'keepalive' => true));
     $this->_delicious = new Zend_Service_Delicious(self::TEST_UNAME, self::TEST_PASS);
 }