public function __construct(JWT $jwt, array $config = [])
 {
     $this->jwt = $jwt;
     $shopId = $jwt->get('id_shop');
     $apiUrl = isset($config['base_uri']) ? $config['base_uri'] : self::API_URL;
     $baseUri = $apiUrl . 'v2/' . ($shopId ? sprintf('shops/%s/', $shopId) : '');
     $defaultConfig = ['base_uri' => $baseUri, 'headers' => ['User-Agent' => sprintf('%s wizishop-php-sdk/%s', \GuzzleHttp\default_user_agent(), self::VERSION), 'Authorization' => 'Bearer ' . $this->jwt->getToken()]];
     parent::__construct($defaultConfig + $config);
 }
Example #2
0
 /**
  * JSONClient constructor.
  *
  * @param string $base_url
  * @param array  $headers
  */
 public function __construct($base_url = '', array $headers = [], $timeout = 10)
 {
     $opts = [];
     $opts['timeout'] = $this->timeout = $timeout;
     $this->global_headers['User-Agent'] = \GuzzleHttp\default_user_agent() . ' json-client/' . self::$version;
     $this->global_headers = array_merge($this->global_headers, $headers);
     if (!empty($base_url)) {
         $opts['base_uri'] = $base_url;
     }
     $this->client = new Client($opts);
 }
 /**
  * @param Psr7Request $request
  * @param array       $options
  *
  * @return Promise\Promise
  */
 public function __invoke(Psr7Request $request, array $options = [])
 {
     $request = $request->withHeader('User-Agent', $request->getHeaderLine('User-Agent') . ' ' . \GuzzleHttp\default_user_agent());
     return $this->client->sendAsync($request, $this->parseOptions($options))->otherwise(static function (\Exception $e) {
         $error = ['exception' => $e, 'connection_error' => $e instanceof ConnectException, 'response' => null];
         if ($e instanceof RequestException && $e->getResponse()) {
             $error['response'] = $e->getResponse();
         }
         return new Promise\RejectedPromise($error);
     });
 }
Example #4
0
 /**
  * @param string $token
  *   The OAuth token to authenticate the request
  * @param array  $config
  *   An array of Guzzle config options so that everything is configurable.
  *
  * @throws \Exception
  */
 public function __construct($token, $config = [])
 {
     $default_config = ['base_uri' => 'https://www.eventbriteapi.com/v3/', 'exceptions' => false, 'timeout' => 30];
     $config = array_merge($default_config, $config);
     // Add this last so it's always there and isn't overwritten.
     $config['headers']['User-Agent'] = 'jamiehollern\\eventbrite v' . self::VERSION . ' ' . \GuzzleHttp\default_user_agent();
     if (!empty($token)) {
         $this->token = $token;
         // Set the authorisation header.
         $config['headers']['Authorization'] = 'Bearer ' . $this->token;
         $this->client = new Client($config);
     } else {
         throw new \Exception('An OAuth token is required to connect to the Eventbrite API.');
     }
 }
Example #5
0
 /**
  * @return string
  */
 protected function getUserAgent()
 {
     static $defaultAgent = '';
     if ($defaultAgent === '') {
         $defaultAgent = 'pwnRaid/' . $this->version->getVersion() . ' ' . \GuzzleHttp\default_user_agent();
     }
     return $defaultAgent;
 }
