1 | <?php |
||
15 | class PublicAPIClient |
||
16 | { |
||
17 | /** |
||
18 | * @var CredentialsInterface |
||
19 | */ |
||
20 | private $credentials; |
||
21 | |||
22 | /** |
||
23 | * @var TransportInterface |
||
24 | */ |
||
25 | private $transport; |
||
26 | |||
27 | /** |
||
28 | * @var LoggerInterface |
||
29 | */ |
||
30 | private $logger; |
||
31 | |||
32 | /** |
||
33 | * @var ValidatorV1 |
||
34 | */ |
||
35 | private $validator; |
||
36 | |||
37 | /** |
||
38 | * @var string|null |
||
39 | */ |
||
40 | private $url; |
||
41 | |||
42 | /** |
||
43 | * Client constructor. |
||
44 | * @param CredentialsInterface $credentials |
||
45 | * @param TransportInterface $transport |
||
46 | * @param string|null $overrideURl |
||
47 | * @param LoggerInterface|null $logger |
||
48 | */ |
||
49 | public function __construct( |
||
67 | |||
68 | private function send(RequestInterface $request) |
||
90 | |||
91 | /** |
||
92 | * Utility method, that prepares and signs request |
||
93 | * |
||
94 | * @param RequestInterface $request |
||
95 | * @return RequestInterface |
||
96 | */ |
||
97 | private function prepareRequest(RequestInterface $request) |
||
111 | |||
112 | /** |
||
113 | * Utility function, that handles error response from Covery |
||
114 | * |
||
115 | * @param ResponseInterface $response |
||
116 | * @throws Exception |
||
117 | */ |
||
118 | private function handleNot200(ResponseInterface $response) |
||
145 | |||
146 | /** |
||
147 | * Utility method, that reads JSON data |
||
148 | * |
||
149 | * @param $string |
||
150 | * @return mixed|null |
||
151 | * @throws Exception |
||
152 | */ |
||
153 | private function readJson($string) |
||
174 | |||
175 | /** |
||
176 | * Sends request to Covery and returns access level, associated with |
||
177 | * used credentials |
||
178 | * |
||
179 | * This method can be used for Covery health check and availability |
||
180 | * On any problem (network, credentials, server side) this method |
||
181 | * will throw an exception |
||
182 | * |
||
183 | * @return string |
||
184 | * @throws Exception |
||
185 | */ |
||
186 | public function ping() |
||
195 | |||
196 | /** |
||
197 | * Sends envelope to Covery and returns it's ID on Covery side |
||
198 | * Before sending, validation is performed |
||
199 | * |
||
200 | * @param EnvelopeInterface $envelope |
||
201 | * @return int |
||
202 | * @throws Exception |
||
203 | */ |
||
204 | public function sendEvent(EnvelopeInterface $envelope) |
||
218 | |||
219 | /** |
||
220 | * Sends envelope to Covery for analysis |
||
221 | * |
||
222 | * @param EnvelopeInterface $envelope |
||
223 | * @return Result |
||
224 | * @throws Exception |
||
225 | */ |
||
226 | public function makeDecision(EnvelopeInterface $envelope) |
||
250 | } |
||
251 |