Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions RELEASE
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
2.2.3
- Adding support for KES Client

2.2.2
- Added support for application/json content-type

Expand Down
28 changes: 28 additions & 0 deletions examples/kes/1_send_kes_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from __future__ import print_function
from telesign.kes import KESClient

customer_id = "FFFFFFFF-EEEE-DDDD-1234-AB1234567890"
api_key = "EXAMPLE----TE8sTgg45yusumoN6BYsBVkh+yRJ5czgsnCehZaOYldPJdmFh6NeX8kunZ2zU1YWaUw/0wV6xfw=="

kes_payload = {
"event_type": "completion",
"event_data": {
"score_transaction_id": 1234,
"account_lifecycle_event": "create",
"industry_type": "fishing",
"transaction_type": "payment",
"label": "fraudulent",
"label_timestamp": "2021-07-01 12:23:23",
"fraud_type": "Abuse",
"transaction_cost": "$.12",
"device_id": "xx",
"account_id": "yy",
"call_completed": True,
}
}

data = KESClient(customer_id, api_key)
response = data.kes(**kes_payload)

if response.ok:
print("Known Event Data request accepted by Telesign")
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

here = path.abspath(path.dirname(__file__))

version = "2.2.2"
version = "2.2.3"

with open(path.join(here, 'README.rst'), encoding='utf-8') as f:
long_description = f.read()
Expand All @@ -36,7 +36,7 @@
"Programming Language :: Python :: 3.6",
],
long_description=long_description,
keywords='telesign, sms, voice, mobile, authentication, identity, messaging',
keywords='telesign, sms, voice, mobile, authentication, identity, messaging, kes',
author='TeleSign Corp.',
author_email='support@telesign.com',
url="https://github.com/telesign/python_telesign",
Expand Down
47 changes: 47 additions & 0 deletions telesign/kes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
from __future__ import unicode_literals
from json import dumps

from telesign.rest import RestClient

KES_HOST = "https://data.telesign.com"
KES_RESOURCE = "/kes"


class KESClient(RestClient):
"""
KES or Known Event Share consumes customer events for data product quality improvement.
"""

def __init__(self, customer_id, api_key, **kwargs):
super(KESClient, self).__init__(customer_id=customer_id,
api_key=api_key,
rest_endpoint=KES_HOST,
**kwargs)

def _execute(self, method_function, method_name, resource, **params):
resource_uri = "{api_host}{resource}".format(api_host=self.api_host, resource=resource)
json_fields = dumps(params)
headers = RestClient.generate_telesign_headers(self.customer_id,
self.api_key,
method_name,
resource,
json_fields,
user_agent=self.user_agent,
content_type='application/json')
payload = {'data': ""}
if method_name in ['POST', 'PUT']:
payload['data'] = json_fields

response = self.Response(method_function(resource_uri,
headers=headers,
timeout=self.timeout,
**payload))
return response

def kes(self, **params):
"""
KES is an API that consumes known event type data

See https://enterprise-beta.telesign.com/api-reference/apis/known-events-share-api for Beta API documentation.
"""
return self.post(resource=KES_RESOURCE, **params)