Skip to content

Commit

Permalink
feat: add delete visitor data endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Orkuncakilkaya committed Aug 27, 2024
1 parent 137c80a commit 4df48c7
Show file tree
Hide file tree
Showing 4 changed files with 355 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
62 changes: 62 additions & 0 deletions docs/Api/FingerprintApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
<?php

require_once(__DIR__ . '/vendor/autoload.php');

const FPJS_API_SECRET = "Your Fingerprint Secret API Key"; // Fingerprint Secret API Key

// Import Fingerprint Classes and Guzzle HTTP Client
use Fingerprint\ServerAPI\Api\FingerprintApi;
use Fingerprint\ServerAPI\Configuration;
use GuzzleHttp\Client;

// Create new Configuration instance with defaultValues, added our API Secret and our Region
$config = Configuration::getDefaultConfiguration(FPJS_API_SECRET, Configuration::REGION_EUROPE);
$client = new FingerprintApi(
new Client(),
$config
);

$visitor_id = "visitor_id_example"; // string | The [visitor ID](https://dev.fingerprint.com/docs/js-agent#visitorid) you want to delete.

try {
$client->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)
Expand Down
63 changes: 63 additions & 0 deletions res/fingerprint-server-api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
229 changes: 229 additions & 0 deletions src/Api/FingerprintApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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'.
*
Expand Down

0 comments on commit 4df48c7

Please sign in to comment.