From 4df48c7c2170042ca1de47e595f74152d4b1adc1 Mon Sep 17 00:00:00 2001 From: Orkun Date: Tue, 27 Aug 2024 02:33:32 +0300 Subject: [PATCH] feat: add delete visitor data endpoint --- README.md | 1 + docs/Api/FingerprintApi.md | 62 +++++++++ res/fingerprint-server-api.yaml | 63 +++++++++ src/Api/FingerprintApi.php | 229 ++++++++++++++++++++++++++++++++ 4 files changed, 355 insertions(+) diff --git a/README.md b/README.md index 8008cc0a..812daa4b 100644 --- a/README.md +++ b/README.md @@ -233,6 +233,7 @@ if(!$isValidWebhookSign) { Class | Method | HTTP request | Description ------------ | ------------- | ------------- | ------------- +*FingerprintApi* | [**deleteVisitorData**](docs/Api/FingerprintApi.md#deletevisitordata) | **DELETE** /visitors/{visitor_id} | Delete data by visitor ID *FingerprintApi* | [**getEvent**](docs/Api/FingerprintApi.md#getevent) | **GET** /events/{request_id} | Get event by request ID *FingerprintApi* | [**getVisits**](docs/Api/FingerprintApi.md#getvisits) | **GET** /visitors/{visitor_id} | Get visits by visitor ID *FingerprintApi* | [**updateEvent**](docs/Api/FingerprintApi.md#updateevent) | **PUT** /events/{request_id} | Update an event with a given request ID diff --git a/docs/Api/FingerprintApi.md b/docs/Api/FingerprintApi.md index e7cfc5e5..7f367e17 100644 --- a/docs/Api/FingerprintApi.md +++ b/docs/Api/FingerprintApi.md @@ -4,10 +4,72 @@ All URIs are relative to *https://api.fpjs.io* Method | HTTP request | Description ------------- | ------------- | ------------- +[**deleteVisitorData**](FingerprintApi.md#deleteVisitorData) | **DELETE** /visitors/{visitor_id} | Delete data by visitor ID [**getEvent**](FingerprintApi.md#getEvent) | **GET** /events/{request_id} | Get event by request ID [**getVisits**](FingerprintApi.md#getVisits) | **GET** /visitors/{visitor_id} | Get visits by visitor ID [**updateEvent**](FingerprintApi.md#updateEvent) | **PUT** /events/{request_id} | Update an event with a given request ID +# **deleteVisitorData** +> deleteVisitorData($visitor_id) + +Delete data by visitor ID + +Request deleting all data associated with the specified visitor ID. This API is useful for compliance with privacy regulations. All delete requests are queued: * Recent data (10 days or newer) belonging to the specified visitor will be deleted within 24 hours. * Data from older (11 days or more) identification events will be deleted after 90 days. If you are interested in using this API, please [contact our support team](https://fingerprint.com/support/) to enable it for you. Otherwise, you will receive a 403. + +### Example +```php +deleteVisitorData($visitor_id); +} catch (Exception $e) { + echo 'Exception when calling FingerprintApi->deleteVisitorData: ', $e->getMessage(), PHP_EOL; +} +?> +``` + +### Parameters + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + **visitor_id** | **string**| The [visitor ID](https://dev.fingerprint.com/docs/js-agent#visitorid) you want to delete. | + +### Return type + +Array: +0. null, +1. \Psr\Http\Message\ResponseInterface + + +### Authorization + +[ApiKeyHeader](../../README.md#ApiKeyHeader), [ApiKeyQuery](../../README.md#ApiKeyQuery) + +### HTTP request headers + +- **Content-Type**: Not defined +- **Accept**: application/json + +[[Back to top]](#) [[Back to API list]](../../README.md#documentation-for-api-endpoints) [[Back to Model list]](../../README.md#documentation-for-models) [[Back to README]](../../README.md) + # **getEvent** > [ \Fingerprint\ServerAPI\Model\EventResponse, \Psr\Http\Message\ResponseInterface ] getEvent($request_id) diff --git a/res/fingerprint-server-api.yaml b/res/fingerprint-server-api.yaml index 65b6f346..f6e6d701 100644 --- a/res/fingerprint-server-api.yaml +++ b/res/fingerprint-server-api.yaml @@ -281,6 +281,69 @@ paths: application/json: schema: $ref: '#/components/schemas/TooManyRequestsResponse' + delete: + tags: + - Fingerprint + operationId: deleteVisitorData + summary: Delete data by visitor ID + description: > + Request deleting all data associated with the specified visitor ID. This + API is useful for compliance with privacy regulations. + + All delete requests are queued: + + + * Recent data (10 days or newer) belonging to the specified visitor will + be deleted within 24 hours. + + * Data from older (11 days or more) identification events will be + deleted after 90 days. + + + If you are interested in using this API, please [contact our support + team](https://fingerprint.com/support/) to enable it for you. Otherwise, + you will receive a 403. + parameters: + - name: visitor_id + in: path + description: >- + The [visitor + ID](https://dev.fingerprint.com/docs/js-agent#visitorid) you want to + delete. + required: true + schema: + type: string + responses: + '200': + description: OK. The visitor ID is scheduled for deletion. + '400': + description: >- + Bad request. The visitor ID parameter is missing or in the wrong + format. + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorVisitor400Response' + '403': + description: Forbidden. Access to this API is denied. + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorCommon403Response' + '404': + description: >- + Not found. The visitor ID cannot be found in this application's + data. + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorVisitor404Response' + '429': + description: Too Many Requests. The request is throttled. + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorCommon429Response' /webhook: trace: tags: diff --git a/src/Api/FingerprintApi.php b/src/Api/FingerprintApi.php index 97c60e1f..8c055290 100644 --- a/src/Api/FingerprintApi.php +++ b/src/Api/FingerprintApi.php @@ -71,6 +71,170 @@ public function getConfig(): Configuration return $this->config; } + /** + * Operation deleteVisitorData. + * + * Delete data by visitor ID + * + * @param string $visitor_id The [visitor ID](https://dev.fingerprint.com/docs/js-agent#visitorid) you want to delete. (required) + * + * @return array{ null, \Psr\Http\Message\ResponseInterface } + * + * @throws \InvalidArgumentException + * @throws SerializationException + * @throws GuzzleException + */ + public function deleteVisitorData(string $visitor_id): array + { + $returnType = ''; + $request = $this->deleteVisitorDataRequest($visitor_id); + + try { + $options = $this->createHttpClientOption(); + + try { + $response = $this->client->send($request, $options); + } catch (RequestException $e) { + $apiException = new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + $e->getCode() + ); + $apiException->setResponseObject($e->getResponse()); + + throw $apiException; + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + $apiException = new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + $request->getUri() + ), + $statusCode + ); + $apiException->setResponseObject($response); + + throw $apiException; + } + + return [null, $response]; + } catch (ApiException $e) { + /** @var ResponseInterface $response */ + $response = $e->getResponseObject(); + + switch ($e->getCode()) { + case 400: + $errorDetail = ObjectSerializer::deserialize($response, '\Fingerprint\ServerAPI\Model\ErrorVisitor400Response'); + $e->setErrorDetails($errorDetail); + $e->setResponseObject($response); + + break; + + case 403: + $errorDetail = ObjectSerializer::deserialize($response, '\Fingerprint\ServerAPI\Model\ErrorCommon403Response'); + $e->setErrorDetails($errorDetail); + $e->setResponseObject($response); + + break; + + case 404: + $errorDetail = ObjectSerializer::deserialize($response, '\Fingerprint\ServerAPI\Model\ErrorVisitor404Response'); + $e->setErrorDetails($errorDetail); + $e->setResponseObject($response); + + break; + + case 429: + $errorDetail = ObjectSerializer::deserialize($response, '\Fingerprint\ServerAPI\Model\ErrorCommon429Response'); + $e->setErrorDetails($errorDetail); + $e->setResponseObject($response); + + break; + } + + throw $e; + } + } + + /** + * Operation deleteVisitorDataAsync. + * + * Delete data by visitor ID + * + * @param string $visitor_id The [visitor ID](https://dev.fingerprint.com/docs/js-agent#visitorid) you want to delete. (required) + * + * @throws \InvalidArgumentException + * @throws SerializationException + */ + public function deleteVisitorDataAsync(string $visitor_id): PromiseInterface + { + $returnType = ''; + $request = $this->deleteVisitorDataRequest($visitor_id); + + return $this->client + ->sendAsync($request, $this->createHttpClientOption()) + ->then( + function ($response) use ($request) { + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + $apiException = new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + $request->getUri() + ), + $statusCode + ); + $apiException->setResponseObject($response); + + throw $apiException; + } + + return [null, $response]; + }, + function ($e) { + /** @var ResponseInterface $response */ + $response = $e->getResponseObject(); + + switch ($e->getCode()) { + case 400: + $errorDetail = ObjectSerializer::deserialize($response, '\Fingerprint\ServerAPI\Model\ErrorVisitor400Response'); + $e->setErrorDetails($errorDetail); + $e->setResponseObject($response); + + break; + + case 403: + $errorDetail = ObjectSerializer::deserialize($response, '\Fingerprint\ServerAPI\Model\ErrorCommon403Response'); + $e->setErrorDetails($errorDetail); + $e->setResponseObject($response); + + break; + + case 404: + $errorDetail = ObjectSerializer::deserialize($response, '\Fingerprint\ServerAPI\Model\ErrorVisitor404Response'); + $e->setErrorDetails($errorDetail); + $e->setResponseObject($response); + + break; + + case 429: + $errorDetail = ObjectSerializer::deserialize($response, '\Fingerprint\ServerAPI\Model\ErrorCommon429Response'); + $e->setErrorDetails($errorDetail); + $e->setResponseObject($response); + + break; + } + + throw $e; + } + ); + } + /** * Operation getEvent. * @@ -555,6 +719,71 @@ function ($e) { ); } + /** + * Create request for operation 'deleteVisitorData'. + * + * @throws \InvalidArgumentException + * @throws SerializationException + */ + protected function deleteVisitorDataRequest(string $visitor_id): Request + { + // verify the required parameter 'visitor_id' is set + if (null === $visitor_id || (is_array($visitor_id) && 0 === count($visitor_id))) { + throw new \InvalidArgumentException( + 'Missing the required parameter $visitor_id when calling deleteVisitorData' + ); + } + + $resourcePath = '/visitors/{visitor_id}'; + $headers = []; + $queryParams = ['ii' => $this->integration_info]; + $headerParams = []; + $httpBody = ''; + + // path params + if (null !== $visitor_id) { + $resourcePath = str_replace( + '{visitor_id}', + ObjectSerializer::toPathValue($visitor_id), + $resourcePath + ); + } + + // this endpoint requires API key authentication + $apiKey = $this->config->getApiKeyWithPrefix('Auth-API-Key'); + if (null !== $apiKey) { + $headers['Auth-API-Key'] = $apiKey; + } + // this endpoint requires API key authentication + $apiKey = $this->config->getApiKeyWithPrefix('api_key'); + if (null !== $apiKey) { + $queryParams['api_key'] = $apiKey; + } + + $defaultHeaders = [ + 'Content-Type' => 'application/json', + 'Accept' => 'application/json', + ]; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); + } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + $query = http_build_query($queryParams); + + return new Request( + 'DELETE', + $this->config->getHost().$resourcePath.($query ? "?{$query}" : ''), + $headers, + $httpBody + ); + } + /** * Create request for operation 'getEvent'. *