Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 588 |
|
0.00% |
0 / 15 |
CRAP | |
0.00% |
0 / 1 |
FingerprintApi | |
0.00% |
0 / 588 |
|
0.00% |
0 / 15 |
17556 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
12 | |||
getConfig | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
deleteVisitorData | |
0.00% |
0 / 52 |
|
0.00% |
0 / 1 |
132 | |||
deleteVisitorDataAsync | |
0.00% |
0 / 50 |
|
0.00% |
0 / 1 |
90 | |||
getEvent | |
0.00% |
0 / 48 |
|
0.00% |
0 / 1 |
110 | |||
getEventAsync | |
0.00% |
0 / 46 |
|
0.00% |
0 / 1 |
72 | |||
getVisits | |
0.00% |
0 / 53 |
|
0.00% |
0 / 1 |
132 | |||
getVisitsAsync | |
0.00% |
0 / 51 |
|
0.00% |
0 / 1 |
90 | |||
updateEvent | |
0.00% |
0 / 52 |
|
0.00% |
0 / 1 |
132 | |||
updateEventAsync | |
0.00% |
0 / 50 |
|
0.00% |
0 / 1 |
90 | |||
deleteVisitorDataRequest | |
0.00% |
0 / 39 |
|
0.00% |
0 / 1 |
90 | |||
getEventRequest | |
0.00% |
0 / 39 |
|
0.00% |
0 / 1 |
90 | |||
getVisitsRequest | |
0.00% |
0 / 49 |
|
0.00% |
0 / 1 |
210 | |||
updateEventRequest | |
0.00% |
0 / 50 |
|
0.00% |
0 / 1 |
240 | |||
createHttpClientOption | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
12 |
1 | <?php |
2 | /** |
3 | * FingerprintApi |
4 | * PHP version 5. |
5 | * |
6 | * @category Class |
7 | * |
8 | * @author Swagger Codegen team |
9 | * |
10 | * @see https://github.com/swagger-api/swagger-codegen |
11 | */ |
12 | |
13 | /** |
14 | * Fingerprint Pro Server API. |
15 | * |
16 | * Fingerprint Pro Server API allows you to get information about visitors and about individual events in a server environment. It can be used for data exports, decision-making, and data analysis scenarios. Server API is intended for server-side usage, it's not intended to be used from the client side, whether it's a browser or a mobile device. |
17 | * |
18 | * OpenAPI spec version: 3 |
19 | * Contact: support@fingerprint.com |
20 | * Generated by: https://github.com/swagger-api/swagger-codegen.git |
21 | * Swagger Codegen version: 3.0.34 |
22 | */ |
23 | /** |
24 | * NOTE: This class is auto generated by the swagger code generator program. |
25 | * https://github.com/swagger-api/swagger-codegen |
26 | * Do not edit the class manually. |
27 | */ |
28 | |
29 | namespace Fingerprint\ServerAPI\Api; |
30 | |
31 | use Fingerprint\ServerAPI\ApiException; |
32 | use Fingerprint\ServerAPI\Configuration; |
33 | use Fingerprint\ServerAPI\Model\EventsUpdateRequest; |
34 | use Fingerprint\ServerAPI\Model\ModelInterface; |
35 | use Fingerprint\ServerAPI\ObjectSerializer; |
36 | use Fingerprint\ServerAPI\SerializationException; |
37 | use GuzzleHttp\Client; |
38 | use GuzzleHttp\ClientInterface; |
39 | use GuzzleHttp\Exception\GuzzleException; |
40 | use GuzzleHttp\Exception\RequestException; |
41 | use GuzzleHttp\Promise\PromiseInterface; |
42 | use GuzzleHttp\Psr7\Request; |
43 | use GuzzleHttp\RequestOptions; |
44 | use Psr\Http\Message\ResponseInterface; |
45 | |
46 | /** |
47 | * FingerprintApi Class Doc Comment. |
48 | * |
49 | * @category Class |
50 | * |
51 | * @author Swagger Codegen team |
52 | * |
53 | * @see https://github.com/swagger-api/swagger-codegen |
54 | */ |
55 | class FingerprintApi |
56 | { |
57 | protected ClientInterface $client; |
58 | protected Configuration $config; |
59 | |
60 | protected string $integration_info = 'fingerprint-pro-server-php-sdk/6.1.0'; |
61 | |
62 | public function __construct( |
63 | ?ClientInterface $client = null, |
64 | ?Configuration $config = null |
65 | ) { |
66 | $this->client = $client ?: new Client(); |
67 | $this->config = $config ?: new Configuration(); |
68 | } |
69 | |
70 | public function getConfig(): Configuration |
71 | { |
72 | return $this->config; |
73 | } |
74 | |
75 | /** |
76 | * Operation deleteVisitorData. |
77 | * |
78 | * Delete data by visitor ID |
79 | * |
80 | * @param string $visitor_id The [visitor ID](https://dev.fingerprint.com/reference/get-function#visitorid) you want to delete. (required) |
81 | * |
82 | * @return array{ null, \Psr\Http\Message\ResponseInterface } |
83 | * |
84 | * @throws \InvalidArgumentException |
85 | * @throws SerializationException |
86 | * @throws GuzzleException |
87 | * @throws ApiException |
88 | */ |
89 | public function deleteVisitorData(string $visitor_id): array |
90 | { |
91 | $returnType = ''; |
92 | $request = $this->deleteVisitorDataRequest($visitor_id); |
93 | |
94 | try { |
95 | $options = $this->createHttpClientOption(); |
96 | |
97 | try { |
98 | $response = $this->client->send($request, $options); |
99 | } catch (RequestException $e) { |
100 | $apiException = new ApiException( |
101 | "[{$e->getCode()}] {$e->getMessage()}", |
102 | $e->getCode() |
103 | ); |
104 | $apiException->setResponseObject($e->getResponse()); |
105 | |
106 | throw $apiException; |
107 | } |
108 | |
109 | $statusCode = $response->getStatusCode(); |
110 | |
111 | if ($statusCode < 200 || $statusCode > 299) { |
112 | $apiException = new ApiException( |
113 | sprintf( |
114 | '[%d] Error connecting to the API (%s)', |
115 | $statusCode, |
116 | $request->getUri() |
117 | ), |
118 | $statusCode |
119 | ); |
120 | $apiException->setResponseObject($response); |
121 | |
122 | throw $apiException; |
123 | } |
124 | |
125 | return [null, $response]; |
126 | } catch (ApiException $e) { |
127 | /** @var ResponseInterface $response */ |
128 | $response = $e->getResponseObject(); |
129 | |
130 | switch ($e->getCode()) { |
131 | case 400: |
132 | $errorDetail = ObjectSerializer::deserialize($response, '\Fingerprint\ServerAPI\Model\ErrorResponse'); |
133 | $e->setErrorDetails($errorDetail); |
134 | $e->setResponseObject($response); |
135 | |
136 | break; |
137 | |
138 | case 403: |
139 | $errorDetail = ObjectSerializer::deserialize($response, '\Fingerprint\ServerAPI\Model\ErrorResponse'); |
140 | $e->setErrorDetails($errorDetail); |
141 | $e->setResponseObject($response); |
142 | |
143 | break; |
144 | |
145 | case 404: |
146 | $errorDetail = ObjectSerializer::deserialize($response, '\Fingerprint\ServerAPI\Model\ErrorResponse'); |
147 | $e->setErrorDetails($errorDetail); |
148 | $e->setResponseObject($response); |
149 | |
150 | break; |
151 | |
152 | case 429: |
153 | $errorDetail = ObjectSerializer::deserialize($response, '\Fingerprint\ServerAPI\Model\ErrorResponse'); |
154 | $e->setErrorDetails($errorDetail); |
155 | $e->setResponseObject($response); |
156 | |
157 | break; |
158 | } |
159 | |
160 | if (429 === $e->getCode()) { |
161 | $e->setRetryAfter(1); |
162 | if ($response->hasHeader('retry-after')) { |
163 | $e->setRetryAfter((int) $response->getHeader('retry-after')[0]); |
164 | } |
165 | } |
166 | |
167 | throw $e; |
168 | } |
169 | } |
170 | |
171 | /** |
172 | * Operation deleteVisitorDataAsync. |
173 | * |
174 | * Delete data by visitor ID |
175 | * |
176 | * @param string $visitor_id The [visitor ID](https://dev.fingerprint.com/reference/get-function#visitorid) you want to delete. (required) |
177 | * |
178 | * @throws \InvalidArgumentException |
179 | * @throws SerializationException |
180 | * @throws GuzzleException |
181 | * @throws ApiException |
182 | */ |
183 | public function deleteVisitorDataAsync(string $visitor_id): PromiseInterface |
184 | { |
185 | $returnType = ''; |
186 | $request = $this->deleteVisitorDataRequest($visitor_id); |
187 | |
188 | return $this->client |
189 | ->sendAsync($request, $this->createHttpClientOption()) |
190 | ->then( |
191 | function ($response) use ($request) { |
192 | $statusCode = $response->getStatusCode(); |
193 | |
194 | if ($statusCode < 200 || $statusCode > 299) { |
195 | $apiException = new ApiException( |
196 | sprintf( |
197 | '[%d] Error connecting to the API (%s)', |
198 | $statusCode, |
199 | $request->getUri() |
200 | ), |
201 | $statusCode |
202 | ); |
203 | $apiException->setResponseObject($response); |
204 | |
205 | throw $apiException; |
206 | } |
207 | |
208 | return [null, $response]; |
209 | }, |
210 | function ($e) { |
211 | /** @var ResponseInterface $response */ |
212 | $response = $e->getResponseObject(); |
213 | |
214 | switch ($e->getCode()) { |
215 | case 400: |
216 | $errorDetail = ObjectSerializer::deserialize($response, '\Fingerprint\ServerAPI\Model\ErrorResponse'); |
217 | $e->setErrorDetails($errorDetail); |
218 | $e->setResponseObject($response); |
219 | |
220 | break; |
221 | |
222 | case 403: |
223 | $errorDetail = ObjectSerializer::deserialize($response, '\Fingerprint\ServerAPI\Model\ErrorResponse'); |
224 | $e->setErrorDetails($errorDetail); |
225 | $e->setResponseObject($response); |
226 | |
227 | break; |
228 | |
229 | case 404: |
230 | $errorDetail = ObjectSerializer::deserialize($response, '\Fingerprint\ServerAPI\Model\ErrorResponse'); |
231 | $e->setErrorDetails($errorDetail); |
232 | $e->setResponseObject($response); |
233 | |
234 | break; |
235 | |
236 | case 429: |
237 | $errorDetail = ObjectSerializer::deserialize($response, '\Fingerprint\ServerAPI\Model\ErrorResponse'); |
238 | $e->setErrorDetails($errorDetail); |
239 | $e->setResponseObject($response); |
240 | |
241 | break; |
242 | } |
243 | |
244 | if (429 === $e->getCode()) { |
245 | $e->setRetryAfter(1); |
246 | if ($response->hasHeader('retry-after')) { |
247 | $e->setRetryAfter((int) $response->getHeader('retry-after')[0]); |
248 | } |
249 | } |
250 | |
251 | throw $e; |
252 | } |
253 | ); |
254 | } |
255 | |
256 | /** |
257 | * Operation getEvent. |
258 | * |
259 | * Get event by request ID |
260 | * |
261 | * @param string $request_id The unique [identifier](https://dev.fingerprint.com/reference/get-function#requestid) of each identification request. (required) |
262 | * |
263 | * @return array{ \Fingerprint\ServerAPI\Model\EventsGetResponse|null, \Psr\Http\Message\ResponseInterface } |
264 | * |
265 | * @throws \InvalidArgumentException |
266 | * @throws SerializationException |
267 | * @throws GuzzleException |
268 | * @throws ApiException |
269 | */ |
270 | public function getEvent(string $request_id): array |
271 | { |
272 | $returnType = '\Fingerprint\ServerAPI\Model\EventsGetResponse'; |
273 | $request = $this->getEventRequest($request_id); |
274 | |
275 | try { |
276 | $options = $this->createHttpClientOption(); |
277 | |
278 | try { |
279 | $response = $this->client->send($request, $options); |
280 | } catch (RequestException $e) { |
281 | $apiException = new ApiException( |
282 | "[{$e->getCode()}] {$e->getMessage()}", |
283 | $e->getCode() |
284 | ); |
285 | $apiException->setResponseObject($e->getResponse()); |
286 | |
287 | throw $apiException; |
288 | } |
289 | |
290 | $statusCode = $response->getStatusCode(); |
291 | |
292 | if ($statusCode < 200 || $statusCode > 299) { |
293 | $apiException = new ApiException( |
294 | sprintf( |
295 | '[%d] Error connecting to the API (%s)', |
296 | $statusCode, |
297 | $request->getUri() |
298 | ), |
299 | $statusCode |
300 | ); |
301 | $apiException->setResponseObject($response); |
302 | |
303 | throw $apiException; |
304 | } |
305 | |
306 | $serialized = ObjectSerializer::deserialize($response, $returnType); |
307 | |
308 | return [$serialized, $response]; |
309 | } catch (ApiException $e) { |
310 | /** @var ResponseInterface $response */ |
311 | $response = $e->getResponseObject(); |
312 | |
313 | switch ($e->getCode()) { |
314 | case 200: |
315 | $errorDetail = ObjectSerializer::deserialize($response, '\Fingerprint\ServerAPI\Model\EventsGetResponse'); |
316 | $e->setErrorDetails($errorDetail); |
317 | $e->setResponseObject($response); |
318 | |
319 | break; |
320 | |
321 | case 403: |
322 | $errorDetail = ObjectSerializer::deserialize($response, '\Fingerprint\ServerAPI\Model\ErrorResponse'); |
323 | $e->setErrorDetails($errorDetail); |
324 | $e->setResponseObject($response); |
325 | |
326 | break; |
327 | |
328 | case 404: |
329 | $errorDetail = ObjectSerializer::deserialize($response, '\Fingerprint\ServerAPI\Model\ErrorResponse'); |
330 | $e->setErrorDetails($errorDetail); |
331 | $e->setResponseObject($response); |
332 | |
333 | break; |
334 | } |
335 | |
336 | if (429 === $e->getCode()) { |
337 | $e->setRetryAfter(1); |
338 | if ($response->hasHeader('retry-after')) { |
339 | $e->setRetryAfter((int) $response->getHeader('retry-after')[0]); |
340 | } |
341 | } |
342 | |
343 | throw $e; |
344 | } |
345 | } |
346 | |
347 | /** |
348 | * Operation getEventAsync. |
349 | * |
350 | * Get event by request ID |
351 | * |
352 | * @param string $request_id The unique [identifier](https://dev.fingerprint.com/reference/get-function#requestid) of each identification request. (required) |
353 | * |
354 | * @throws \InvalidArgumentException |
355 | * @throws SerializationException |
356 | * @throws GuzzleException |
357 | * @throws ApiException |
358 | */ |
359 | public function getEventAsync(string $request_id): PromiseInterface |
360 | { |
361 | $returnType = '\Fingerprint\ServerAPI\Model\EventsGetResponse'; |
362 | $request = $this->getEventRequest($request_id); |
363 | |
364 | return $this->client |
365 | ->sendAsync($request, $this->createHttpClientOption()) |
366 | ->then( |
367 | function ($response) use ($returnType, $request) { |
368 | $statusCode = $response->getStatusCode(); |
369 | |
370 | if ($statusCode < 200 || $statusCode > 299) { |
371 | $apiException = new ApiException( |
372 | sprintf( |
373 | '[%d] Error connecting to the API (%s)', |
374 | $statusCode, |
375 | $request->getUri() |
376 | ), |
377 | $statusCode |
378 | ); |
379 | $apiException->setResponseObject($response); |
380 | |
381 | throw $apiException; |
382 | } |
383 | |
384 | $serialized = ObjectSerializer::deserialize($response, $returnType); |
385 | |
386 | return [$serialized, $response]; |
387 | }, |
388 | function ($e) { |
389 | /** @var ResponseInterface $response */ |
390 | $response = $e->getResponseObject(); |
391 | |
392 | switch ($e->getCode()) { |
393 | case 200: |
394 | $errorDetail = ObjectSerializer::deserialize($response, '\Fingerprint\ServerAPI\Model\EventsGetResponse'); |
395 | $e->setErrorDetails($errorDetail); |
396 | $e->setResponseObject($response); |
397 | |
398 | break; |
399 | |
400 | case 403: |
401 | $errorDetail = ObjectSerializer::deserialize($response, '\Fingerprint\ServerAPI\Model\ErrorResponse'); |
402 | $e->setErrorDetails($errorDetail); |
403 | $e->setResponseObject($response); |
404 | |
405 | break; |
406 | |
407 | case 404: |
408 | $errorDetail = ObjectSerializer::deserialize($response, '\Fingerprint\ServerAPI\Model\ErrorResponse'); |
409 | $e->setErrorDetails($errorDetail); |
410 | $e->setResponseObject($response); |
411 | |
412 | break; |
413 | } |
414 | |
415 | if (429 === $e->getCode()) { |
416 | $e->setRetryAfter(1); |
417 | if ($response->hasHeader('retry-after')) { |
418 | $e->setRetryAfter((int) $response->getHeader('retry-after')[0]); |
419 | } |
420 | } |
421 | |
422 | throw $e; |
423 | } |
424 | ); |
425 | } |
426 | |
427 | /** |
428 | * Operation getVisits. |
429 | * |
430 | * Get visits by visitor ID |
431 | * |
432 | * @param string $visitor_id Unique [visitor identifier](https://dev.fingerprint.com/reference/get-function#visitorid) issued by Fingerprint Pro. (required) |
433 | * @param string $request_id Filter visits by `requestId`. Every identification request has a unique identifier associated with it called `requestId`. This identifier is returned to the client in the identification [result](https://dev.fingerprint.com/reference/get-function#requestid). When you filter visits by `requestId`, only one visit will be returned. (optional) |
434 | * @param string $linked_id Filter visits by your custom identifier. You can use [`linkedId`](https://dev.fingerprint.com/reference/get-function#linkedid) to associate identification requests with your own identifier, for example: session ID, purchase ID, or transaction ID. You can then use this `linked_id` parameter to retrieve all events associated with your custom identifier. (optional) |
435 | * @param int $limit Limit scanned results. For performance reasons, the API first scans some number of events before filtering them. Use `limit` to specify how many events are scanned before they are filtered by `requestId` or `linkedId`. Results are always returned sorted by the timestamp (most recent first). By default, the most recent 100 visits are scanned, the maximum is 500. (optional) |
436 | * @param string $pagination_key Use `paginationKey` to get the next page of results. When more results are available (e.g., you requested 200 results using `limit` parameter, but a total of 600 results are available), the `paginationKey` top-level attribute is added to the response. The key corresponds to the `requestId` of the last returned event. In the following request, use that value in the `paginationKey` parameter to get the next page of results: 1. First request, returning most recent 200 events: `GET api-base-url/visitors/:visitorId?limit=200` 2. Use `response.paginationKey` to get the next page of results: `GET api-base-url/visitors/:visitorId?limit=200&paginationKey=1683900801733.Ogvu1j` Pagination happens during scanning and before filtering, so you can get less visits than the `limit` you specified with more available on the next page. When there are no more results available for scanning, the `paginationKey` attribute is not returned. (optional) |
437 | * @param int $before ⚠️ Deprecated pagination method, please use `paginationKey` instead. Timestamp (in milliseconds since epoch) used to paginate results. (optional) |
438 | * |
439 | * @return array{ \Fingerprint\ServerAPI\Model\VisitorsGetResponse|null, \Psr\Http\Message\ResponseInterface } |
440 | * |
441 | * @throws \InvalidArgumentException |
442 | * @throws SerializationException |
443 | * @throws GuzzleException |
444 | * @throws ApiException |
445 | */ |
446 | public function getVisits(string $visitor_id, ?string $request_id = null, ?string $linked_id = null, ?int $limit = null, ?string $pagination_key = null, ?int $before = null): array |
447 | { |
448 | $returnType = '\Fingerprint\ServerAPI\Model\VisitorsGetResponse'; |
449 | $request = $this->getVisitsRequest($visitor_id, $request_id, $linked_id, $limit, $pagination_key, $before); |
450 | |
451 | try { |
452 | $options = $this->createHttpClientOption(); |
453 | |
454 | try { |
455 | $response = $this->client->send($request, $options); |
456 | } catch (RequestException $e) { |
457 | $apiException = new ApiException( |
458 | "[{$e->getCode()}] {$e->getMessage()}", |
459 | $e->getCode() |
460 | ); |
461 | $apiException->setResponseObject($e->getResponse()); |
462 | |
463 | throw $apiException; |
464 | } |
465 | |
466 | $statusCode = $response->getStatusCode(); |
467 | |
468 | if ($statusCode < 200 || $statusCode > 299) { |
469 | $apiException = new ApiException( |
470 | sprintf( |
471 | '[%d] Error connecting to the API (%s)', |
472 | $statusCode, |
473 | $request->getUri() |
474 | ), |
475 | $statusCode |
476 | ); |
477 | $apiException->setResponseObject($response); |
478 | |
479 | throw $apiException; |
480 | } |
481 | |
482 | $serialized = ObjectSerializer::deserialize($response, $returnType); |
483 | |
484 | return [$serialized, $response]; |
485 | } catch (ApiException $e) { |
486 | /** @var ResponseInterface $response */ |
487 | $response = $e->getResponseObject(); |
488 | |
489 | switch ($e->getCode()) { |
490 | case 200: |
491 | $errorDetail = ObjectSerializer::deserialize($response, '\Fingerprint\ServerAPI\Model\VisitorsGetResponse'); |
492 | $e->setErrorDetails($errorDetail); |
493 | $e->setResponseObject($response); |
494 | |
495 | break; |
496 | |
497 | case 400: |
498 | $errorDetail = ObjectSerializer::deserialize($response, '\Fingerprint\ServerAPI\Model\ErrorPlainResponse'); |
499 | $e->setErrorDetails($errorDetail); |
500 | $e->setResponseObject($response); |
501 | |
502 | break; |
503 | |
504 | case 403: |
505 | $errorDetail = ObjectSerializer::deserialize($response, '\Fingerprint\ServerAPI\Model\ErrorPlainResponse'); |
506 | $e->setErrorDetails($errorDetail); |
507 | $e->setResponseObject($response); |
508 | |
509 | break; |
510 | |
511 | case 429: |
512 | $errorDetail = ObjectSerializer::deserialize($response, '\Fingerprint\ServerAPI\Model\ErrorPlainResponse'); |
513 | $e->setErrorDetails($errorDetail); |
514 | $e->setResponseObject($response); |
515 | |
516 | break; |
517 | } |
518 | |
519 | if (429 === $e->getCode()) { |
520 | $e->setRetryAfter(1); |
521 | if ($response->hasHeader('retry-after')) { |
522 | $e->setRetryAfter((int) $response->getHeader('retry-after')[0]); |
523 | } |
524 | } |
525 | |
526 | throw $e; |
527 | } |
528 | } |
529 | |
530 | /** |
531 | * Operation getVisitsAsync. |
532 | * |
533 | * Get visits by visitor ID |
534 | * |
535 | * @param string $visitor_id Unique [visitor identifier](https://dev.fingerprint.com/reference/get-function#visitorid) issued by Fingerprint Pro. (required) |
536 | * @param string $request_id Filter visits by `requestId`. Every identification request has a unique identifier associated with it called `requestId`. This identifier is returned to the client in the identification [result](https://dev.fingerprint.com/reference/get-function#requestid). When you filter visits by `requestId`, only one visit will be returned. (optional) |
537 | * @param string $linked_id Filter visits by your custom identifier. You can use [`linkedId`](https://dev.fingerprint.com/reference/get-function#linkedid) to associate identification requests with your own identifier, for example: session ID, purchase ID, or transaction ID. You can then use this `linked_id` parameter to retrieve all events associated with your custom identifier. (optional) |
538 | * @param int $limit Limit scanned results. For performance reasons, the API first scans some number of events before filtering them. Use `limit` to specify how many events are scanned before they are filtered by `requestId` or `linkedId`. Results are always returned sorted by the timestamp (most recent first). By default, the most recent 100 visits are scanned, the maximum is 500. (optional) |
539 | * @param string $pagination_key Use `paginationKey` to get the next page of results. When more results are available (e.g., you requested 200 results using `limit` parameter, but a total of 600 results are available), the `paginationKey` top-level attribute is added to the response. The key corresponds to the `requestId` of the last returned event. In the following request, use that value in the `paginationKey` parameter to get the next page of results: 1. First request, returning most recent 200 events: `GET api-base-url/visitors/:visitorId?limit=200` 2. Use `response.paginationKey` to get the next page of results: `GET api-base-url/visitors/:visitorId?limit=200&paginationKey=1683900801733.Ogvu1j` Pagination happens during scanning and before filtering, so you can get less visits than the `limit` you specified with more available on the next page. When there are no more results available for scanning, the `paginationKey` attribute is not returned. (optional) |
540 | * @param int $before ⚠️ Deprecated pagination method, please use `paginationKey` instead. Timestamp (in milliseconds since epoch) used to paginate results. (optional) |
541 | * |
542 | * @throws \InvalidArgumentException |
543 | * @throws SerializationException |
544 | * @throws GuzzleException |
545 | * @throws ApiException |
546 | */ |
547 | public function getVisitsAsync(string $visitor_id, ?string $request_id = null, ?string $linked_id = null, ?int $limit = null, ?string $pagination_key = null, ?int $before = null): PromiseInterface |
548 | { |
549 | $returnType = '\Fingerprint\ServerAPI\Model\VisitorsGetResponse'; |
550 | $request = $this->getVisitsRequest($visitor_id, $request_id, $linked_id, $limit, $pagination_key, $before); |
551 | |
552 | return $this->client |
553 | ->sendAsync($request, $this->createHttpClientOption()) |
554 | ->then( |
555 | function ($response) use ($returnType, $request) { |
556 | $statusCode = $response->getStatusCode(); |
557 | |
558 | if ($statusCode < 200 || $statusCode > 299) { |
559 | $apiException = new ApiException( |
560 | sprintf( |
561 | '[%d] Error connecting to the API (%s)', |
562 | $statusCode, |
563 | $request->getUri() |
564 | ), |
565 | $statusCode |
566 | ); |
567 | $apiException->setResponseObject($response); |
568 | |
569 | throw $apiException; |
570 | } |
571 | |
572 | $serialized = ObjectSerializer::deserialize($response, $returnType); |
573 | |
574 | return [$serialized, $response]; |
575 | }, |
576 | function ($e) { |
577 | /** @var ResponseInterface $response */ |
578 | $response = $e->getResponseObject(); |
579 | |
580 | switch ($e->getCode()) { |
581 | case 200: |
582 | $errorDetail = ObjectSerializer::deserialize($response, '\Fingerprint\ServerAPI\Model\VisitorsGetResponse'); |
583 | $e->setErrorDetails($errorDetail); |
584 | $e->setResponseObject($response); |
585 | |
586 | break; |
587 | |
588 | case 400: |
589 | $errorDetail = ObjectSerializer::deserialize($response, '\Fingerprint\ServerAPI\Model\ErrorPlainResponse'); |
590 | $e->setErrorDetails($errorDetail); |
591 | $e->setResponseObject($response); |
592 | |
593 | break; |
594 | |
595 | case 403: |
596 | $errorDetail = ObjectSerializer::deserialize($response, '\Fingerprint\ServerAPI\Model\ErrorPlainResponse'); |
597 | $e->setErrorDetails($errorDetail); |
598 | $e->setResponseObject($response); |
599 | |
600 | break; |
601 | |
602 | case 429: |
603 | $errorDetail = ObjectSerializer::deserialize($response, '\Fingerprint\ServerAPI\Model\ErrorPlainResponse'); |
604 | $e->setErrorDetails($errorDetail); |
605 | $e->setResponseObject($response); |
606 | |
607 | break; |
608 | } |
609 | |
610 | if (429 === $e->getCode()) { |
611 | $e->setRetryAfter(1); |
612 | if ($response->hasHeader('retry-after')) { |
613 | $e->setRetryAfter((int) $response->getHeader('retry-after')[0]); |
614 | } |
615 | } |
616 | |
617 | throw $e; |
618 | } |
619 | ); |
620 | } |
621 | |
622 | /** |
623 | * Operation updateEvent. |
624 | * |
625 | * Update an event with a given request ID |
626 | * |
627 | * @param EventsUpdateRequest $body (required) |
628 | * @param string $request_id The unique event [identifier](https://dev.fingerprint.com/reference/get-function#requestid). (required) |
629 | * |
630 | * @return array{ null, \Psr\Http\Message\ResponseInterface } |
631 | * |
632 | * @throws \InvalidArgumentException |
633 | * @throws SerializationException |
634 | * @throws GuzzleException |
635 | * @throws ApiException |
636 | */ |
637 | public function updateEvent(EventsUpdateRequest $body, string $request_id): array |
638 | { |
639 | $returnType = ''; |
640 | $request = $this->updateEventRequest($body, $request_id); |
641 | |
642 | try { |
643 | $options = $this->createHttpClientOption(); |
644 | |
645 | try { |
646 | $response = $this->client->send($request, $options); |
647 | } catch (RequestException $e) { |
648 | $apiException = new ApiException( |
649 | "[{$e->getCode()}] {$e->getMessage()}", |
650 | $e->getCode() |
651 | ); |
652 | $apiException->setResponseObject($e->getResponse()); |
653 | |
654 | throw $apiException; |
655 | } |
656 | |
657 | $statusCode = $response->getStatusCode(); |
658 | |
659 | if ($statusCode < 200 || $statusCode > 299) { |
660 | $apiException = new ApiException( |
661 | sprintf( |
662 | '[%d] Error connecting to the API (%s)', |
663 | $statusCode, |
664 | $request->getUri() |
665 | ), |
666 | $statusCode |
667 | ); |
668 | $apiException->setResponseObject($response); |
669 | |
670 | throw $apiException; |
671 | } |
672 | |
673 | return [null, $response]; |
674 | } catch (ApiException $e) { |
675 | /** @var ResponseInterface $response */ |
676 | $response = $e->getResponseObject(); |
677 | |
678 | switch ($e->getCode()) { |
679 | case 400: |
680 | $errorDetail = ObjectSerializer::deserialize($response, '\Fingerprint\ServerAPI\Model\ErrorResponse'); |
681 | $e->setErrorDetails($errorDetail); |
682 | $e->setResponseObject($response); |
683 | |
684 | break; |
685 | |
686 | case 403: |
687 | $errorDetail = ObjectSerializer::deserialize($response, '\Fingerprint\ServerAPI\Model\ErrorResponse'); |
688 | $e->setErrorDetails($errorDetail); |
689 | $e->setResponseObject($response); |
690 | |
691 | break; |
692 | |
693 | case 404: |
694 | $errorDetail = ObjectSerializer::deserialize($response, '\Fingerprint\ServerAPI\Model\ErrorResponse'); |
695 | $e->setErrorDetails($errorDetail); |
696 | $e->setResponseObject($response); |
697 | |
698 | break; |
699 | |
700 | case 409: |
701 | $errorDetail = ObjectSerializer::deserialize($response, '\Fingerprint\ServerAPI\Model\ErrorResponse'); |
702 | $e->setErrorDetails($errorDetail); |
703 | $e->setResponseObject($response); |
704 | |
705 | break; |
706 | } |
707 | |
708 | if (429 === $e->getCode()) { |
709 | $e->setRetryAfter(1); |
710 | if ($response->hasHeader('retry-after')) { |
711 | $e->setRetryAfter((int) $response->getHeader('retry-after')[0]); |
712 | } |
713 | } |
714 | |
715 | throw $e; |
716 | } |
717 | } |
718 | |
719 | /** |
720 | * Operation updateEventAsync. |
721 | * |
722 | * Update an event with a given request ID |
723 | * |
724 | * @param EventsUpdateRequest $body (required) |
725 | * @param string $request_id The unique event [identifier](https://dev.fingerprint.com/reference/get-function#requestid). (required) |
726 | * |
727 | * @throws \InvalidArgumentException |
728 | * @throws SerializationException |
729 | * @throws GuzzleException |
730 | * @throws ApiException |
731 | */ |
732 | public function updateEventAsync(EventsUpdateRequest $body, string $request_id): PromiseInterface |
733 | { |
734 | $returnType = ''; |
735 | $request = $this->updateEventRequest($body, $request_id); |
736 | |
737 | return $this->client |
738 | ->sendAsync($request, $this->createHttpClientOption()) |
739 | ->then( |
740 | function ($response) use ($request) { |
741 | $statusCode = $response->getStatusCode(); |
742 | |
743 | if ($statusCode < 200 || $statusCode > 299) { |
744 | $apiException = new ApiException( |
745 | sprintf( |
746 | '[%d] Error connecting to the API (%s)', |
747 | $statusCode, |
748 | $request->getUri() |
749 | ), |
750 | $statusCode |
751 | ); |
752 | $apiException->setResponseObject($response); |
753 | |
754 | throw $apiException; |
755 | } |
756 | |
757 | return [null, $response]; |
758 | }, |
759 | function ($e) { |
760 | /** @var ResponseInterface $response */ |
761 | $response = $e->getResponseObject(); |
762 | |
763 | switch ($e->getCode()) { |
764 | case 400: |
765 | $errorDetail = ObjectSerializer::deserialize($response, '\Fingerprint\ServerAPI\Model\ErrorResponse'); |
766 | $e->setErrorDetails($errorDetail); |
767 | $e->setResponseObject($response); |
768 | |
769 | break; |
770 | |
771 | case 403: |
772 | $errorDetail = ObjectSerializer::deserialize($response, '\Fingerprint\ServerAPI\Model\ErrorResponse'); |
773 | $e->setErrorDetails($errorDetail); |
774 | $e->setResponseObject($response); |
775 | |
776 | break; |
777 | |
778 | case 404: |
779 | $errorDetail = ObjectSerializer::deserialize($response, '\Fingerprint\ServerAPI\Model\ErrorResponse'); |
780 | $e->setErrorDetails($errorDetail); |
781 | $e->setResponseObject($response); |
782 | |
783 | break; |
784 | |
785 | case 409: |
786 | $errorDetail = ObjectSerializer::deserialize($response, '\Fingerprint\ServerAPI\Model\ErrorResponse'); |
787 | $e->setErrorDetails($errorDetail); |
788 | $e->setResponseObject($response); |
789 | |
790 | break; |
791 | } |
792 | |
793 | if (429 === $e->getCode()) { |
794 | $e->setRetryAfter(1); |
795 | if ($response->hasHeader('retry-after')) { |
796 | $e->setRetryAfter((int) $response->getHeader('retry-after')[0]); |
797 | } |
798 | } |
799 | |
800 | throw $e; |
801 | } |
802 | ); |
803 | } |
804 | |
805 | /** |
806 | * Create request for operation 'deleteVisitorData'. |
807 | * |
808 | * @throws \InvalidArgumentException |
809 | * @throws SerializationException |
810 | * @throws GuzzleException |
811 | * @throws ApiException |
812 | */ |
813 | protected function deleteVisitorDataRequest(string $visitor_id): Request |
814 | { |
815 | // verify the required parameter 'visitor_id' is set |
816 | if (null === $visitor_id || (is_array($visitor_id) && 0 === count($visitor_id))) { |
817 | throw new \InvalidArgumentException( |
818 | 'Missing the required parameter $visitor_id when calling deleteVisitorData' |
819 | ); |
820 | } |
821 | |
822 | $resourcePath = '/visitors/{visitor_id}'; |
823 | $headers = []; |
824 | $queryParams = ['ii' => $this->integration_info]; |
825 | $headerParams = []; |
826 | $httpBody = ''; |
827 | |
828 | // path params |
829 | if (null !== $visitor_id) { |
830 | $resourcePath = str_replace( |
831 | '{visitor_id}', |
832 | ObjectSerializer::toPathValue($visitor_id), |
833 | $resourcePath |
834 | ); |
835 | } |
836 | |
837 | // this endpoint requires API key authentication |
838 | $apiKey = $this->config->getApiKeyWithPrefix('Auth-API-Key'); |
839 | if (null !== $apiKey) { |
840 | $headers['Auth-API-Key'] = $apiKey; |
841 | } |
842 | // this endpoint requires API key authentication |
843 | $apiKey = $this->config->getApiKeyWithPrefix('api_key'); |
844 | if (null !== $apiKey) { |
845 | $queryParams['api_key'] = $apiKey; |
846 | } |
847 | |
848 | $defaultHeaders = [ |
849 | 'Content-Type' => 'application/json', |
850 | 'Accept' => 'application/json', |
851 | ]; |
852 | if ($this->config->getUserAgent()) { |
853 | $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); |
854 | } |
855 | |
856 | $headers = array_merge( |
857 | $defaultHeaders, |
858 | $headerParams, |
859 | $headers |
860 | ); |
861 | |
862 | $query = http_build_query($queryParams); |
863 | |
864 | return new Request( |
865 | 'DELETE', |
866 | $this->config->getHost().$resourcePath.($query ? "?{$query}" : ''), |
867 | $headers, |
868 | $httpBody |
869 | ); |
870 | } |
871 | |
872 | /** |
873 | * Create request for operation 'getEvent'. |
874 | * |
875 | * @throws \InvalidArgumentException |
876 | * @throws SerializationException |
877 | * @throws GuzzleException |
878 | * @throws ApiException |
879 | */ |
880 | protected function getEventRequest(string $request_id): Request |
881 | { |
882 | // verify the required parameter 'request_id' is set |
883 | if (null === $request_id || (is_array($request_id) && 0 === count($request_id))) { |
884 | throw new \InvalidArgumentException( |
885 | 'Missing the required parameter $request_id when calling getEvent' |
886 | ); |
887 | } |
888 | |
889 | $resourcePath = '/events/{request_id}'; |
890 | $headers = []; |
891 | $queryParams = ['ii' => $this->integration_info]; |
892 | $headerParams = []; |
893 | $httpBody = ''; |
894 | |
895 | // path params |
896 | if (null !== $request_id) { |
897 | $resourcePath = str_replace( |
898 | '{request_id}', |
899 | ObjectSerializer::toPathValue($request_id), |
900 | $resourcePath |
901 | ); |
902 | } |
903 | |
904 | // this endpoint requires API key authentication |
905 | $apiKey = $this->config->getApiKeyWithPrefix('Auth-API-Key'); |
906 | if (null !== $apiKey) { |
907 | $headers['Auth-API-Key'] = $apiKey; |
908 | } |
909 | // this endpoint requires API key authentication |
910 | $apiKey = $this->config->getApiKeyWithPrefix('api_key'); |
911 | if (null !== $apiKey) { |
912 | $queryParams['api_key'] = $apiKey; |
913 | } |
914 | |
915 | $defaultHeaders = [ |
916 | 'Content-Type' => 'application/json', |
917 | 'Accept' => 'application/json', |
918 | ]; |
919 | if ($this->config->getUserAgent()) { |
920 | $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); |
921 | } |
922 | |
923 | $headers = array_merge( |
924 | $defaultHeaders, |
925 | $headerParams, |
926 | $headers |
927 | ); |
928 | |
929 | $query = http_build_query($queryParams); |
930 | |
931 | return new Request( |
932 | 'GET', |
933 | $this->config->getHost().$resourcePath.($query ? "?{$query}" : ''), |
934 | $headers, |
935 | $httpBody |
936 | ); |
937 | } |
938 | |
939 | /** |
940 | * Create request for operation 'getVisits'. |
941 | * |
942 | * @throws \InvalidArgumentException |
943 | * @throws SerializationException |
944 | * @throws GuzzleException |
945 | * @throws ApiException |
946 | */ |
947 | protected function getVisitsRequest(string $visitor_id, ?string $request_id = null, ?string $linked_id = null, ?int $limit = null, ?string $pagination_key = null, ?int $before = null): Request |
948 | { |
949 | // verify the required parameter 'visitor_id' is set |
950 | if (null === $visitor_id || (is_array($visitor_id) && 0 === count($visitor_id))) { |
951 | throw new \InvalidArgumentException( |
952 | 'Missing the required parameter $visitor_id when calling getVisits' |
953 | ); |
954 | } |
955 | |
956 | $resourcePath = '/visitors/{visitor_id}'; |
957 | $headers = []; |
958 | $queryParams = ['ii' => $this->integration_info]; |
959 | $headerParams = []; |
960 | $httpBody = ''; |
961 | |
962 | // query params |
963 | if (null !== $request_id) { |
964 | $queryParams['request_id'] = ObjectSerializer::toQueryValue($request_id, null); |
965 | } |
966 | // query params |
967 | if (null !== $linked_id) { |
968 | $queryParams['linked_id'] = ObjectSerializer::toQueryValue($linked_id, null); |
969 | } |
970 | // query params |
971 | if (null !== $limit) { |
972 | $queryParams['limit'] = ObjectSerializer::toQueryValue($limit, 'int32'); |
973 | } |
974 | // query params |
975 | if (null !== $pagination_key) { |
976 | $queryParams['paginationKey'] = ObjectSerializer::toQueryValue($pagination_key, null); |
977 | } |
978 | // query params |
979 | if (null !== $before) { |
980 | $queryParams['before'] = ObjectSerializer::toQueryValue($before, 'int64'); |
981 | } |
982 | |
983 | // path params |
984 | if (null !== $visitor_id) { |
985 | $resourcePath = str_replace( |
986 | '{visitor_id}', |
987 | ObjectSerializer::toPathValue($visitor_id), |
988 | $resourcePath |
989 | ); |
990 | } |
991 | |
992 | // this endpoint requires API key authentication |
993 | $apiKey = $this->config->getApiKeyWithPrefix('Auth-API-Key'); |
994 | if (null !== $apiKey) { |
995 | $headers['Auth-API-Key'] = $apiKey; |
996 | } |
997 | // this endpoint requires API key authentication |
998 | $apiKey = $this->config->getApiKeyWithPrefix('api_key'); |
999 | if (null !== $apiKey) { |
1000 | $queryParams['api_key'] = $apiKey; |
1001 | } |
1002 | |
1003 | $defaultHeaders = [ |
1004 | 'Content-Type' => 'application/json', |
1005 | 'Accept' => 'application/json', |
1006 | ]; |
1007 | if ($this->config->getUserAgent()) { |
1008 | $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); |
1009 | } |
1010 | |
1011 | $headers = array_merge( |
1012 | $defaultHeaders, |
1013 | $headerParams, |
1014 | $headers |
1015 | ); |
1016 | |
1017 | $query = http_build_query($queryParams); |
1018 | |
1019 | return new Request( |
1020 | 'GET', |
1021 | $this->config->getHost().$resourcePath.($query ? "?{$query}" : ''), |
1022 | $headers, |
1023 | $httpBody |
1024 | ); |
1025 | } |
1026 | |
1027 | /** |
1028 | * Create request for operation 'updateEvent'. |
1029 | * |
1030 | * @throws \InvalidArgumentException |
1031 | * @throws SerializationException |
1032 | * @throws GuzzleException |
1033 | * @throws ApiException |
1034 | */ |
1035 | protected function updateEventRequest(EventsUpdateRequest $body, string $request_id): Request |
1036 | { |
1037 | // verify the required parameter 'body' is set |
1038 | if (null === $body || (is_array($body) && 0 === count($body))) { |
1039 | throw new \InvalidArgumentException( |
1040 | 'Missing the required parameter $body when calling updateEvent' |
1041 | ); |
1042 | } |
1043 | // verify the required parameter 'request_id' is set |
1044 | if (null === $request_id || (is_array($request_id) && 0 === count($request_id))) { |
1045 | throw new \InvalidArgumentException( |
1046 | 'Missing the required parameter $request_id when calling updateEvent' |
1047 | ); |
1048 | } |
1049 | |
1050 | $resourcePath = '/events/{request_id}'; |
1051 | $headers = []; |
1052 | $queryParams = ['ii' => $this->integration_info]; |
1053 | $headerParams = []; |
1054 | $httpBody = ''; |
1055 | |
1056 | // path params |
1057 | if (null !== $request_id) { |
1058 | $resourcePath = str_replace( |
1059 | '{request_id}', |
1060 | ObjectSerializer::toPathValue($request_id), |
1061 | $resourcePath |
1062 | ); |
1063 | } |
1064 | |
1065 | // body params |
1066 | $_tempBody = null; |
1067 | if (isset($body)) { |
1068 | $_tempBody = $body; |
1069 | } |
1070 | |
1071 | // for model (json/xml) |
1072 | if (isset($_tempBody)) { |
1073 | if ($_tempBody instanceof ModelInterface) { |
1074 | $httpBody = (string) $_tempBody; |
1075 | } else { |
1076 | // $_tempBody is the method argument, if present |
1077 | $httpBody = json_encode($_tempBody); |
1078 | } |
1079 | } |
1080 | |
1081 | // this endpoint requires API key authentication |
1082 | $apiKey = $this->config->getApiKeyWithPrefix('Auth-API-Key'); |
1083 | if (null !== $apiKey) { |
1084 | $headers['Auth-API-Key'] = $apiKey; |
1085 | } |
1086 | // this endpoint requires API key authentication |
1087 | $apiKey = $this->config->getApiKeyWithPrefix('api_key'); |
1088 | if (null !== $apiKey) { |
1089 | $queryParams['api_key'] = $apiKey; |
1090 | } |
1091 | |
1092 | $defaultHeaders = [ |
1093 | 'Content-Type' => 'application/json', |
1094 | 'Accept' => 'application/json', |
1095 | ]; |
1096 | if ($this->config->getUserAgent()) { |
1097 | $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); |
1098 | } |
1099 | |
1100 | $headers = array_merge( |
1101 | $defaultHeaders, |
1102 | $headerParams, |
1103 | $headers |
1104 | ); |
1105 | |
1106 | $query = http_build_query($queryParams); |
1107 | |
1108 | return new Request( |
1109 | 'PUT', |
1110 | $this->config->getHost().$resourcePath.($query ? "?{$query}" : ''), |
1111 | $headers, |
1112 | $httpBody |
1113 | ); |
1114 | } |
1115 | |
1116 | /** |
1117 | * Create http client option. |
1118 | * |
1119 | * @throws \RuntimeException on file opening failure |
1120 | */ |
1121 | protected function createHttpClientOption(): array |
1122 | { |
1123 | $options = []; |
1124 | if ($this->config->getDebug()) { |
1125 | $options[RequestOptions::DEBUG] = fopen($this->config->getDebugFile(), 'a'); |
1126 | if (!$options[RequestOptions::DEBUG]) { |
1127 | throw new \RuntimeException('Failed to open the debug file: '.$this->config->getDebugFile()); |
1128 | } |
1129 | } |
1130 | |
1131 | return $options; |
1132 | } |
1133 | } |