1 | <?php |
||
38 | class Client implements LoggerAwareInterface |
||
39 | { |
||
40 | private $apiroot = 'https://connect.liblynx.com'; |
||
41 | |||
42 | /** @var string client ID obtain from LibLynx Connect admin portal */ |
||
43 | private $clientId; |
||
44 | |||
45 | /** @var string client secret obtain from LibLynx Connect admin portal */ |
||
46 | private $clientSecret; |
||
47 | |||
48 | /** @var ClientInterface HTTP client for API requests */ |
||
49 | private $guzzle; |
||
50 | |||
51 | /** @var \stdClass entry point resource */ |
||
52 | private $entrypoint; |
||
53 | |||
54 | /** @var CacheInterface */ |
||
55 | protected $cache; |
||
56 | |||
57 | /** @var LoggerInterface */ |
||
58 | protected $log; |
||
59 | |||
60 | /** @var HTTPClientFactory */ |
||
61 | protected $httpClientFactory; |
||
62 | |||
63 | /** |
||
64 | * Create new LibLynx API client |
||
65 | */ |
||
66 | public function __construct(HTTPClientFactory $clientFactory = null) |
||
78 | |||
79 | /** |
||
80 | * @inheritdoc |
||
81 | */ |
||
82 | public function setLogger(LoggerInterface $logger) |
||
86 | |||
87 | /** |
||
88 | * Set API root |
||
89 | * An alternative root may be provided to you by LibLynx Technical Support |
||
90 | * @param string $url |
||
91 | */ |
||
92 | public function setAPIRoot($url) |
||
96 | |||
97 | /** |
||
98 | * Set OAuth2.0 client credentials |
||
99 | * These will be provided to you by LibLynx Technical Support |
||
100 | * |
||
101 | * @param string $clientId |
||
102 | * @param string $clientSecret |
||
103 | */ |
||
104 | public function setCredentials($clientId, $clientSecret) |
||
109 | |||
110 | /** |
||
111 | * @return array containing client id and secret |
||
112 | */ |
||
113 | public function getCredentials() |
||
117 | |||
118 | /** |
||
119 | * Attempt an identification using the LibLynx API |
||
120 | * |
||
121 | * @param IdentificationRequest $request |
||
122 | * @return Identification|null |
||
123 | */ |
||
124 | public function authorize(IdentificationRequest $request) |
||
147 | |||
148 | /** |
||
149 | * General purpose 'GET' request against API |
||
150 | * @param $entrypoint string contains either an @entrypoint or full URL obtained from a resource |
||
151 | * @return mixed |
||
152 | */ |
||
153 | public function get($entrypoint) |
||
157 | |||
158 | /** |
||
159 | * General purpose 'POST' request against API |
||
160 | * @param $entrypoint string contains either an @entrypoint or full URL obtained from a resource |
||
161 | * @param $json string contains JSON formatted data to post |
||
162 | * @return mixed |
||
163 | */ |
||
164 | public function post($entrypoint, $json) |
||
168 | |||
169 | /** |
||
170 | * General purpose 'PUT' request against API |
||
171 | * @param $entrypoint string contains either an @entrypoint or full URL obtained from a resource |
||
172 | * @return mixed string contains JSON formatted data to put |
||
173 | */ |
||
174 | public function put($entrypoint, $json) |
||
178 | |||
179 | /** |
||
180 | * @param $method |
||
181 | * @param $entrypoint |
||
182 | * @param null $json |
||
183 | * @return \stdClass object containing JSON decoded response - note this can be an error response for normally |
||
184 | * handled errors |
||
185 | * @throws LogicException for integration errors, e.g. not setting a cache |
||
186 | * @throws APIException for unexpected API failures |
||
187 | */ |
||
188 | protected function makeAPIRequest($method, $entrypoint, $json = null) |
||
233 | |||
234 | public function resolveEntryPoint($nameOrUrl) |
||
247 | |||
248 | public function getEntryPoint($name) |
||
262 | |||
263 | protected function getEntrypointResource() |
||
282 | |||
283 | public function getCache() |
||
290 | |||
291 | public function setCache(CacheInterface $cache) |
||
295 | |||
296 | /** |
||
297 | * Internal helper to provide an OAuth2 capable HTTP client |
||
298 | */ |
||
299 | protected function getClient() |
||
315 | } |
||
316 |