/** * Constructor. * * @param ClientInterface $client The HTTP client. * @param string $accessToken The Strava API access token. * @param SportMapperInterface $sportMapper The sport mapper. */ public function __construct(ClientInterface $client, $accessToken, SportMapperInterface $sportMapper) { $this->httpClient = $client; $this->accessToken = $accessToken; $this->sportMapper = $sportMapper; $this->httpClient->setDefaultOption('headers/Authorization', 'Bearer ' . $this->accessToken); }
/** * Constructor. * * @param GuzzleClientInterface $client * @param SerializerInterface $serializer * @param string $apiKey */ public function __construct(GuzzleClientInterface $client, SerializerInterface $serializer, $apiKey) { $this->apiKey = $apiKey; $this->client = $client; $this->serializer = $serializer; $this->client->setDefaultOption('headers/User-Agent', 'Helthe-Mandrill/' . self::VERSION); }
/** * @param ClientInterface $client * @param string $apiKey * * @return HTTPClient */ private function prepareClient(ClientInterface $client, $apiKey) { if ($client->getDefaultOption('timeout') === null) { $client->setDefaultOption('timeout', 5.0); } $client->setDefaultOption('headers/X-Api-Key', $apiKey); return $client; }
/** * Constructor * * @param string $token Access Token * @param ClientInterface|null $client Client Instance */ public function __construct($token, ClientInterface $client = null) { if (version_compare(ClientInterface::VERSION, '6') === 1) { $this->client = $client ?: new Client(['headers' => ['access_token' => $token]]); } else { $this->client = $client ?: new Client(); $this->client->setDefaultOption('headers/access_token', $token); } }
/** * @param string $token * @param ClientInterface|null $client */ public function __construct($token, ClientInterface $client = null) { if (version_compare(ClientInterface::VERSION, '6') === 1) { $this->client = $client ?: new Client(['headers' => ['Authorization' => sprintf('Bearer %s', $token)]]); } else { $this->client = $client ?: new Client(); $this->client->setDefaultOption('headers/Authorization', sprintf('Bearer %s', $token)); } }
/** * @param string $accessToken * @param ClientInterface $client (optional) * @param ExceptionInterface $exception (optional) */ public function __construct($accessToken, ClientInterface $client = null, ExceptionInterface $exception = null) { $that = $this; $this->client = $client ?: new \GuzzleHttp\Client(); $this->exception = $exception; $this->client->setDefaultOption('headers/Authorization', sprintf('Bearer %s', $accessToken)); $this->client->getEmitter()->on('complete', function (CompleteEvent $e) use($that) { $that->handleResponse($e); $e->stopPropagation(); }); }
public function attachKey(ClientInterface $http, $key) { $subscriber = new SimpleSubscriber(['key' => $key]); $http->setDefaultOption('auth', 'simple'); $http->getEmitter()->attach($subscriber); return $http; }
/** * Changes the authentication method on all the requests made by this client * @param \Snorlax\Auth\Authorization $auth The authorizaztion method */ public function setAuthMethod(Authorization $auth) { $this->client->setDefaultOption('headers', ['Authorization' => sprintf('%s %s', $auth->getAuthType(), $auth->getCredentials())]); }
public function __construct(ClientInterface $client) { $client->setDefaultOption('headers/Accept', 'application/json'); $this->http = $client; }
/** * Instantiate class with minimal fields to be make valid request * * @param ClientInterface $client */ public function __construct(ClientInterface $client) { $this->client = $client; $this->client->setDefaultOption('headers/User-Agent', 'caseyw/ziprecruiter-php'); }
/** * Prettyprints output and uses ClientInterface debugger * * @author Eelke van den Bos <*****@*****.**> */ public function debug() { $this->setOption('prettyprint', 1); $this->client->setDefaultOption('debug', true); }