Skip to content

Commit

Permalink
feat: add checks for deleting visitor data and updating event
Browse files Browse the repository at this point in the history
  • Loading branch information
ilfa committed Oct 31, 2024
1 parent 12760be commit bbed5f9
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions run_checks.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Fingerprint\ServerAPI\Api\FingerprintApi;
use Fingerprint\ServerAPI\Configuration;
use Fingerprint\ServerAPI\Model\EventsGetResponse;
use Fingerprint\ServerAPI\Model\EventsUpdateRequest;
use Fingerprint\ServerAPI\Model\VisitorsGetResponse;
use Fingerprint\ServerAPI\Webhook\WebhookVerifier;
use GuzzleHttp\Client;
Expand All @@ -18,7 +19,9 @@

$api_key = $_ENV['FP_PRIVATE_API_KEY'] ?? getenv('FP_PRIVATE_API_KEY') ?? 'Private API Key not defined';
$visitor_id = $_ENV['FP_VISITOR_ID'] ?? getenv('FP_VISITOR_ID') ?? 'Visitor ID not defined';
$visitor_id_to_delete = $_ENV['FP_VISITOR_ID_TO_DELETE'] ?? getenv('FP_VISITOR_ID_TO_DELETE') ?? false;
$request_id = $_ENV['FP_REQUEST_ID'] ?? getenv('FP_REQUEST_ID') ?? 'Request ID not defined';
$request_id_to_update = $_ENV['FP_REQUEST_ID_TO_UPDATE'] ?? getenv('FP_REQUEST_ID_TO_UPDATE') ?? false;
$region_env = $_ENV['FP_REGION'] ?? getenv('FP_REGION') ?? 'us';

$region = Configuration::REGION_GLOBAL;
Expand Down Expand Up @@ -56,6 +59,16 @@
exit(1);
}

if ($visitor_id_to_delete) {
try {
list($model, $response) = $client->deleteVisitorData($visitor_id_to_delete);
fwrite(STDOUT, sprintf("Visitor data deleted: %s \n", $response->getBody()->getContents()));
} catch (Exception $e) {
fwrite(STDERR, sprintf("Exception when calling FingerprintApi->deleteVisitorData: %s\n", $e->getMessage()));
exit(1);
}
}

try {
/** @var EventsGetResponse $result */
list($result, $response) = $client->getEvent($request_id);
Expand All @@ -69,6 +82,19 @@
exit(1);
}

if ($request_id_to_update) {
try {
$body = new EventsUpdateRequest([
'linked_id' => date('Y-m-d H:i:s'),
]);
list($model, $response) = $client->updateEvent($body, $request_id_to_update);
fwrite(STDOUT, sprintf("\n\nEvent updated: %s \n", $response->getBody()->getContents()));
} catch (Exception $e) {
fwrite("\n\nException when calling FingerprintApi->updateEvent: %s\n", $e->getMessage());
exit(1);
}
}

$eventPromise = $client->getEventAsync($request_id);
$eventPromise->then(function ($tuple) use ($request_id) {
list($result, $response) = $tuple;
Expand Down

0 comments on commit bbed5f9

Please sign in to comment.