Skip to content

Commit fabfa98

Browse files
committed
Merge branch 'feature/TSMD-8502_Python_PhoneID_SDK_change'
2 parents a0affdf + 7f86d38 commit fabfa98

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

telesign/phoneid.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from __future__ import unicode_literals
22

3+
import json
4+
35
from telesign.rest import RestClient
46

57
PHONEID_RESOURCE = "/v1/phoneid/{phone_number}"
@@ -23,3 +25,30 @@ def phoneid(self, phone_number, **params):
2325
"""
2426
return self.post(PHONEID_RESOURCE.format(phone_number=phone_number),
2527
**params)
28+
29+
def _execute(self, method_function, method_name, resource, **params):
30+
resource_uri = "{api_host}{resource}".format(api_host=self.api_host, resource=resource)
31+
32+
json_fields = json.dumps(params)
33+
34+
content_type = "application/json" if method_name in ("POST", "PUT") else ""
35+
36+
headers = self.generate_telesign_headers(self.customer_id,
37+
self.api_key,
38+
method_name,
39+
resource,
40+
json_fields,
41+
user_agent=self.user_agent,
42+
content_type=content_type)
43+
44+
if method_name in ['POST', 'PUT']:
45+
payload = {'data': json_fields}
46+
else:
47+
payload = {'params': json_fields}
48+
49+
response = self.Response(method_function(resource_uri,
50+
headers=headers,
51+
timeout=self.timeout,
52+
**payload))
53+
54+
return response

telesign/rest.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ def generate_telesign_headers(customer_id,
8181
url_encoded_fields,
8282
date_rfc2616=None,
8383
nonce=None,
84-
user_agent=None):
84+
user_agent=None,
85+
content_type=None):
8586
"""
8687
Generates the TeleSign REST API headers used to authenticate requests.
8788
@@ -99,15 +100,17 @@ def generate_telesign_headers(customer_id,
99100
:param date_rfc2616: The date and time of the request formatted in rfc 2616, as a string.
100101
:param nonce: A unique cryptographic nonce for the request, as a string.
101102
:param user_agent: (optional) User Agent associated with the request, as a string.
103+
:param content_type: (optional) ContentType of the request, as a string.
102104
:return: The TeleSign authentication headers.
103105
"""
104106
if date_rfc2616 is None:
105107
date_rfc2616 = formatdate(usegmt=True)
106108

107109
if nonce is None:
108110
nonce = str(uuid.uuid4())
109-
110-
content_type = "application/x-www-form-urlencoded" if method_name in ("POST", "PUT") else ""
111+
112+
if not content_type:
113+
content_type = "application/x-www-form-urlencoded" if method_name in ("POST", "PUT") else ""
111114

112115
auth_method = "HMAC-SHA256"
113116

0 commit comments

Comments
 (0)