/**
  * Class constructor
  *
  * @param array $parameters Context parameters
  */
 public function __construct(array $parameters)
 {
     $this->params = $parameters;
     $this->client = new Client($this->params['url']);
     $defaultHeaders = array('X-Test-Session-Id' => self::$testSessionId);
     if ($this->params['enableCodeCoverage']) {
         $defaultHeaders['X-Enable-Coverage'] = 1;
     }
     $this->client->setDefaultHeaders($defaultHeaders);
 }
Esempio n. 2
0
 /**
  * Create a new HTTP client
  */
 private function createClient()
 {
     $this->client = new Client($this->params['url']);
     $defaultHeaders = array('X-Test-Session-Id' => self::$testSessionId);
     if ($this->params['enableCodeCoverage']) {
         $defaultHeaders['X-Enable-Coverage'] = 1;
     }
     $this->client->setDefaultHeaders($defaultHeaders);
 }
Esempio n. 3
0
 /**
  * @return GuzzleClient
  */
 protected function getGuzzleClient()
 {
     if (is_null($this->guzzleClient)) {
         $this->guzzleClient = new GuzzleClient($this->host);
         $this->guzzleClient->setDefaultHeaders(array('User-Agent' => $this->userAgent));
         if (!is_null($this->logger)) {
             $this->guzzleClient->addSubscriber(new LogPlugin(new MonologLogAdapter($this->logger), MessageFormatter::DEBUG_FORMAT));
         }
     }
     return $this->guzzleClient;
 }
Esempio n. 4
0
 public static function build($type, $domain, $api_key)
 {
     // Get the base url for all the connections.
     $base_url = sprintf('https://%s.chargify.com', $domain);
     // Set the response format through the header.
     $header = array('Content-Type' => 'application/json', 'Accept' => 'application/json');
     // Add the same basic authentication to all requests.
     $basicAuth = new CurlAuthPlugin($api_key, 'x');
     $client = new Client($base_url);
     $client->addSubscriber($basicAuth);
     $client->setDefaultHeaders($header);
     $class_name = 'Chargify\\Controller\\' . ucfirst($type);
     if (class_exists($class_name)) {
         return new $class_name($client);
     } else {
         throw new Exception("Invalid controller type given.");
     }
 }
 /**
  * Get HTTP browser
  *
  * @param \Guzzle\Http\Client
  */
 protected function getBrowser()
 {
     if (!$this->browser instanceof Client) {
         $this->browser = new Client($this->host);
         // try to set User-Agent from original request
         $user_agent = self::DEFAULT_USER_AGENT;
         if ($this->request) {
             $user_agent = $this->request->server->get('HTTP_USER_AGENT', self::DEFAULT_USER_AGENT);
         }
         $this->browser->setDefaultHeaders(['User-Agent' => $user_agent]);
         // configure browser client
         $this->browser->setDefaultOption('timeout', $this->timeout);
         if ($this->proxy_list) {
             $this->browser->setDefaultOption('proxy', $this->proxy_list[array_rand($this->proxy_list)]);
         }
     }
     return $this->browser;
 }
Esempio n. 6
0
 private function setup_http_client()
 {
     // Fetch a copy of the configuration.
     $config = Honeybadger::$config;
     $options = array('curl.options' => array('CURLOPT_CONNECTTIMEOUT' => $config->http_open_timeout, 'CURLOPT_TIMEOUT' => $config->http_read_timeout, 'CURLOPT_AUTOREFERER' => TRUE, 'CURLOPT_FOLLOWLOCATION' => TRUE, 'CURLOPT_MAXREDIRS' => 10));
     if ($config->proxy_host) {
         $options['curl.options']['CURLOPT_HTTPPROXYTUNNEL'] = TRUE;
         $options['curl.options']['CURLOPT_PROXY'] = $config->proxy_host;
         $options['curl.options']['CURLOPT_PROXYPORT'] = $config->proxy_user . ':' . $config->proxy_pass;
     }
     if ($config->is_secure()) {
         $options['ssl.certificate_authority'] = $config->certificate_authority;
     }
     try {
         $client = new Client($config->base_url(), $options);
         $client->setDefaultHeaders(self::$default_headers);
         $client->setUserAgent($this->user_agent());
         return $client;
     } catch (Exception $e) {
         // $this->log(Logger::ERROR, '['.__CLASS__.'::setup_http_client] Failure initializing the request client. Error: [ '.$e->getCode().' ] '.$e->getMessage());
         // Rethrow the exception
         throw $e;
     }
 }
 public function testAllowsDefaultHeaders()
 {
     Version::$emitWarnings = false;
     $default = array('X-Test' => 'Hi!');
     $other = array('X-Other' => 'Foo');
     $client = new Client();
     $client->setDefaultHeaders($default);
     $this->assertEquals($default, $client->getDefaultHeaders()->getAll());
     $client->setDefaultHeaders(new Collection($default));
     $this->assertEquals($default, $client->getDefaultHeaders()->getAll());
     $request = $client->createRequest('GET', null, $other);
     $this->assertEquals('Hi!', $request->getHeader('X-Test'));
     $this->assertEquals('Foo', $request->getHeader('X-Other'));
     $request = $client->createRequest('GET', null, new Collection($other));
     $this->assertEquals('Hi!', $request->getHeader('X-Test'));
     $this->assertEquals('Foo', $request->getHeader('X-Other'));
     $request = $client->createRequest('GET');
     $this->assertEquals('Hi!', $request->getHeader('X-Test'));
     Version::$emitWarnings = true;
 }
Esempio n. 8
0
 /**
  * @covers Guzzle\Http\Client::setDefaultHeaders
  * @expectedException InvalidArgumentException
  */
 public function testValidatesDefaultHeaders()
 {
     $client = new Client();
     $client->setDefaultHeaders('foo');
 }
 /**
  * @param \Guzzle\Http\Client $restClient
  * @return void
  */
 public function injectRestClient(\Guzzle\Http\Client $restClient)
 {
     $this->restClient = $restClient->setDefaultHeaders(array('User-Agent' => 'Searchperience-API-Client version: ' . \Searchperience\Common\Version::Version, 'Accepts' => 'application/searchperienceproduct+xml,application/xml,text/xml'));
 }