示例#1
0
 /**
  * @param GuzzleClientInterface $client
  * @param RequestBuilder        $requestBuilder
  *
  * @throws \InvalidArgumentException
  */
 public function __construct(GuzzleClientInterface $client, RequestBuilder $requestBuilder)
 {
     if ($client->getConfig('base_url') !== $requestBuilder->getBaseUrl()) {
         throw new \InvalidArgumentException(sprintf('Expected base url of client and request build to match. Got respectively "%s" and "%s" instead.', $client->getConfig('base_url'), $requestBuilder->getBaseUrl()));
     }
     $this->client = $client;
     $this->requestBuilder = $requestBuilder;
 }
示例#2
0
 public function __invoke($mmId)
 {
     $config = $this->httpClient->getConfig();
     $baseUri = $config['base_uri'];
     $auth = $config['auth'];
     $url = $baseUri->withQueryValue($baseUri, 'mm_id', $mmId);
     $response = $this->httpClient->request('GET', $url, ['auth' => $auth]);
     $responseData = json_decode($response->getBody()->getContents(), true);
     if (!isset($responseData['data']) || empty($responseData['data'])) {
         return;
     }
     return $responseData['data'][0];
 }
示例#3
0
 /**
  * @param  string           $method
  * @param  array            $options
  *
  * @return RequestInterface
  */
 protected function createRequest($method, $options)
 {
     $uri = $this->httpClient->getConfig('base_uri');
     $defaults = $this->httpClient->getConfig('defaults');
     $headers = isset($defaults['headers']) ? $defaults['headers'] : [];
     return $this->messageFactory->createRequest($method, $uri, $headers, $options);
 }
示例#4
0
 /**
  * @param ClientInterface $client
  */
 public function __construct(ClientInterface $client, TimelineToken $token)
 {
     $this->baseUri = $client->getConfig('base_uri');
     if ($this->baseUri === null) {
         $this->baseUri = 'https://timeline-api.getpebble.com';
     }
     $this->token = $token;
     $this->client = $client;
 }
 /**
  * @inheritDoc
  */
 public function authenticate(ClientInterface $httpClient)
 {
     if (!$httpClient->getConfig('cookies') instanceof CookieJarInterface) {
         throw new UnsupportedClientException('This HTTP client does not have cookies configured');
     }
     $homePageDom = $this->requestHomePageDom($httpClient);
     if (!$this->isLoggedIn($homePageDom)) {
         if ($homePageDom->query('#_login-form')->count() < 1) {
             throw new LoginFormNotFoundException();
         }
         $csrfToken = $homePageDom->query('#_login-form [name=fs_csrf]')->val();
         $newHomePageDom = $this->doLogin($httpClient, $csrfToken);
         if (!$this->isLoggedIn($newHomePageDom)) {
             throw new FailedLoggingInException('User was not logged in');
         }
     }
 }
 /**
  * {@inheritdoc}
  */
 public function get($url, array $args = [])
 {
     $options = [];
     // Add additional arguments to the defaults:
     //   Guzzle 6 does no longer merge the default query params with the
     //   additional params given here!
     if (!empty($args)) {
         if ($this->guzzleVersion > 5) {
             $options['query'] = array_merge($this->client->getConfig('query'), $args);
         } else {
             $options['query'] = $args;
         }
     }
     try {
         $this->response = $this->client->get($url, $options);
     } catch (RequestException $e) {
         $this->response = $e->getResponse();
         return $this->handleError();
     }
     // $response->json() is not compatible with Guzzle 6.
     return json_decode($this->response->getBody(), true);
 }
 /**
  * Get the URL.
  *
  * @return \GuzzleHttp\Psr7\Uri
  */
 public function getUrl()
 {
     return $this->client->getConfig('base_uri');
 }
 private function createAuthHttp(ClientInterface $http)
 {
     return new Client(['base_uri' => $http->getConfig('base_uri'), 'exceptions' => true, 'verify' => $http->getConfig('verify'), 'proxy' => $http->getConfig('proxy')]);
 }
示例#9
0
 /**
  * @param string $url
  * @param array  $options
  *
  * @return string
  */
 protected function getRequestKey($url, array $options)
 {
     $options = array_replace_recursive(['headers' => $this->client->getConfig('headers'), 'query' => $this->client->getConfig('query')], $options);
     return hash_hmac('md5', $url, serialize($options));
 }
示例#10
0
 /**
  * @return \GuzzleHttp\Psr7\Uri
  */
 protected function getHttpBaseUrl()
 {
     return $this->client->getConfig('base_uri');
 }
 private function createRequest($uri)
 {
     $baseUri = \GuzzleHttp\Psr7\uri_for($this->client->getConfig('base_uri'));
     $uri = Uri::resolve($baseUri, $uri);
     return new Request('GET', $uri);
 }
示例#12
0
 /**
  * @param string $path
  *
  * @return string
  */
 protected function getFinalPath($path)
 {
     return $this->client->getConfig('base_uri')->getPath() . '/' . $path;
 }
 /**
  * @return string
  */
 private function getTokenEndpoint()
 {
     return vsprintf('%s%s', [$this->httpClient->getConfig('base_uri'), $this->serverConfig->getParams()['token_endpoint']]);
 }
示例#14
0
 /**
  * Creates the uri with the unit query parameter
  *
  * @param mixed $unit
  * @return UriInterface
  */
 private function createBaseUri($unit)
 {
     $config = $this->httpClient->getConfig();
     $baseUri = $config['base_uri'];
     return $baseUri->withQueryValue($baseUri, 'unit', $unit);
 }
示例#15
0
 /**
  * @return UriInterface
  */
 public function getBaseUri()
 {
     return new Uri($this->client->getConfig('token_pool')->getPublicUrl());
 }
 /**
  * @param string|Uri $uri
  * @return Uri
  */
 private function createUri($uri)
 {
     $baseUri = \GuzzleHttp\Psr7\uri_for($this->client->getConfig('base_uri'));
     return Uri::resolve($baseUri, $uri);
 }