|
19 | 19 | $dotenv->safeLoad(); |
20 | 20 |
|
21 | 21 | $api_key = $_ENV['FP_PRIVATE_API_KEY'] ?? getenv('FP_PRIVATE_API_KEY') ?? 'Private API Key not defined'; |
22 | | -$visitor_id = $_ENV['FP_VISITOR_ID'] ?? getenv('FP_VISITOR_ID') ?? 'Visitor ID not defined'; |
23 | 22 | $visitor_id_to_delete = $_ENV['FP_VISITOR_ID_TO_DELETE'] ?? getenv('FP_VISITOR_ID_TO_DELETE') ?? false; |
24 | | -$request_id = $_ENV['FP_REQUEST_ID'] ?? getenv('FP_REQUEST_ID') ?? 'Request ID not defined'; |
25 | 23 | $request_id_to_update = $_ENV['FP_REQUEST_ID_TO_UPDATE'] ?? getenv('FP_REQUEST_ID_TO_UPDATE') ?? false; |
26 | 24 | $region_env = $_ENV['FP_REGION'] ?? getenv('FP_REGION') ?? 'us'; |
27 | 25 |
|
|
47 | 45 | // https://github.com/swagger-api/swagger-codegen/issues/11820 |
48 | 46 | error_reporting(error_reporting() & ~E_DEPRECATED); |
49 | 47 |
|
| 48 | +// FingerprintApi->searchEvents usage example |
| 49 | +try { |
| 50 | + // 3 month from now |
| 51 | + $start = (new DateTime())->sub(new DateInterval('P3M')); |
| 52 | + $end = new DateTime(); |
| 53 | + |
| 54 | + /** @var SearchEventsResponse $result */ |
| 55 | + list($result, $response) = $client->searchEvents(10, start: $start->getTimestamp() * 1000, end: $end->getTimestamp() * 1000); |
| 56 | + if (!is_countable($result->getEvents()) || count($result->getEvents()) === 0) { |
| 57 | + throw new Exception('No events found'); |
| 58 | + } |
| 59 | + $identification_data = $result->getEvents()[0]->getProducts()->getIdentification()->getData(); |
| 60 | + $visitor_id = $identification_data->getVisitorId(); |
| 61 | + $request_id = $identification_data->getRequestId(); |
| 62 | + fwrite(STDOUT, sprintf("\n\nGot events: %s \n", $response->getBody()->getContents())); |
| 63 | +} catch (Exception $e) { |
| 64 | + fwrite(STDERR, sprintf("\n\nException when calling FingerprintApi->searchEvents: %s\n", $e->getMessage())); |
| 65 | + |
| 66 | + exit(1); |
| 67 | +} |
| 68 | + |
| 69 | +// FingerprintApi->getVisits usage example |
50 | 70 | try { |
51 | 71 | /** @var VisitorsGetResponse $result */ |
52 | 72 | list($result, $response) = $client->getVisits($visitor_id); |
|
60 | 80 | exit(1); |
61 | 81 | } |
62 | 82 |
|
| 83 | +// FingerprintApi->deleteVisitorData usage example |
63 | 84 | if ($visitor_id_to_delete) { |
64 | 85 | try { |
65 | 86 | list($model, $response) = $client->deleteVisitorData($visitor_id_to_delete); |
|
70 | 91 | } |
71 | 92 | } |
72 | 93 |
|
| 94 | +// FingerprintApi->getEvent usage example |
73 | 95 | try { |
74 | 96 | /** @var EventsGetResponse $result */ |
75 | 97 | list($result, $response) = $client->getEvent($request_id); |
|
83 | 105 | exit(1); |
84 | 106 | } |
85 | 107 |
|
86 | | -try { |
87 | | - // 2 years from now |
88 | | - $start = (new DateTime())->sub(new DateInterval('P2Y')); |
89 | | - $end = new DateTime(); |
90 | | - |
91 | | - /** @var SearchEventsResponse $result */ |
92 | | - list($result, $response) = $client->searchEvents(10, start: $start->getTimestamp() * 1000, end: $end->getTimestamp() * 1000); |
93 | | - if (!is_countable($result->getEvents()) || count($result->getEvents()) === 0) { |
94 | | - throw new Exception('No events found'); |
95 | | - } |
96 | | - fwrite(STDOUT, sprintf("\n\nGot events: %s \n", $response->getBody()->getContents())); |
97 | | -} catch (Exception $e) { |
98 | | - fwrite(STDERR, sprintf("\n\nException when calling FingerprintApi->searchEvents: %s\n", $e->getMessage())); |
99 | | - |
100 | | - exit(1); |
101 | | -} |
102 | | - |
| 108 | +// FingerprintApi->updateEvent usage example |
103 | 109 | if ($request_id_to_update) { |
104 | 110 | try { |
105 | 111 | $body = new EventsUpdateRequest([ |
|
113 | 119 | } |
114 | 120 | } |
115 | 121 |
|
| 122 | +// Call API asynchronously examples |
116 | 123 | $eventPromise = $client->getEventAsync($request_id); |
117 | 124 | $eventPromise->then(function ($tuple) use ($request_id) { |
118 | 125 | list($result, $response) = $tuple; |
|
139 | 146 | exit(1); |
140 | 147 | })->wait(); |
141 | 148 |
|
| 149 | +// Webhook verification example |
142 | 150 | $webhookSecret = 'secret'; |
143 | 151 | $webhookData = 'data'; |
144 | 152 | $webhookHeader = 'v1=1b2c16b75bd2a870c114153ccda5bcfca63314bc722fa160d690de133ccbb9db'; |
|
151 | 159 | exit(1); |
152 | 160 | } |
153 | 161 |
|
| 162 | +// Check that old events still match expected format |
| 163 | +try { |
| 164 | + list($result_old) = $client->searchEvents(1, start: $start->getTimestamp() * 1000, end: $end->getTimestamp() * 1000, reverse: true); |
| 165 | + if (!is_countable($result_old->getEvents()) || count($result_old->getEvents()) === 0) { |
| 166 | + throw new Exception('No old events found'); |
| 167 | + } |
| 168 | + $identification_data_old = $result_old->getEvents()[0]->getProducts()->getIdentification()->getData(); |
| 169 | + $visitor_id_old = $identification_data_old->getVisitorId(); |
| 170 | + $request_id_old = $identification_data_old->getRequestId(); |
| 171 | + |
| 172 | + if ($visitor_id === $visitor_id_old || $request_id === $request_id_old) { |
| 173 | + throw new Exception('Old events are identical to new'); |
| 174 | + } |
| 175 | + |
| 176 | + list($result, $response) = $client->getEvent($request_id_old); |
| 177 | + list($result, $response) = $client->getVisits($visitor_id_old); |
| 178 | + fwrite(STDERR, sprintf("\n\nOld events are good\n")); |
| 179 | +} catch (Exception $e) { |
| 180 | + fwrite(STDERR, sprintf("\n\nException when trying to read old data: %s\n", $e->getMessage())); |
| 181 | +} |
| 182 | + |
154 | 183 | // Enable the deprecated ArrayAccess return type warning again if needed |
155 | 184 | error_reporting(error_reporting() | E_DEPRECATED); |
156 | 185 |
|
|
0 commit comments