From bbed5f913826e994e1c0b352878c4bbd959f5f6b Mon Sep 17 00:00:00 2001 From: Ilya Taratukhin Date: Thu, 31 Oct 2024 18:22:34 +0100 Subject: [PATCH] feat: add checks for deleting visitor data and updating event --- run_checks.php | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/run_checks.php b/run_checks.php index 1bd068b..76103ca 100644 --- a/run_checks.php +++ b/run_checks.php @@ -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; @@ -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; @@ -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); @@ -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;