1 | <?php |
||
21 | class Client |
||
22 | { |
||
23 | public $baseUrl; |
||
24 | |||
25 | /** @var string Alma zone (institution or network) */ |
||
26 | public $zone; |
||
27 | |||
28 | /** @var string Alma Developers Network API key for this zone */ |
||
29 | public $key; |
||
30 | |||
31 | /** @var Client Network zone instance */ |
||
32 | public $nz; |
||
33 | |||
34 | /** @var HttpClient */ |
||
35 | protected $httpClient; |
||
36 | |||
37 | /** @var SruClient */ |
||
38 | public $sru; |
||
39 | |||
40 | /** @var Bibs */ |
||
41 | public $bibs; |
||
42 | |||
43 | /** @var Analytics */ |
||
44 | public $analytics; |
||
45 | |||
46 | /** @var Users */ |
||
47 | public $users; |
||
48 | |||
49 | /** @var int Max number of retries if we get 429 errors */ |
||
50 | public $maxAttempts = 10; |
||
51 | |||
52 | /** |
||
53 | * Create a new client to connect to a given Alma instance. |
||
54 | * |
||
55 | * @param string $key API key |
||
56 | * @param string $region Hosted region code, used to build base URL |
||
57 | * @param string $zone Alma zone (Either Zones::INSTITUTION or Zones::NETWORK) |
||
58 | * @param HttpClient $httpClient |
||
59 | * |
||
60 | * @throws \ErrorException |
||
61 | */ |
||
62 | public function __construct($key = null, $region = 'eu', $zone = Zones::INSTITUTION, HttpClient $httpClient = null) |
||
77 | |||
78 | /** |
||
79 | * Attach an SRU client (so you can search for Bib records). |
||
80 | * |
||
81 | * @param SruClient $sru |
||
82 | */ |
||
83 | public function setSruClient(SruClient $sru) |
||
87 | |||
88 | /** |
||
89 | * Assert that an SRU client is connected. Throws SruClientNotSetException if not. |
||
90 | * |
||
91 | * @throws SruClientNotSetException |
||
92 | */ |
||
93 | public function assertHasSruClient() |
||
99 | |||
100 | /** |
||
101 | * Set the API key for this Alma instance. |
||
102 | * |
||
103 | * @param string $key The API key |
||
104 | * @return $this |
||
105 | */ |
||
106 | public function setKey($key) |
||
112 | |||
113 | /** |
||
114 | * Set the Alma region code ('na' for North America, 'eu' for Europe, 'ap' for Asia Pacific). |
||
115 | * |
||
116 | * @param $regionCode |
||
117 | * @return $this |
||
118 | * @throws \ErrorException |
||
119 | */ |
||
120 | public function setRegion($regionCode) |
||
129 | |||
130 | /** |
||
131 | * @param $url |
||
132 | * |
||
133 | * @return string |
||
134 | */ |
||
135 | protected function getFullUrl($url) |
||
139 | |||
140 | /** |
||
141 | * @param array $options |
||
142 | * |
||
143 | * @return array |
||
144 | */ |
||
145 | protected function getHttpOptions($options = []) |
||
156 | |||
157 | /** |
||
158 | * Make a HTTP request. |
||
159 | * |
||
160 | * @param string $method |
||
161 | * @param string $url |
||
162 | * @param array $options |
||
163 | * @param int $attempt |
||
164 | * @return \Psr\Http\Message\ResponseInterface |
||
165 | */ |
||
166 | public function request($method, $url, $options = [], $attempt = 1) |
||
197 | |||
198 | /** |
||
199 | * Make a GET request. |
||
200 | * |
||
201 | * @param string $url |
||
202 | * @param array $query |
||
203 | * @param string $contentType |
||
204 | * @return string Response body |
||
205 | */ |
||
206 | public function get($url, $query = [], $contentType = 'application/json') |
||
215 | |||
216 | /** |
||
217 | * Make a GET request, accepting JSON. |
||
218 | * |
||
219 | * @param string $url |
||
220 | * @param array $query |
||
221 | * |
||
222 | * @return \stdClass JSON response as an object. |
||
223 | */ |
||
224 | public function getJSON($url, $query = []) |
||
230 | |||
231 | /** |
||
232 | * Make a GET request, accepting XML. |
||
233 | * |
||
234 | * @param string $url |
||
235 | * @param array $query |
||
236 | * |
||
237 | * @return QuiteSimpleXMLElement |
||
238 | */ |
||
239 | public function getXML($url, $query = []) |
||
245 | |||
246 | /** |
||
247 | * Make a PUT request. |
||
248 | * |
||
249 | * @param string $url |
||
250 | * @param $data |
||
251 | * @param string $contentType |
||
252 | * @return bool |
||
253 | */ |
||
254 | public function put($url, $data, $contentType = 'application/json') |
||
267 | |||
268 | /** |
||
269 | * Make a PUT request, sending JSON data. |
||
270 | * |
||
271 | * @param string $url |
||
272 | * @param $data |
||
273 | * |
||
274 | * @return bool |
||
275 | */ |
||
276 | public function putJSON($url, $data) |
||
282 | |||
283 | /** |
||
284 | * Make a PUT request, sending XML data. |
||
285 | * |
||
286 | * @param string $url |
||
287 | * @param $data |
||
288 | * |
||
289 | * @return bool |
||
290 | */ |
||
291 | public function putXML($url, $data) |
||
295 | |||
296 | /** |
||
297 | * Get the redirect target location of an URL, or null if not a redirect. |
||
298 | * |
||
299 | * @param string $url |
||
300 | * @param array $query |
||
301 | * |
||
302 | * @return string|null |
||
303 | */ |
||
304 | public function getRedirectLocation($url, $query = []) |
||
320 | } |
||
321 |