Example #6
0
 /**
  * Constructs a new client object from some configuration.
  *
  * @param array $config
  *   The config for the client.
  *
  * @return \GuzzleHttp\Client
  *   The HTTP client.
  */
 public function fromOptions(array $config = [])
 {
     $default_config = ['verify' => TRUE, 'timeout' => 30, 'headers' => ['User-Agent' => 'Drupal/' . \Drupal::VERSION . ' (+https://www.drupal.org/) ' . \GuzzleHttp\default_user_agent()], 'handler' => $this->stack];
     $config = NestedArray::mergeDeep($default_config, Settings::get('http_client_config', []), $config);
     return new Client($config);
 }
 /**
  * Construct a FamilySearch Client.
  *
  * @param array $options A keyed array of configuration options for the client. Available options:
  * 
  * * `clientId` - Required for authentication.
  * * `redirectURI` - Required for authentication.
  * * `accessToken` - If the access token is set then the `clientId` and `redirectURI` are not needed.
  * * `environment` - `production`, `beta`, or `sandbox`; defaults to `sandbox`.
  * * `userAgent` - A string which will be prepended to the default user agent string.
  * * `pendingModifications` - An array of pending modifications that should be enabled.
  * * `logger` - A `Psr\Log\LoggerInterface`. A logger can also be registered via the `setLogger()` method but passing it in as an option during instantiation ensures that the logger will see all client events.
  * * `middleware` - An array of [Guzzle Middleware](http://docs.guzzlephp.org/en/latest/handlers-and-middleware.html#middleware).
  * * `httpExceptions` - When `true`, the client will throw a `Gedcomx\Rs\Client\Exception\GedcomxApplicationException` when a 400 or 500 level HTTP response is received. 
  * * `throttling` - When `true`, the client will automatically handled throttled responses.
  */
 public function __construct($options = array())
 {
     if (isset($options['redirectURI'])) {
         $this->redirectURI = $options['redirectURI'];
     }
     if (isset($options['clientId'])) {
         $this->clientId = $options['clientId'];
     }
     // Set the proper homeURI based on the environment.
     // Default to sandbox.
     $environment = '';
     $baseURI = '';
     if (isset($options['environment'])) {
         $environment = $options['environment'];
     }
     switch ($environment) {
         case 'production':
             $baseURI = 'https://familysearch.org';
             break;
         case 'beta':
             $baseURI = 'https://beta.familysearch.org';
             break;
         default:
             $baseURI = 'https://sandbox.familysearch.org';
             break;
     }
     $this->homeURI = $baseURI . '/platform/collection';
     // Middleware
     $this->stack = new HandlerStack();
     $this->stack->setHandler(new CurlHandler());
     $this->stack->push(Middleware::httpErrors());
     $this->stack->push(Middleware::redirect());
     // Pending modifications
     if (isset($options['pendingModifications']) && is_array($options['pendingModifications']) && count($options['pendingModifications']) > 0) {
         $experiments = join(",", $options['pendingModifications']);
         $this->stack->push(Middleware::mapRequest(function (RequestInterface $request) use($experiments) {
             return $request->withHeader('X-FS-Feature-Tag', $experiments);
         }));
     }
     // Throttling
     if (isset($options['throttling']) && $options['throttling'] === true) {
         $this->stack->push(ThrottlingMiddleware::middleware());
     }
     // Set user agent string
     $userAgent = 'gedcomx-php/1.1.1 ' . \GuzzleHttp\default_user_agent();
     if (isset($options['userAgent'])) {
         $userAgent = $options['userAgent'] . ' ' . $userAgent;
     }
     // Custom middleware
     if (isset($options['middleware']) && is_array($options['middleware'])) {
         foreach ($options['middleware'] as $middleware) {
             $this->stack->push($middleware);
         }
     }
     // This goes last so that it sees the final request and response
     if (isset($options['logger'])) {
         $this->setLogger($options['logger']);
     }
     $clientOptions = ['handler' => $this->stack, 'base_uri' => $baseURI, 'headers' => ['User-Agent' => $userAgent]];
     // Throw exceptions
     if (isset($options['httpExceptions']) && $options['httpExceptions'] === true) {
         $clientOptions['http_errors'] = true;
     } else {
         $clientOptions['http_errors'] = false;
     }
     // Create client
     $this->client = new Client($clientOptions);
     $this->stateFactory = new FamilyTreeStateFactory();
     $this->createHomeState();
     $this->createTreeState();
     if (isset($options['accessToken'])) {
         $this->treeState->authenticateWithAccessToken($options['accessToken']);
     }
 }