/** * Constructor. * * @param \Guzzle\Http\ClientInterface $client A ClientInterface instance. * @param string $owner The owner of the Github repository. * @param string $repository The Github repository. */ public function __construct(ClientInterface $client, $owner, $repository) { $this->client = $client; $this->owner = $owner; $this->repository = $repository; $this->client->setBaseUrl('https://api.github.com'); }
public function __construct(\Guzzle\Http\ClientInterface $client = null) { if (empty($client)) { $client = new \Guzzle\Http\Client(); } $this->client = $client; $this->client->setBaseUrl('https://drupal.org/'); }
/** * AmplitudeClient constructor. * * @param $apiKey * @param ClientInterface $client */ public function __construct($apiKey, ClientInterface $client) { if (empty($apiKey)) { throw new \InvalidArgumentException('Empty api key', 500); } $this->apiKey = $apiKey; $this->client = $client; $this->client->setBaseUrl(self::AMPLITUDE_URL); }
/** * @param string $clientId * @param string $clientSecret * @param string $redirectUri * @param array $scopes * @param ProviderInterface $provider * @param ClientInterface $httpClient */ public function __construct($clientId, $clientSecret, $redirectUri, $scopes = [], ProviderInterface $provider = null, ClientInterface $httpClient = null) { if (is_null($provider)) { $this->provider = new Base(['clientId' => $clientId, 'clientSecret' => $clientSecret, 'redirectUri' => $redirectUri, 'scopes' => $scopes]); } else { $this->provider = $provider; } if (is_null($httpClient)) { $this->httpClient = new HttpClient(); } else { $this->httpClient = $httpClient; } $this->httpClient->setBaseUrl(Base::BASE_URL); }
/** * @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']; }
/** * @return Response * @throws ConnectionErrorException * @throws EmptyHostPoolException * @throws ServerErrorException */ public function send() { $exception = null; while ($this->hostPool->hasNext()) { try { $this->guzzleClient->setBaseUrl($this->hostPool->getNext()); /** @var GuzzleRequest $guzzleRequest */ $guzzleRequest = $this->guzzleClient->{$this->method}(array($this->url, $this->binds)); $guzzleRequest->addHeaders($this->headers); if ($this->body && $guzzleRequest instanceof EntityEnclosingRequest) { /** @var EntityEnclosingRequest $guzzleRequest */ $guzzleRequest->setBody($this->body); } $this->updateQueryParams($guzzleRequest); return new Response($guzzleRequest->send()); } catch (ClientErrorResponseException $e) { return new Response($e->getResponse()); } catch (ServerErrorResponseException $e) { $exception = new ServerErrorException(new Response($e->getResponse()), $e->getMessage(), $e->getCode(), $e); } catch (CurlException $e) { $exception = new ConnectionErrorException($e->getMessage(), $e->getCode(), $e); } } if ($exception == null) { throw new EmptyHostPoolException(sprintf("Empty host pool: %s", $this->hostPool->getName())); } throw $exception; }
/** * 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))); }
/** * Set application hostname, optionally including a base URL, for purge and * refresh requests * * @param string $url Your application’s base URL or hostname */ public function setBaseUrl($url) { if ($url) { $url = $this->filterUrl($url); } $this->client->setBaseUrl($url); }
/** * Perform a cURL request based on a supplied path * * @param string $path * * @return array */ private function call($path) { $this->client->setBaseUrl(self::URL); $request = $this->client->get($path); $request->setHeader('Accept', 'application/json'); return $request->send()->json(); }
/** * Perform an HTTP request on MusicBrainz * * @param string $path * @param array $params * @param string $options * @param boolean $isAuthRequred * @return array */ public function call($path, array $params = array(), array $options = array(), $isAuthRequred = false) { if ($options['user-agent'] == '') { throw new Exception('You must set a valid User Agent before accessing the MusicBrainz API'); } $this->client->setBaseUrl(MbClient::URL); $this->client->setConfig(array('data' => $params)); $request = $this->client->get($path . '{?data*}'); $request->setHeader('Accept', 'application/json'); $request->setHeader('User-Agent', $options['user-agent']); if ($isAuthRequred) { if ($options['user'] != null && $options['password'] != null) { $request->setAuth($options['user'], $options['password'], CURLAUTH_DIGEST); } else { throw new Exception('Authentication is required'); } } $request->getQuery()->useUrlEncoding(false); return $request->send()->json(); }
/** * HttpClient constructor. * @param $clientId * @param $apiKey * @param $apiSecret * @param $endpoint * @param ClientInterface $client */ public function __construct($clientId, $apiKey, $apiSecret, $endpoint, ClientInterface $client) { $this->authData = ['clientId' => $clientId, 'apiKey' => $apiKey, 'sha' => sha1($apiKey . $clientId . $apiSecret)]; $this->client = $client; $this->client->setBaseUrl($endpoint); }
/** * Constructor. * * @param \Guzzle\Http\ClientInterface $client A ClientInterface instance. */ public function __construct(ClientInterface $client) { $this->client = $client; $this->client->setBaseUrl('https://api.github.com'); }
/** * {@inheritDoc} */ public function setBaseUrl($url) { $this->client->setBaseUrl($url); return $this; }
/** * Constructor. * * @param \Guzzle\Http\ClientInterface $client A ClientInterface instance. * @param string $folder The ID of the folder on Google Drive. */ public function __construct(ClientInterface $client, $folder = 'root') { $this->client = $client; $this->folder = $folder; $this->client->setBaseUrl('https://www.googleapis.com/upload/drive/v2'); }
private function setGuzzleClient(GuzzleClientInterface $guzzleClient) { $guzzleClient->setBaseUrl('https://leanpub.com'); $this->guzzleClient = $guzzleClient; }