Ejemplo n.º 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);
 }
Ejemplo n.º 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);
 }
Ejemplo n.º 3
0
 /**
  * @param RestClient $client
  */
 public function authenticateClient(RestClient $client)
 {
     $sub = new UrlSignature();
     // Create array of objects instead of arrays from YML
     $q = (array) Utils::arrayToObject($this->query);
     $sub->setSignatureGenerator(function (array $requestInfo = []) use($q) {
         $params = array_merge($requestInfo, ['attr' => $this->attrs]);
         $query = [];
         try {
             foreach ($q as $key => $value) {
                 $query[$key] = is_scalar($value) ? $value : $this->builder->run($value, $params);
             }
         } catch (UserScriptException $e) {
             throw new UserException("Error in query authentication script: " . $e->getMessage());
         }
         return $query;
     });
     $client->getClient()->getEmitter()->attach($sub);
 }
Ejemplo n.º 4
0
 /**
  * @param RestClient $client
  * @todo Add a possibility to add the option before each request, to allow refresh/signature here?
  */
 public function authenticateClient(RestClient $client)
 {
     $client->getClient()->setDefaultOption('auth', [$this->username, $this->password]);
 }
Ejemplo n.º 5
0
 /**
  * @param RestClient $client
  */
 public function authenticateClient(RestClient $client)
 {
     $sub = new Oauth1(['consumer_key' => $this->consumerKey, 'consumer_secret' => $this->consumerSecret, 'token' => $this->token, 'token_secret' => $this->tokenSecret]);
     $client->getClient()->getEmitter()->attach($sub);
     $client->getClient()->setDefaultOption('auth', 'oauth');
 }
Ejemplo n.º 6
0
 /**
  * @param RestClient $client
  */
 public function authenticateClient(RestClient $client)
 {
     $subscribers = [['subscriber' => new UrlSignature(), 'definitions' => $this->query], ['subscriber' => new HeaderSignature(), 'definitions' => $this->headers]];
     $authorization = ['clientId' => $this->clientId, 'nonce' => substr(sha1(uniqid(microtime(), true)), 0, 16), 'timestamp' => time()];
     if (!is_scalar($this->data)) {
         $authorization = array_merge($authorization, Utils::flattenArray(Utils::objectToArray($this->data), 'data.'));
     } else {
         $authorization['data'] = $this->data;
     }
     foreach ($subscribers as $subscriber) {
         if (empty($subscriber['definitions'])) {
             continue;
         }
         $this->addGenerator($subscriber['subscriber'], $subscriber['definitions'], $authorization);
         $client->getClient()->getEmitter()->attach($subscriber['subscriber']);
     }
 }