public function delete(Model $model, $id = null)
 {
     if (!empty($model->request['method'])) {
         unset($model->request['method']);
     }
     return parent::delete($model, $id);
 }
 /**
  * Overloads the RestSource::request() method to add Bitly API specific
  * elements to the request property of the passed model before sending it off
  * to the RestSource::request() method that actually issues the request and
  * decodes the response.
  *
  * @param AppModel $model The model the call was made on. Expects the model
  * object to have a request property in the form of HttpSocket::request
  * @return mixed
  */
 public function request(&$model)
 {
     if (!isset($model->request['uri']['host'])) {
         $model->request['uri']['host'] = 'api.bit.ly';
     }
     if (!isset($model->request['uri']['query']['login'])) {
         $model->request['uri']['query']['login'] = $this->config['login'];
     }
     if (!isset($model->request['uri']['query']['apiKey'])) {
         $model->request['uri']['query']['apiKey'] = $this->config['apiKey'];
     }
     $response = parent::request($model);
     if (!$response) {
         return $response;
     }
     if (substr($model->request['uri']['path'], -4) == '.rss') {
         return $response;
     }
     if (is_string($response)) {
         $response = json_decode($response, true);
     }
     if (!is_array($response)) {
         return $response;
     }
     if (!isset($response['status_code'])) {
         return $response;
     }
     if ($response['status_code'] != 200) {
         return false;
     }
     if (!isset($response['data'])) {
         return $response;
     }
     return $model->response = $response['data'];
 }
 /**
  * Overloads the RestSource::request() method to add Yahoo GeoPlanet API
  * specific elements to the request property of the passed model before
  * sending it off to the RestSource::request() method that actually issues the
  * request and decodes the response.
  * 
  * @param AppModel $model The model the call was made on. Expects the model
  * object to have a request property in the form of HttpSocket::request
  * @return mixed
  */
 public function request(&$model)
 {
     if (!isset($model->request['uri']['host'])) {
         $model->request['uri']['host'] = 'where.yahooapis.com';
     }
     if (!isset($model->request['uri']['query']['appid'])) {
         $model->request['uri']['query']['appid'] = $this->config['appid'];
     }
     if (!isset($model->request['uri']['query']['format'])) {
         $model->request['uri']['query']['format'] = 'json';
     }
     // Prefixes the path element of the request with 'v1/' if a version is not
     // already present.
     if (isset($model->request['uri']['path']) && !preg_match('/^v\\d+/', $model->request['uri']['path'])) {
         $model->request['uri']['path'] = 'v1/' . $model->request['uri']['path'];
     }
     $response = parent::request($model);
     return $response;
 }
 /**
  * Adds in common elements to the request such as GData version and Developer
  * key headers and the OAuth params from config if not set in the request
  * already
  *
  * @param AppModel $model The model the operation is called on. Should have a
  *  request property in the format described in HttpSocket::request
  * @return mixed Depending on what is returned from RestSource::request()
  */
 public function request(&$model)
 {
     // If auth key is set and not false, fill the request with auth params from
     // config if not already present in the request and set the method to OAuth
     // to trigger HttpSocketOauth to sign the request
     if (array_key_exists('auth', $model->request) && $model->request['auth'] !== false) {
         if (!is_array($model->request['auth'])) {
             $model->request['auth'] = array();
         }
         if (!isset($model->request['auth']['method'])) {
             $model->request['auth']['method'] = 'OAuth';
         }
         $oAuthParams = array('oauth_consumer_key', 'oauth_consumer_secret', 'oauth_token', 'oauth_token_secret');
         foreach ($oAuthParams as $oAuthParam) {
             if (!isset($model->request['auth'][$oAuthParam])) {
                 if (!isset($this->config[$oAuthParam])) {
                     trigger_error(sprintf(__('Please specify (either statically or dynamically) the datasource config param "%1s" for connection config %2s.', true), $oAuthParam, get_class($this)), E_USER_ERROR);
                     continue;
                 }
                 $model->request['auth'][$oAuthParam] = $this->config[$oAuthParam];
             }
         }
     }
     // Add in GData Version to request
     if (!isset($model->request['header']['GData-Version'])) {
         $model->request['header']['GData-Version'] = $this->config['GData-Version'];
     }
     // Add in developer key to request N.B. Prefix developer key with 'key='
     if (!isset($model->request['header']['X-GData-Key']) && isset($this->config['X-GData-Key'])) {
         $model->request['header']['X-GData-Key'] = 'key=' . $this->config['X-GData-Key'];
     }
     // Get the response from calling request on the Rest Source (it's parent)
     $response = parent::request($model);
     //    echo '<pre>';
     //    echo htmlspecialchars($this->Http->request['raw']);
     //    echo htmlspecialchars($this->Http->response['raw']['response']);
     //    echo '</pre>';
     //    pr($response);
     //    die();
     return $response;
 }
