1 | <?php |
||
56 | class JustGivingClient |
||
57 | { |
||
58 | /** |
||
59 | * The clients that have been instantiated. |
||
60 | * |
||
61 | * @var array |
||
62 | */ |
||
63 | protected $clients = []; |
||
64 | |||
65 | /** |
||
66 | * The client to execute the HTTP requests. |
||
67 | * |
||
68 | * @var ClientInterface |
||
69 | */ |
||
70 | protected $httpClient; |
||
71 | |||
72 | /** |
||
73 | * The client options. |
||
74 | * |
||
75 | * @var array |
||
76 | */ |
||
77 | protected $options = [ |
||
78 | 'api_version' => 1, |
||
79 | 'root_domain' => 'https://api.justgiving.com', |
||
80 | ]; |
||
81 | |||
82 | /** |
||
83 | * @var AuthValue |
||
84 | */ |
||
85 | private $auth; |
||
86 | |||
87 | /** |
||
88 | * JustGivingClient constructor. |
||
89 | * |
||
90 | * @param AuthValue $auth |
||
91 | * @param ClientInterface $client |
||
92 | * @param array $options |
||
93 | */ |
||
94 | 89 | public function __construct(AuthValue $auth, ClientInterface $client = null, $options = []) |
|
100 | |||
101 | /** |
||
102 | * Set the client options, using defaults for any that are not provided. |
||
103 | * |
||
104 | * @param array $options |
||
105 | */ |
||
106 | 89 | private function setOptions(array $options) |
|
111 | |||
112 | /** |
||
113 | * Proxy a request onto the HTTP client, using the fully qualified URI. |
||
114 | * |
||
115 | * @param string $method |
||
116 | * @param string $uri |
||
117 | * @param array $httpOptions Custom options for the HTTP client (e.g. headers) |
||
118 | * @param array $clientOptions Custom options for the JustGiving client (e.g. API version) |
||
119 | * @return Response |
||
120 | * @throws \Psr\Http\Client\ClientExceptionInterface |
||
121 | */ |
||
122 | 74 | public function request($method, $uri, $httpOptions = [], $clientOptions = []) |
|
134 | |||
135 | /** |
||
136 | * Build the PSR-7 request object. Encode JSON payload and set headers if needed. |
||
137 | * |
||
138 | * @param string $method |
||
139 | * @param string $uri |
||
140 | * @param array $options |
||
141 | * @return Request |
||
142 | */ |
||
143 | 74 | private function buildRequest($method, $uri, $options) |
|
156 | |||
157 | /** |
||
158 | * Build the full URI using the root URI and API version. |
||
159 | * |
||
160 | * @param string $uri |
||
161 | * @return string |
||
162 | */ |
||
163 | 74 | private function buildUri($uri) |
|
167 | |||
168 | /** |
||
169 | * Merge the per-request headers with the auth headers. |
||
170 | * |
||
171 | * @param array $requestHeaders |
||
172 | * @return array |
||
173 | */ |
||
174 | 74 | private function buildHeaders($requestHeaders) |
|
180 | |||
181 | /** |
||
182 | * Allow API classes to be called as properties. Return a singleton client class. |
||
183 | * |
||
184 | * @param string $property |
||
185 | * @return mixed |
||
186 | * @throws \Exception |
||
187 | */ |
||
188 | 77 | public function __get($property) |
|
202 | } |
||
203 |