Here's an example of creating a client using a base_uri and an array of
default request options to apply to each request:
$client = new Client([
'base_uri' => 'http://www.foo.com/1.0/',
'timeout' => 0,
'allow_redirects' => false,
'proxy' => '192.168.16.1:10'
]);
Client configuration settings include the following options:
- handler: (callable) Function that transfers HTTP requests over the
wire. The function is called with a Psr7\Http\Message\RequestInterface
and array of transfer options, and must return a
GuzzleHttp\Promise\PromiseInterface that is fulfilled with a
Psr7\Http\Message\ResponseInterface on success. "handler" is a
constructor only option that cannot be overridden in per/request
options. If no handler is provided, a default handler will be created
that enables all of the request options below by attaching all of the
default middleware to the handler.
- base_uri: (string|UriInterface) Base URI of the client that is merged
into relative URIs. Can be a string or instance of UriInterface.
- **: any request option
public __construct ( array $config = [] ) | ||
$config | array | Client configuration settings. |
/** * Constructor. * * @param string $xApiKey * An api.data.gov api key that is granted to your user. * * @param string $xAdminAuthToken * Admin Authorization Token provided by api.data.gov admin accounts. */ public function __construct($xApiKey, $xAdminAuthToken) { parent::__construct(['base_url' => $this->apiUrl]); $this->xApiKey = $xApiKey; $this->xAdminAuthToken = $xAdminAuthToken; $this->setDefaultOption('headers', array('X-Api-Key' => $this->xApiKey, 'X-Admin-Auth-Token' => $this->xAdminAuthToken, 'Content-Type' => 'application/json', 'Accept' => 'text/*')); }
/** * Client constructor. */ public function __construct(array $config = []) { $vindi = new Vindi(); $host = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : ''; $config = array_merge(['base_uri' => Vindi::$apiBase, 'auth' => [$vindi->getApiKey(), '', 'BASIC'], 'headers' => ['Content-Type' => 'application/json', 'User-Agent' => trim('Vindi-PHP/' . Vindi::$sdkVersion . "; {$host}")], 'verify' => $vindi->getCertPath(), 'timeout' => 60, 'curl.options' => ['CURLOPT_SSLVERSION' => 'CURL_SSLVERSION_TLSv1_2']], $config); parent::__construct($config); }
public function __construct($base_uri, $username, $access_token) { parent::__construct(['base_uri' => $base_uri]); $this->access_token = $access_token; $this->username = $username; $this->auth = new Authentication($this); }
/** * Constructor */ public function __construct() { parent::__construct(); $this->token = true; $this->ph_session = (new \Phalcon\DI())->getDefault()->getSession(); $this->base_url = getenv('API_URL'); }
/** * Constructor * * @param string $version version number (v0) */ public function __construct($version = null) { if ($version) { $this->version = $version; } parent::__construct(['base_url' => implode("/", [self::API_BASE_URL, $this->version, ''])]); }
/** * @param Endpunkt $endpoint API-Endpunkt * @param string $userAgent User-Agent * @param string $token API-Token * @param string $user Benutzername * @param string $password Passwort * @param bool $compress Komprimierung aktivieren * @param bool $verify SSL-Zertifikate verifizieren */ public function __construct(Endpunkt $endpoint, $userAgent, $token, $user, $password, $compress = false, $verify = true) { parent::__construct(['base_url' => $endpoint->getBaseUrl()]); if (!$userAgent) { throw new \InvalidArgumentException('User-Agent erforderlich.'); } if (!$token) { throw new \InvalidArgumentException('Token erforderlich.'); } if (!$user) { throw new \InvalidArgumentException('Benutzername erforderlich.'); } if (!$password) { throw new \InvalidArgumentException('Passwort erforderlich.'); } $headers = ['User-Agent' => sprintf('%1$s; Token=%2$s', $userAgent, $token)]; if ($compress) { $headers['Accept-Encoding'] = 'gzip'; } $this->setDefaultOption('headers', $headers); $this->setDefaultOption('auth', [$user, $password]); $this->setDefaultOption('verify', $verify); if ($compress) { $this->setDefaultOption('decode_content', true); } else { $this->setDefaultOption('decode_content', false); } $this->endpoint = $endpoint; }
/** * Sets up our client vars and initialises the base_uri on the * GuzzleHttp Client instance. * * @param string $key Google Places API key * @param array $location Latitude/Longitude pair * @param array $options Options for refining the search. */ public function __construct($key, array $location, $options = []) { $this->key = $key; $this->location = $location; $this->options = $options; parent::__construct(['base_uri' => $this->endpoint]); }
/** * @param string $apiKey The API key for your ThisData account * @param int $version The version of the ThisData API to use * @param array $options Extra options for the GuzzleClient */ public function __construct($apiKey, $version = 1, array $options = []) { $this->apiKey = $apiKey; $this->version = $version; $options = array_merge($this->getDefaultConfiguration(), $options); parent::__construct($options); }
/** * @param array $accessToken * @param string $version * @param array $config */ public function __construct($accessToken, $version = 'v2.6', array $config = []) { $this->accessToken = $accessToken; $this->version = $version; $config = array_merge(['base_uri' => $this->baseUri, 'query' => ['access_token' => $this->accessToken]], $config); parent::__construct($config); }
/** * @param Client $client */ public function __construct(Client $client) { $this->client = $client; $this->testing = $this->client->isTesting(); $this->options = array('query' => array('lang' => $this->client->getLocale())); parent::__construct(array('base_url' => array($this->client->getUrl() . '/{version}/', array('version' => $this->client->getVersion())))); }
/** * @param AccessTokenInterface $token * @param array $options */ public function __construct(AccessTokenInterface $token, array $options = []) { $options = array_merge($options, ['emitter' => EventsManager::getEmitter()]); parent::__construct($options); if ($token instanceof OAuth2AccessTokenInterface) { $this->getEmitter()->on('before', function (BeforeEvent $event) use($token) { /** @var \Eva\EvaOAuth\OAuth2\Token\AccessToken $token */ $event->getRequest()->setHeader('Authorization', $token->getTokenType() . ' ' . $token->getTokenValue()); }); } else { $signatureMethod = isset($options['signature_method']) ? $options['signature_method'] : SignatureInterface::METHOD_HMAC_SHA1; $signatureClasses = [SignatureInterface::METHOD_PLAINTEXT => 'Eva\\EvaOAuth\\OAuth1\\Signature\\PlainText', SignatureInterface::METHOD_HMAC_SHA1 => 'Eva\\EvaOAuth\\OAuth1\\Signature\\Hmac', SignatureInterface::METHOD_RSA_SHA1 => 'Eva\\EvaOAuth\\OAuth1\\Signature\\Rsa']; if (false === isset($signatureClasses[$signatureMethod])) { throw new InvalidArgumentException(sprintf('Signature method %s not able to process', $signatureMethod)); } $signatureClass = $signatureClasses[$signatureMethod]; $this->getEmitter()->on('before', function (BeforeEvent $event) use($token, $signatureClass) { /** @var Request $request */ $request = $event->getRequest(); /** @var \Eva\EvaOAuth\OAuth1\Token\AccessToken $token */ $httpMethod = strtoupper($request->getMethod()); $url = Url::fromString($request->getUrl()); $parameters = ['oauth_consumer_key' => $token->getConsumerKey(), 'oauth_signature_method' => SignatureInterface::METHOD_HMAC_SHA1, 'oauth_timestamp' => (string) time(), 'oauth_nonce' => strtolower(Text::generateRandomString(32)), 'oauth_token' => $token->getTokenValue(), 'oauth_version' => '1.0']; $signature = (string) new $signatureClass($token->getConsumerSecret(), Text::buildBaseString($httpMethod, $url, $parameters), $token->getTokenSecret()); $parameters['oauth_signature'] = $signature; $event->getRequest()->setHeader('Authorization', Text::buildHeaderString($parameters)); }); } }
/** * @param KeyValueStore $kvs * @param string $clientId * @param string $clientSecret * @param string $redirectUri */ public function __construct(KeyValueStore $kvs, $clientId, $clientSecret, $redirectUri) { $this->kvs = $kvs; $this->clientId = $clientId; $this->clientSecret = $clientSecret; $this->redirectUri = $redirectUri; parent::__construct(); }
/** * GuzzleWrapper constructor. * @param $client */ public function __construct(array $config) { $config['on_stats'] = function (TransferStats $stats) { // contient les stats $stats->getHandlerStats(); }; parent::__construct($config); }
public function __construct($parameters) { parent::__construct(); $this->url = $parameters['url']; $this->version = $parameters['version']; $this->id = $parameters['id']; $this->sslVerficationEnabled = $parameters['sslVerifcationEnabled']; }
/** * Client constructor. * @param array $config */ public function __construct($config = []) { $config = new Config($config); if (!$config->hasRequired()) { throw new NotExistRequiredException(); } parent::__construct($config->toGuzzleConfig()); }
/** * Constructor. * * @param string $homepage satis repository url * @param array|null $credentials Credentials (user, pass) * @param SatisHttpServerInfo|null $httpServer Satis Http Server Informations */ public function __construct($homepage, array $credentials = null, SatisHttpServerInfo $httpServer = null) { $this->setCredentials($credentials); $this->setUrlHelper($homepage); parent::__construct(['base_url' => $this->baseUrl]); $this->httpServer = is_null($httpServer) ? new SatisHttpServerInfo() : $httpServer; $this->checkServer(); }
public function __construct($params, $subscribers) { $this->params = $params; foreach ($subscribers as $name => $v) { $this->addNewSubscriber($name, $v); } parent::__construct(['base_url' => $this->params['endpoint'], 'headers' => ['User-Agent' => $this->params['user_agent']]]); }
/** * Constructor * @param array $config Client configuration settings. */ public function __construct(array $config = []) { if (isset($config['base_uri']) && !preg_match("/\\/api2\$/", $config['base_uri'])) { $config['base_uri'] .= '/api2'; } $config = array_merge(['http_errors' => true, 'request.options' => ['verify' => true, 'headers' => ['Content-Type' => 'application/json', 'Authorization' => 'Token none']]], $config); parent::__construct($config); }
public function __construct(ScopeConfigInterface $config) { $openpayConfigValues = $config->getValue('payment/openpay'); $useSandbox = $openpayConfigValues['sandbox']; $baseUrl = $useSandbox == true ? $openpayConfigValues['sandbox_url'] : $openpayConfigValues['production_url']; $params = ['base_uri' => $baseUrl]; parent::__construct($params); }
public function __construct($baseUrl = '', $config = null) { if (PHP_VERSION < self::MINIMUM_PHP_VERSION) { throw new NitrapiException(sprintf('You must have PHP version >= %s installed.', self::MINIMUM_PHP_VERSION)); } $config['base_url'] = $baseUrl; parent::__construct($config); }
public function __construct($consumerKey, $consumerSecret, $baseUrl = null) { $config = array('base_url' => $baseUrl ? $baseUrl : self::BASE_URL, 'defaults' => array('auth' => 'oauth', 'headers' => array('Return-Type' => 'text/json'))); parent::__construct($config); $this->oauthConfig = array('consumer_key' => $consumerKey, 'consumer_secret' => $consumerSecret); $this->unauthenticatedOauthListener = new Oauth1($this->oauthConfig); $this->getEmitter()->attach($this->unauthenticatedOauthListener); }
public function __construct(array $config) { if (!array_key_exists('api_key', $config)) { throw new \InvalidArgumentException('API Key must be provided.'); } $this->apiKey = $config['api_key']; unset($config['api_key']); parent::__construct($config); }
/** * @inheritdoc */ public function __construct(array $config = []) { if (!isset($config['handlers'])) { $handler = new MockHandler(['status' => isset($config['mockStatus']) ? $config['mockStatus'] : 200, 'body' => isset($config['mockValues']) ? json_encode($config['mockValues']) : '']); $config['handlers'] = [$handler]; unset($config['mockStatus'], $config['mockValues']); } parent::__construct($config); }
/** * The c * * @param array $config */ public function __construct(array $config = array()) { $this->_initConfig(); $this->_stack = HandlerStack::create(); $this->_middlewareConfig = ['consumer_key' => Yii::$app->params['scoopit']['consumerKey'], 'consumer_secret' => Yii::$app->params['scoopit']['consumerSecret'], 'token' => isset(Yii::$app->params['scoopit']['token']) ? Yii::$app->params['scoopit']['token'] : NULL, 'token_secret' => isset(Yii::$app->params['scoopit']['tokenSecret']) ? Yii::$app->params['scoopit']['tokenSecret'] : NULL]; $middleware = new Oauth1($this->_middlewareConfig); $this->_stack->push($middleware); parent::__construct(['base_uri' => Yii::$app->params['scoopit']['remoteUri'], 'handler' => &$this->_stack, 'auth' => 'oauth']); }
/** * {@inheritdoc} */ public function __construct(array $config = []) { $default_config = array('verify' => TRUE, 'timeout' => 30, 'headers' => array('User-Agent' => 'Drupal/' . \Drupal::VERSION . ' (+https://www.drupal.org/) ' . static::getDefaultUserAgent())); // The entire config array is merged/configurable to allow Guzzle client // options outside of 'defaults' to be changed, such as 'adapter', or // 'message_factory'. $config = NestedArray::mergeDeep(array('defaults' => $default_config), $config, Settings::get('http_client_config', array())); parent::__construct($config); }
public function __construct($username, $password, $integrator_key, $account_id = null, $env = 'demo', $version = 'v2') { $this->authenticate($username, $password, $integrator_key, $env, $version); $base_uri = $this->getBaseUri($account_id); if (!$base_uri) { throw new \GuzzleHttp\Exception\TransferException('Could not determine a base URI.'); } parent::__construct(['base_uri' => $base_uri, 'headers' => ['X-DocuSign-Authentication' => $this->auth_header]]); }
public function __construct() { $history = Middleware::history($this->container); $this->mock = new MockHandler(); $stack = HandlerStack::create($this->mock); // Add the history middleware to the handler stack. $stack->push($history); parent::__construct(['handler' => $stack]); }
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); }
public function __construct($username) { if (empty($username)) { throw new NullUserException(); } $this->username = $username; $this->loadEnv(); $this->github_api = "https://api.github.com/users/{$this->username}?client_id=" . getenv('ClientID') . "&client_secret=" . getenv('ClientSecret'); parent::__construct([$this->github_api]); }
/** * Build a new Http request * @param array $auth [apikey, apisecret] * @param string $method http method * @param string $url call url * @param array $filters Mailjet resource filters * @param array $body Mailjet resource body * @param string $type Request Content-type */ public function __construct($auth, $method, $url, $filters, $body, $type) { parent::__construct(['defaults' => ['headers' => ['user-agent' => 'mailjet-apiv3-php/' . phpversion() . '/' . \Mailjet\Client::WRAPPER_VERSION]]]); $this->type = $type; $this->auth = $auth; $this->method = $method; $this->url = $url; $this->filters = $filters; $this->body = $body; }