/** * @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; }
public function isLoggedIn(ClientInterface $guzzle) { if (($cookieJar = $guzzle->getDefaultOption('cookies')) instanceof CookieJar) { /** @var \GuzzleHttp\Cookie\SetCookie $cookie */ foreach ($cookieJar as $cookie) { // check required cookies if ($cookie->getDomain() == $this->siteConfig->getHost()) { return true; } } } return false; }
function it_posts_a_login_request(ClientInterface $guzzle) { $guzzle->post('http://example.com/login', ['body' => ['username' => 'johndoe', 'password' => 'unkn0wn', 'action' => 'login', 'foo' => 'bar'], 'verify' => false, 'allow_redirects' => true])->shouldBeCalled(); $guzzle->getDefaultOption('cookies')->willReturn(new CookieJar(false, new SetCookie())); $this->login($guzzle); }
private function createAuthHttp(ClientInterface $http) { return new Client(['base_url' => $http->getBaseUrl(), 'defaults' => ['exceptions' => true, 'verify' => $http->getDefaultOption('verify'), 'proxy' => $http->getDefaultOption('proxy')]]); }