Пример #1
0
 protected function runBackoff(RestClient $restClient, Response $errResponse)
 {
     $body = '[
             {"field": "data"},
             {"field": "more"}
     ]';
     $mock = new Mock([$errResponse, new Response(200, [], Stream::factory($body))]);
     $restClient->getClient()->getEmitter()->attach($mock);
     $history = new History();
     $restClient->getClient()->getEmitter()->attach($history);
     $request = new RestRequest('ep', ['a' => 1]);
     $this->assertEquals(json_decode($body), $restClient->download($request));
     $this->assertEquals(5000, $history->getLastRequest()->getConfig()['delay'], '', 1000);
 }
Пример #2
0
 public function authenticateClient(RestClient $client)
 {
     if (empty($this->auth['loginRequest'])) {
         throw new UserException("'loginRequest' is not configured for Login authentication");
     }
     $loginRequest = $this->getAuthRequest($this->auth['loginRequest']);
     $sub = new LoginSubscriber();
     // @return [query, headers]
     $sub->setLoginMethod(function () use($client, $loginRequest, $sub) {
         // Need to bypass the subscriber for the login call
         $client->getClient()->getEmitter()->detach($sub);
         $response = $client->download($loginRequest);
         $client->getClient()->getEmitter()->attach($sub);
         return ['query' => $this->getResults($response, 'query'), 'headers' => $this->getResults($response, 'headers'), 'expires' => $this->getExpiry($response)];
     });
     $client->getClient()->getEmitter()->attach($sub);
 }