/** * @param string $projectname * @param string $username * @param string $password * @param ClientInterface $httpClient */ public function __construct($projectname, $username, $password, ClientInterface $httpClient = null) { $this->projectname = $projectname; $this->username = $username; $this->password = $password; $this->httpClient = $httpClient ?: new GuzzleClient(); $this->httpClient->addSubscriber($this); }
/** * @param ClientInterface $client Client object */ public function __construct(ClientInterface $client = null) { $this->requests = array(); if (!$client) { $this->client = new Client(); $cache = new CachePlugin(array('storage' => new DefaultCacheStorage(new DoctrineCacheAdapter(new FilesystemCache(sys_get_temp_dir()))))); $this->client->addSubscriber($cache); } else { $this->client = $client; } }
protected function setUp() { Phake::initAnnotations($this); Phake::when($this->cryptService)->encryptRSA(Phake::anyParameters())->thenReturn($this->rsaEncrypted); Phake::when($this->cryptService)->sign(Phake::anyParameters())->thenReturn($this->signed); Phake::when($this->cache)->get(GuzzleApiService::CACHE_KEY_PUBLIC_KEY)->thenReturn($this->publicKey); $this->guzzleClient = new Client(); $this->guzzleMockPlugin = new MockPlugin(); $this->guzzleClient->addSubscriber($this->guzzleMockPlugin); $this->apiService = new GuzzleApiService($this->appKey, $this->secretKey, $this->guzzleClient, $this->cryptService, $this->cache, 999999); $this->loggingApiService = new GuzzleApiService($this->appKey, $this->secretKey, $this->guzzleClient, $this->cryptService, $this->cache, 999999, $this->logger); }
public function __construct(ClientInterface $client = null) { $this->client = $client; if (!$this->client) { $this->client = new Client(); $this->client->getEventDispatcher()->addListener('request.error', function (Event $event) { // override guzzle default behavior of throwing exceptions // when 4xx & 5xx responses are encountered $event->stopPropagation(); }, -254); $this->client->addSubscriber(BackoffPlugin::getExponentialBackoff(5, array(500, 502, 503, 408))); } }
/** * @param array $configs * @param ClientInterface $client * @param LoggerInterface $logger */ protected function __construct(array $configs, ClientInterface $client = null, LoggerInterface $logger = null) { $configs = array_merge($this->getDefaultConfig(), $configs); $this->setCredentials($configs); $this->setDefaults(); if ($configs['auth_in_header']) { $this->headers['Authorization'] = $this->getAuthHeader(); } $this->logger = $logger ?: new NullLogger(); $this->client = $client ?: new Client(); $this->client->setBaseUrl($configs['base_url']); $this->client->addSubscriber(new LogPlugin(new PsrLogAdapter($this->logger))); $this->tokenRequestPath = $configs['token_request_path']; }
/** * Constructor. * * @param ClientInterface $httpClient * @param array $options * @param LoggerInterface $logger */ public function __construct(ClientInterface $httpClient, array $options, LoggerInterface $logger = null) { $this->httpClient = $httpClient; $scheme = isset($options['scheme']) ? $options['scheme'] : static::DEFAULT_SCHEME; $host = isset($options['host']) ? $options['host'] : static::DEFAULT_HOST; $port = isset($options['port']) ? $options['port'] : static::DEFAULT_PORT; $pathPrefix = isset($options['path_prefix']) ? $options['path_prefix'] : static::DEFAULT_PATH_PREFIX; $accessKey = isset($options['access_key']) ? $options['access_key'] : null; $secretKey = isset($options['secret_key']) ? $options['secret_key'] : null; $this->scheme = $scheme; $this->host = $host; $this->port = $port; $this->pathPrefix = $pathPrefix; $this->accessKey = $accessKey; $this->secretKey = $secretKey; $this->companyName = isset($options['company']) ? $options['company'] : null; $this->collectionName = isset($options['collection']) ? $options['collection'] : null; $this->options = $options; $this->logger = $logger; $exceptionFactory = new NamespaceExceptionFactory(new EngineExceptionParser(), 'Sajari\\Engine\\Exception', 'Sajari\\Engine\\Exception\\EngineException'); $this->httpClient->addSubscriber(new StatusCodeListener()); $this->httpClient->addSubscriber(new ExceptionListener($exceptionFactory)); $connectTimeout = 10; $timeout = 10; if (isset($this->options['curl.options']['CURLOPT_CONNECTTIMEOUT'])) { $connectTimeout = (int) $this->options['curl.options']['CURLOPT_CONNECTTIMEOUT']; } if (isset($this->options['curl.options']['CURLOPT_TIMEOUT'])) { $timeout = (int) $this->options['curl.options']['CURLOPT_TIMEOUT']; } $this->httpClient->setBaseUrl(sprintf('%s://%s', $this->scheme, $this->host)); $this->httpClient->setConfig(array(HttpClient::SSL_CERT_AUTHORITY => false, HttpClient::CURL_OPTIONS => array(CURLOPT_CONNECTTIMEOUT => $connectTimeout, CURLOPT_TIMEOUT => $timeout))); }
/** * @param ClientInterface $client * @param LoggerInterface $logger * @param null|string $formatter * @return LogPlugin */ public static function addPsrLoggerToClient(ClientInterface $client, LoggerInterface $logger, $formatter = self::SIMPLE_FORMAT) { $formatter = is_null($formatter) ? self::SIMPLE_FORMAT : $formatter; $adapter = new PsrLogAdapter($logger); $plugin = new LogPlugin($adapter, $formatter); $client->addSubscriber($plugin); return $plugin; }
public function testGetByAccessToken_Invalid() { $user = $this->createUser(); $this->user_service->save($user); $mock_plugin = new \Guzzle\Plugin\Mock\MockPlugin(); $mock_plugin->addResponse(new \Guzzle\Http\Message\Response(200, [], json_encode(['id' => 2]))); $this->http->addSubscriber($mock_plugin); $this->assertNull($this->user_service->getByAccessToken('invalid_token')); }
/** * setting up the oauth2 plugin for authorizing the requests */ private function setupOAuth2Plugin() { $oauth2AuthorizationClient = $this->resolveClient(null); $oauth2AuthorizationClient->setBaseUrl(Properties::authorizationUrl()); $clientCredentials = new ClientCredentials($oauth2AuthorizationClient, $this->config->toArray()); $oauth2Plugin = new OAuth2Plugin($clientCredentials); $oauth2Plugin->setCache($this->config->getAccessTokenCacheFile()); $this->client->addSubscriber($oauth2Plugin); }
/** * Add a subscriber * * @param EventSubscriberInterface $subscriber */ public function addSubscriber(EventSubscriberInterface $subscriber) { $this->client->addSubscriber($subscriber); }