Skip to content

Commit b467787

Browse files
authored
Merge pull request #63 from fingerprintjs/async-methods-examples
Improve async response typing, add example for async response
2 parents 0723f0d + ac9e6f1 commit b467787

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

fingerprint_pro_server_api_sdk/api/fingerprint_api.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
import re # noqa: F401
1414
from multiprocessing import Pool
15-
from threading import Thread
15+
from multiprocessing.pool import ApplyResult as AsyncResult
1616
from typing import Optional, Union
1717

1818
from fingerprint_pro_server_api_sdk.configuration import Configuration
@@ -45,7 +45,7 @@ def __init__(self, configuration: Optional[Configuration] = None, pool: Optional
4545
raise ValueError("Missing the required parameter `configuration` when calling `FingerprintApi`") # noqa: E501
4646
self.api_client = ApiClient(configuration, pool=pool)
4747

48-
def delete_visitor_data(self, visitor_id: str, **kwargs) -> Union[None, Thread]: # noqa: E501
48+
def delete_visitor_data(self, visitor_id: str, **kwargs) -> Union[None, AsyncResult[None]]: # noqa: E501
4949
"""Delete data by visitor ID # noqa: E501
5050
5151
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. # noqa: E501
@@ -155,7 +155,7 @@ def delete_visitor_data_with_http_info(self, visitor_id: str, **kwargs): # noqa
155155
raise extend_exception(e, error)
156156
raise e
157157

158-
def get_event(self, request_id: str, **kwargs) -> Union[EventResponse, Thread]: # noqa: E501
158+
def get_event(self, request_id: str, **kwargs) -> Union[EventResponse, AsyncResult[EventResponse]]: # noqa: E501
159159
"""Get event by request ID # noqa: E501
160160
161161
Get a detailed analysis of an individual identification event, including Smart Signals. Please note that the response includes mobile signals (e.g. `rootApps`) even if the request originated from a non-mobile platform. It is highly recommended that you **ignore** the mobile signals for such requests. Use `requestId` as the URL path parameter. This API method is scoped to a request, i.e. all returned information is by `requestId`. # noqa: E501
@@ -259,7 +259,7 @@ def get_event_with_http_info(self, request_id: str, **kwargs): # noqa: E501
259259
raise extend_exception(e, error)
260260
raise e
261261

262-
def get_visits(self, visitor_id: str, **kwargs) -> Union[Response, Thread]: # noqa: E501
262+
def get_visits(self, visitor_id: str, **kwargs) -> Union[Response, AsyncResult[Response]]: # noqa: E501
263263
"""Get visits by visitor ID # noqa: E501
264264
265265
Get a history of visits (identification events) for a specific `visitorId`. Use the `visitorId` as a URL path parameter. Only information from the _Identification_ product is returned. #### Headers * `Retry-After` — Present in case of `429 Too many requests`. Indicates how long you should wait before making a follow-up request. The value is non-negative decimal integer indicating the seconds to delay after the response is received. # noqa: E501
@@ -388,7 +388,7 @@ def get_visits_with_http_info(self, visitor_id: str, **kwargs): # noqa: E501
388388
raise extend_exception(e, error)
389389
raise e
390390

391-
def update_event(self, body: EventUpdateRequest, request_id: str, **kwargs) -> Union[None, Thread]: # noqa: E501
391+
def update_event(self, body: EventUpdateRequest, request_id: str, **kwargs) -> Union[None, AsyncResult[None]]: # noqa: E501
392392
"""Update an event with a given request ID # noqa: E501
393393
394394
Change information in existing events specified by `requestId` or *flag suspicious events*. When an event is created, it is assigned `linkedId` and `tag` submitted through the JS agent parameters. This information might not be available on the client so the Server API allows for updating the attributes after the fact. **Warning** It's not possible to update events older than 10 days. # noqa: E501

run_checks.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,18 @@
3636
print("Exception when calling DefaultApi->get_event: %s\n" % e)
3737
exit(1)
3838

39+
# Async methods examples
40+
try:
41+
visits_response_request = api_instance.get_visits(visitor_id, limit=2, async_req=True)
42+
events_response_request = api_instance.get_event(request_id, async_req=True)
43+
visits_response = visits_response_request.get()
44+
print("\n\n\nVisits async response: \n", visits_response)
45+
events_response = events_response_request.get()
46+
print("\n\n\nEvent async response: \n", events_response.products)
47+
except ApiException as e:
48+
print("Exception when calling Async example: %s\n" % e)
49+
exit(1)
50+
3951
print("Checks passed!")
4052

4153
exit(0)

template/api.mustache

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import re # noqa: F401
66
from multiprocessing import Pool
7-
from threading import Thread
7+
from multiprocessing.pool import ApplyResult as AsyncResult
88
from typing import Optional, Union
99

1010
from {{packageName}}.configuration import Configuration
@@ -30,7 +30,7 @@ class {{classname}}:
3030
self.api_client = ApiClient(configuration, pool=pool)
3131
{{#operation}}
3232

33-
def {{operationId}}(self, {{#sortParamsByRequiredFlag}}{{#allParams}}{{#required}}{{paramName}}: {{dataType}}, {{/required}}{{/allParams}}{{/sortParamsByRequiredFlag}}**kwargs) -> Union[{{#returnType}}{{returnType}}{{/returnType}}{{^returnType}}None{{/returnType}}, Thread]: # noqa: E501
33+
def {{operationId}}(self, {{#sortParamsByRequiredFlag}}{{#allParams}}{{#required}}{{paramName}}: {{dataType}}, {{/required}}{{/allParams}}{{/sortParamsByRequiredFlag}}**kwargs) -> Union[{{#returnType}}{{returnType}}{{/returnType}}{{^returnType}}None{{/returnType}}, AsyncResult[{{#returnType}}{{returnType}}{{/returnType}}{{^returnType}}None{{/returnType}}]]: # noqa: E501
3434
"""{{#summary}}{{{.}}}{{/summary}}{{^summary}}{{operationId}}{{/summary}} # noqa: E501
3535

3636
{{#notes}}

0 commit comments

Comments
 (0)