1 | <?php |
||
18 | class GuzzleClientFactory |
||
19 | { |
||
20 | /** @var string */ |
||
21 | protected $apiVersion; |
||
22 | |||
23 | /** @var string */ |
||
24 | protected $rootDomain; |
||
25 | |||
26 | /** @var array */ |
||
27 | protected $userOptions; |
||
28 | |||
29 | /** @var AuthValue */ |
||
30 | protected $auth; |
||
31 | |||
32 | /** |
||
33 | * GuzzleClientFactory constructor. |
||
34 | * |
||
35 | * @param AuthValue $auth |
||
36 | * @param array $options |
||
37 | */ |
||
38 | 89 | public function __construct(AuthValue $auth, $options = []) |
|
45 | |||
46 | /** |
||
47 | * Set up the handler stack with middleware, configure options and instantiate the Guzzle client. |
||
48 | * |
||
49 | * @return Client |
||
50 | */ |
||
51 | 89 | public function createClient() |
|
52 | { |
||
53 | 89 | $stack = HandlerStack::create(); |
|
54 | 89 | $stack->push(Middleware::mapResponse(function (ResponseInterface $response) { |
|
55 | 70 | return new Response($response); |
|
56 | 89 | })); |
|
57 | |||
58 | 89 | $defaultHeaders = ['Accept' => 'application/json']; |
|
59 | |||
60 | 89 | return new Client(array_merge([ |
|
61 | 89 | 'http_errors' => false, |
|
62 | 89 | 'handler' => $stack, |
|
63 | 89 | 'base_uri' => $this->baseUrl(), |
|
64 | 89 | 'headers' => array_merge($defaultHeaders, $this->auth->getHeaders()), |
|
65 | 89 | ], $this->userOptions)); |
|
66 | } |
||
67 | |||
68 | /** |
||
69 | * Return the base URL string for the API call. |
||
70 | * |
||
71 | * @return string |
||
72 | */ |
||
73 | 89 | protected function baseUrl() |
|
77 | } |
||
78 |