1 | <?php |
||
11 | class Client |
||
12 | { |
||
13 | protected $guzzleClient; |
||
14 | |||
15 | protected $method = 'get'; |
||
16 | |||
17 | protected $uri = ''; |
||
18 | |||
19 | protected $options = [ ]; |
||
20 | |||
21 | /** |
||
22 | * instantiate Guzzle client (unless one is injected). |
||
23 | * |
||
24 | * @param GuzzleClient $httpClient |
||
25 | */ |
||
26 | public function __construct($httpClient = null) |
||
27 | { |
||
28 | $this->guzzleClient = $httpClient ?: new GuzzleClient; |
||
29 | $this->options[ 'headers' ] = [ 'Accept' => 'application/json' ]; |
||
30 | } |
||
31 | |||
32 | /** |
||
33 | * Setter for request method. |
||
34 | * |
||
35 | * @param string $method |
||
36 | * @return Client |
||
37 | */ |
||
38 | public function setMethod(string $method) |
||
43 | |||
44 | /** |
||
45 | * Setter for request end point URI. |
||
46 | * |
||
47 | * @param string $endPoint |
||
48 | * @return Client |
||
49 | */ |
||
50 | public function setEndPoint(string $endPoint) |
||
55 | |||
56 | /** |
||
57 | * Setter for request headers. |
||
58 | * |
||
59 | * @param array $header |
||
60 | * @return Client |
||
61 | */ |
||
62 | public function addHeader(array $header) |
||
67 | |||
68 | /** |
||
69 | * Setter for authentication headers. |
||
70 | * |
||
71 | * @param array $headers |
||
72 | * @return Client |
||
73 | */ |
||
74 | public function authHeaders(array $headers = [ ]) |
||
82 | |||
83 | /** |
||
84 | * Setter for request form data. |
||
85 | * |
||
86 | * @param array $formData |
||
87 | * @return Client |
||
88 | */ |
||
89 | public function setFormData(array $formData) |
||
94 | |||
95 | /** |
||
96 | * Setter for params. |
||
97 | * |
||
98 | * @param string $params |
||
99 | * @return Client |
||
100 | */ |
||
101 | public function setParams($params) |
||
110 | |||
111 | /** |
||
112 | * Dispatch the request and provide hooks for error handling for the response. |
||
113 | * |
||
114 | * @return object stdClass |
||
115 | */ |
||
116 | public function send() |
||
128 | |||
129 | /** |
||
130 | * Get http response body, cast to json and decode. |
||
131 | * |
||
132 | * @param ResponseInterface $response |
||
133 | * @return array |
||
134 | */ |
||
135 | protected function getBody(ResponseInterface $response) |
||
139 | |||
140 | /** |
||
141 | * Stub for API exception handling. |
||
142 | * |
||
143 | * @param String $exception |
||
144 | */ |
||
145 | protected function handleApiException($exception) { |
||
148 | } |
||
149 |