Exemplo n.º 5
0
 /**
  * Connects if not already connected to Google, then adds the Authorisation
  * header into the request
  *
  * @param array $request An HTTP Request as used by HttpSocket
  * @return array
  * @access protected
  */
 protected function _request($request)
 {
     // Attempts to connect to google if not connected, if fails, returns false
     if (!$this->connected && !$this->connect()) {
         return false;
     }
     // Add in authorisation header
     $request = Set::merge(array('header' => array('Authorization' => 'GoogleLogin auth=' . $this->_auth)), $request);
     // Get the response from calling _request on the Rest Source (it's parent)
     $response = parent::_request($request);
     // If response is false, add the body to the errors property
     if (!$response) {
         $this->_errors[] = $this->Http->response['body'];
         return false;
     }
     // Set the number of rows and results properties from the response
     $this->numRows = $response['feed']['totalResults'];
     $this->_result = $response['feed'];
     // Return the result
     return $this->_result;
 }
 /**
  * Adds in common elements to the request such as the host and extension and
  * OAuth params from config if not set in the request already
  *
  * @param AppModel $model The model the operation is called on. Should have a
  *  request property in the format described in HttpSocket::request
  * @return mixed Depending on what is returned from RestSource::request()
  */
 public function request(&$model)
 {
     // If auth key is set and not false, fill the request with auth params from
     // config if not already present in the request and set the method to OAuth
     // to trigger HttpSocketOauth to sign the request
     if (array_key_exists('auth', $model->request) && $model->request['auth'] !== false) {
         if (!is_array($model->request['auth'])) {
             $model->request['auth'] = array();
         }
         if (!isset($model->request['auth']['method'])) {
             $model->request['auth']['method'] = 'OAuth';
         }
         $oAuthParams = array('oauth_consumer_key', 'oauth_consumer_secret', 'oauth_token', 'oauth_token_secret');
         foreach ($oAuthParams as $oAuthParam) {
             if (!isset($model->request['auth'][$oAuthParam])) {
                 $model->request['auth'][$oAuthParam] = $this->config[$oAuthParam];
             }
         }
     }
     // Set default host, N.B. some API calls use api.twitter.com, in which case
     // they should be set in the individual model call
     if (!isset($model->request['uri']['host'])) {
         $model->request['uri']['host'] = 'api.twitter.com';
     }
     // Append '.json' to path if not already got an extension
     if (strpos($model->request['uri']['path'], '.') === false) {
         $model->request['uri']['path'] .= '.json';
     }
     // Get the response from calling request on the Rest Source (it's parent)
     $response = parent::request($model);
     //    echo '<pre>';
     //    echo htmlspecialchars($this->Http->request['raw']);
     //    echo htmlspecialchars($this->Http->response['raw']['response']);
     //    echo '</pre>';
     //    die();
     return $response;
 }
Exemplo n.º 7
0
 /**
  * Adds in common elements to the request such as the host and extension and
  * OAuth params from config if not set in the request already
  *
  * @param AppModel $model The model the operation is called on. Should have a
  *  request property in the format described in HttpSocket::request
  * @return mixed Depending on what is returned from RestSource::request()
  */
 protected function _request($model)
 {
     // If auth key is set and not false, fill the request with auth params from
     // config if not already present in the request and set the method to OAuth
     // to trigger HttpSocketOauth to sign the request
     if (array_key_exists('auth', $model->request) && $model->request['auth'] !== false) {
         if (!is_array($model->request['auth'])) {
             $model->request['auth'] = array();
         }
         if (!isset($model->request['auth']['method'])) {
             $model->request['auth']['method'] = 'OAuth';
         }
         $oAuthParams = array('oauth_consumer_key', 'oauth_consumer_secret', 'oauth_token', 'oauth_token_secret');
         foreach ($oAuthParams as $oAuthParam) {
             if (!isset($model->request['auth'][$oAuthParam]) && !empty($this->config[$oAuthParam])) {
                 $model->request['auth'][$oAuthParam] = $this->config[$oAuthParam];
             }
         }
         // Set default uri scheme to https
         if (!isset($model->request['uri']['scheme']) && extension_loaded('openssl')) {
             $model->request['uri']['scheme'] = 'https';
         }
     }
     // Set default host, N.B. some API calls use api.twitter.com, in which case
     // they should be set in the individual model call
     if (!isset($model->request['uri']['host'])) {
         $model->request['uri']['host'] = 'api.twitter.com';
     }
     // Append '.json' to path if not already got an extension
     if (!preg_match('/\\.(?:json|xml)$/', $model->request['uri']['path']) && !preg_match('!oauth/!i', $model->request['uri']['path'])) {
         $model->request['uri']['path'] .= '.json';
     }
     // Get the response from calling request on the Rest Source (it's parent)
     $response = parent::request($model);
     return $response;
 }
Exemplo n.º 8
0
 /**
  * Sets request url according to  $model->remoteResource
  *
  * @param AppModel $model
  * @param array $fields Unused
  * @param array $values Unused
  */
 public function create($model, $fields = null, $values = null)
 {
     $model->request = array('uri' => array('host' => 'api.cosm.com', 'path' => 'v2/' . $model->remoteResource), 'body' => array("title" => ['title'], "version" => "1.0.0", "datastreams" => array("id" => "Temperature", "id" => "Humidity")), 'header' => array('X-ApiKey' => Configure::read('cosm.apikey')));
     return parent::request($model);
 }