/**
  * @param type $baseUrl
  * @param type $config
  * @return \Guzzle\Http\Client
  */
 public function getGuzzleClient($baseUrl = '', $config = null)
 {
     if (!is_null($config)) {
         $this->config->merge($config);
     }
     return new Client($baseUrl, $this->config);
 }
Beispiel #2
0
 public function testImplementsArrayAccess()
 {
     $this->coll->merge(array('k1' => 'v1', 'k2' => 'v2'));
     $this->assertTrue($this->coll->offsetExists('k1'));
     $this->assertFalse($this->coll->offsetExists('Krull'));
     $this->coll->offsetSet('k3', 'v3');
     $this->assertEquals('v3', $this->coll->offsetGet('k3'));
     $this->assertEquals('v3', $this->coll->get('k3'));
     $this->coll->offsetUnset('k1');
     $this->assertFalse($this->coll->offsetExists('k1'));
 }
 /**
  * Called when a request is being retried
  *
  * @param Event $event Event emitted
  */
 public function onRequestRetry(Event $event)
 {
     $request = $event['request'];
     $response = $event['response'];
     $handle = $event['handle'];
     $data = new Collection(array('ts' => gmdate('c'), 'method' => $request->getMethod(), 'url' => $request->getUrl(), 'retries' => $event['retries'], 'delay' => $event['delay']));
     if ($response) {
         $data->merge(array('code' => $response->getStatusCode(), 'phrase' => $response->getReasonPhrase(), 'connect_time' => $response->getInfo('connect_time'), 'total_time' => $response->getInfo('total_time')));
     } elseif ($handle) {
         $data->merge(array('connect_time' => $handle->getInfo(CURLINFO_CONNECT_TIME), 'total_time' => $handle->getInfo(CURLINFO_TOTAL_TIME)));
     }
     if ($handle) {
         $data->set('curl_error', $handle->getError());
         $data->set('curl_code', $handle->getErrorNo());
     }
     // Add request headers to the possible template values
     foreach ($request->getHeaders(true) as $header => $value) {
         $data->set("header_{$header}", (string) $value);
     }
     $this->logger->log($data->inject($this->template), LOG_INFO, $data);
 }
Beispiel #4
0
 public function getParamsToSign(RequestInterface $request, $timestamp, $nonce)
 {
     $params = new Collection(array('oauth_consumer_key' => $this->config['consumer_key'], 'oauth_nonce' => $nonce, 'oauth_signature_method' => $this->config['signature_method'], 'oauth_timestamp' => $timestamp, 'oauth_version' => $this->config['version']));
     // Filter out oauth_token during temp token step, as in request_token.
     if ($this->config['token'] !== false) {
         $params->add('oauth_token', $this->config['token']);
     }
     // Add call back uri
     if (isset($this->config['callback_uri']) && !empty($this->config['callback_uri'])) {
         $params->add('oauth_callback', $this->config['callback_uri']);
     }
     // Add query string parameters
     $params->merge($request->getQuery());
     // Add POST fields to signing string
     if (!$this->config->get('disable_post_params') && $request instanceof EntityEnclosingRequestInterface && false !== strpos($request->getHeader('Content-Type'), 'application/x-www-form-urlencoded')) {
         $params->merge($request->getPostFields());
     }
     // Sort params
     $params = $params->getAll();
     ksort($params);
     return $params;
 }
Beispiel #5
0
 /**
  * Parameters sorted and filtered in order to properly sign a request
  *
  * @param RequestInterface $request   Request to generate a signature for
  * @param integer          $timestamp Timestamp to use for nonce
  * @param string           $nonce
  *
  * @return array
  */
 public function getParamsToSign(RequestInterface $request, $timestamp, $nonce)
 {
     $params = new Collection(array('oauth_consumer_key' => $this->config['consumer_key'], 'oauth_nonce' => $nonce, 'oauth_signature_method' => $this->config['signature_method'], 'oauth_timestamp' => $timestamp, 'oauth_token' => $this->config['token'], 'oauth_version' => $this->config['version']));
     if (array_key_exists('callback', $this->config) == true) {
         $params['oauth_callback'] = $this->config['callback'];
     }
     if (array_key_exists('verifier', $this->config) == true) {
         $params['oauth_verifier'] = $this->config['verifier'];
     }
     // Add query string parameters
     $params->merge($request->getQuery());
     // Add POST fields to signing string if required
     if ($this->shouldPostFieldsBeSigned($request)) {
         $params->merge($request->getPostFields());
     }
     // Sort params
     $params = $params->toArray();
     ksort($params);
     return $params;
 }
 /**
  * Calculate string to sign
  *
  * @param RequestInterface $request Request to generate a signature for
  * @param int $timestamp Timestamp to use for nonce
  *
  * @return string
  */
 public function getStringToSign(RequestInterface $request, $timestamp)
 {
     $params = new Collection(array('oauth_consumer_key' => $this->config['consumer_key'], 'oauth_nonce' => $this->generateNonce($request, $timestamp), 'oauth_signature_method' => $this->config['signature_method'], 'oauth_timestamp' => $timestamp, 'oauth_token' => $this->config['token'], 'oauth_version' => $this->config['version']));
     // Add query string parameters
     $params->merge($request->getQuery());
     // Add POST fields to signing string
     if ($request instanceof EntityEnclosingRequestInterface && $request->getHeader('Content-Type') == 'application/x-www-form-urlencoded') {
         $params->merge($request->getPostFields());
     }
     // Sort params
     $params = $params->getAll();
     ksort($params);
     // Build signing string from combined params
     $parameterString = array();
     foreach ($params as $key => $values) {
         $key = rawurlencode($key);
         $values = (array) $values;
         sort($values);
         foreach ($values as $value) {
             if (is_bool($value)) {
                 $value = $value ? 'true' : 'false';
             }
             $parameterString[] = $key . '=' . rawurlencode($value);
         }
     }
     $url = Url::factory($request->getUrl())->setQuery('')->setFragment('');
     return strtoupper($request->getMethod()) . '&' . rawurlencode($url) . '&' . rawurlencode(implode('&', $parameterString));
 }