Skip to content

Commit a11ebb0

Browse files
authored
Merge pull request #5 from Target365/refactoring-1
making code python2 compatiable.
2 parents 6bf06ab + 2e93742 commit a11ebb0

File tree

12 files changed

+52
-38
lines changed

12 files changed

+52
-38
lines changed

target365_sdk/api_client.py

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def loopup(self, msisdn):
6868

6969
### Keyword controller ###
7070

71-
def create_keyword(self, keyword) -> str:
71+
def create_keyword(self, keyword):
7272
"""
7373
POST /api/keywords
7474
Creates a new keyword.
@@ -82,7 +82,7 @@ def create_keyword(self, keyword) -> str:
8282

8383
return self._get_id_from_header(response.headers)
8484

85-
def get_all_keywords(self, short_number_id=None, keyword=None, mode=None, tag=None) -> list:
85+
def get_all_keywords(self, short_number_id=None, keyword=None, mode=None, tag=None):
8686
"""
8787
GET /api/keywords
8888
Gets all keywords.
@@ -102,7 +102,7 @@ def get_all_keywords(self, short_number_id=None, keyword=None, mode=None, tag=No
102102
response.raise_for_status()
103103
return Keyword.from_list(response.json())
104104

105-
def get_keyword(self, keyword_id: str) -> Keyword:
105+
def get_keyword(self, keyword_id):
106106
"""
107107
GET /api/keywords/{keywordId}
108108
Gets a keyword.
@@ -120,11 +120,12 @@ def get_keyword(self, keyword_id: str) -> Keyword:
120120

121121
return Keyword(**response.json())
122122

123-
def update_keyword(self, keyword: Keyword):
123+
def update_keyword(self, keyword):
124124
"""
125125
PUT /api/keywords/{keywordId}
126126
Updates a keyword
127-
:keyword: Keyword to update
127+
:param keyword: Keyword
128+
:return:
128129
"""
129130
if keyword is None:
130131
raise ValueError("keyword")
@@ -136,7 +137,7 @@ def update_keyword(self, keyword: Keyword):
136137

137138
response.raise_for_status()
138139

139-
def delete_keyword(self, keyword_id: str):
140+
def delete_keyword(self, keyword_id):
140141
"""
141142
DELETE /api/keywords/{keywordId}
142143
Deletes a keyword
@@ -150,7 +151,7 @@ def delete_keyword(self, keyword_id: str):
150151

151152
### OutMessage controller ###
152153

153-
def prepare_msisdns(self, msisdns: str):
154+
def prepare_msisdns(self, msisdns):
154155
"""
155156
POST /api/prepare-msisdns
156157
MSISDNs to prepare as a string array
@@ -161,7 +162,7 @@ def prepare_msisdns(self, msisdns: str):
161162
response = self.client.post(self.PREPARE_MSISDNS, msisdns)
162163
response.raise_for_status()
163164

164-
def create_out_message(self, out_message: OutMessage):
165+
def create_out_message(self, out_message):
165166
"""
166167
POST /api/out-messages
167168
Creates a new out-message
@@ -175,7 +176,7 @@ def create_out_message(self, out_message: OutMessage):
175176

176177
return self._get_id_from_header(response.headers)
177178

178-
def create_out_message_batch(self, out_messages: list):
179+
def create_out_message_batch(self, out_messages):
179180
"""
180181
POST /api/out-messages/batch
181182
Creates a new out-message batch.
@@ -187,7 +188,7 @@ def create_out_message_batch(self, out_messages: list):
187188
response = self.client.post(self.OUT_MESSAGES + "/batch", out_messages)
188189
response.raise_for_status()
189190

190-
def get_out_message(self, transaction_id: str) -> OutMessage:
191+
def get_out_message(self, transaction_id):
191192
"""
192193
GET /api/out-messages/batch/{transactionId}
193194
Gets and out-message
@@ -205,7 +206,7 @@ def get_out_message(self, transaction_id: str) -> OutMessage:
205206

206207
return OutMessage(**response.json())
207208

208-
def update_out_message(self, out_message: OutMessage):
209+
def update_out_message(self, out_message):
209210
"""
210211
PUT /api/out-messages/batch/{transactionId}
211212
Updates a future scheduled out-message.
@@ -220,7 +221,7 @@ def update_out_message(self, out_message: OutMessage):
220221
self.OUT_MESSAGES + "/" + out_message.transactionId, out_message)
221222
response.raise_for_status()
222223

223-
def delete_out_message(self, transaction_id: str):
224+
def delete_out_message(self, transaction_id):
224225
"""
225226
DELETE /api/out-messages/batch/{transactionId}
226227
Deletes a future sheduled out-message.
@@ -234,7 +235,7 @@ def delete_out_message(self, transaction_id: str):
234235

235236
### InMessages controller ###
236237

237-
def get_in_message(self, short_number_id, transaction_id) -> InMessage:
238+
def get_in_message(self, short_number_id, transaction_id):
238239
"""
239240
GET /api/in-messages/{shortNumberId}/{transactionId}
240241
Gets and in-message
@@ -253,7 +254,7 @@ def get_in_message(self, short_number_id, transaction_id) -> InMessage:
253254

254255
### StrexMerchants controller ###
255256

256-
def get_strex_merchants(self) -> list:
257+
def get_strex_merchants(self):
257258
"""
258259
GET /api/strex/merchants
259260
Gets all merchant ids.
@@ -263,7 +264,7 @@ def get_strex_merchants(self) -> list:
263264
response.raise_for_status()
264265
return StrexMerchant.from_list(response.json())
265266

266-
def get_strex_merchant(self, merchant_id: str) -> StrexMerchant:
267+
def get_strex_merchant(self, merchant_id):
267268
"""
268269
GET /api/strex/merchants/{merchantId}
269270
Gets a merchant.
@@ -282,7 +283,7 @@ def get_strex_merchant(self, merchant_id: str) -> StrexMerchant:
282283

283284
return StrexMerchant(**response.json())
284285

285-
def save_strex_merchant(self, strex_merchant: StrexMerchant):
286+
def save_strex_merchant(self, strex_merchant):
286287
"""
287288
PUT /api/strex/merchants/{merchantId}
288289
Creates/updates a merchant.
@@ -309,7 +310,7 @@ def delete_strex_merchant(self, merchant_id):
309310
response = self.client.delete(self.STREX_MERCHANTS + "/" + merchant_id)
310311
response.raise_for_status()
311312

312-
def create_one_time_password(self, one_time_password: OneTimePassword):
313+
def create_one_time_password(self, one_time_password):
313314
"""
314315
POST /api/strex/one-time-passwords
315316
:return:
@@ -331,7 +332,7 @@ def create_one_time_password(self, one_time_password: OneTimePassword):
331332
response = self.client.post(self.STREX_ONE_TIME_PASSWORDS, one_time_password)
332333
response.raise_for_status()
333334

334-
def get_one_time_password(self, transaction_id) -> OneTimePassword:
335+
def get_one_time_password(self, transaction_id):
335336
"""
336337
GET /api/strex/one-time-passwords/{transactionId}
337338
@@ -345,7 +346,7 @@ def get_one_time_password(self, transaction_id) -> OneTimePassword:
345346

346347
return OneTimePassword(**response.json())
347348

348-
def create_strex_transaction(self, transaction: StrexTransaction) -> str:
349+
def create_strex_transaction(self, transaction):
349350
"""
350351
POST /api/strex/transactions
351352
:return str:
@@ -356,7 +357,7 @@ def create_strex_transaction(self, transaction: StrexTransaction) -> str:
356357

357358
return self._get_id_from_header(response.headers)
358359

359-
def get_strex_transaction(self, transaction_id: str) -> StrexTransaction:
360+
def get_strex_transaction(self, transaction_id):
360361
"""
361362
GET /api/strex/transactions/{transactionId}
362363
:return:
@@ -367,7 +368,7 @@ def get_strex_transaction(self, transaction_id: str) -> StrexTransaction:
367368

368369
return StrexTransaction(**response.json())
369370

370-
def delete_strex_transaction(self, transaction_id: str):
371+
def delete_strex_transaction(self, transaction_id):
371372
"""
372373
DELETE /api/strex/transactions/{transactionId}
373374
:param transaction_id:
@@ -379,7 +380,7 @@ def delete_strex_transaction(self, transaction_id: str):
379380

380381
### PublicKey controller ###
381382

382-
def get_server_public_key(self, key_name: str) -> PublicKey:
383+
def get_server_public_key(self, key_name):
383384
"""
384385
GET /api/server/public-keys/{key_name}
385386
:param key_name:
@@ -400,7 +401,7 @@ def get_client_public_keys(self):
400401

401402
return PublicKey.from_list(response.json())
402403

403-
def get_client_public_key(self, key_name: str) -> PublicKey:
404+
def get_client_public_key(self, key_name):
404405
"""
405406
GET /api/client/public-keys/{key_name}
406407
:return: Dict
@@ -410,7 +411,7 @@ def get_client_public_key(self, key_name: str) -> PublicKey:
410411

411412
return PublicKey(**response.json())
412413

413-
def delete_client_public_key(self, key_name: str):
414+
def delete_client_public_key(self, key_name):
414415
"""
415416
DELETE /api/client/public-keys/{key_name}
416417
:return:

target365_sdk/helpers/http_client.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,14 @@
55
import uuid
66
import base64
77
import hashlib
8-
import urllib
98
import jsonpickle
109

10+
try:
11+
#python2
12+
from urllib import urlencode
13+
except ImportError:
14+
#python3
15+
from urllib.parse import urlencode
1116

1217
class HttpClient:
1318
def __init__(self, base_uri, key_name, private_key):
@@ -21,11 +26,12 @@ def get(self, path):
2126
return requests.get(self._build_url(path), headers=self._get_auth_header("get", self._build_url(path)))
2227

2328
def get_with_params(self, path, query_params):
29+
2430
url = self._build_url(path)
2531
if len(query_params.keys()) > 0:
2632
url += "?"
2733

28-
absolute_uri = (url + urllib.parse.urlencode(query_params)).lower()
34+
absolute_uri = (url + urlencode(query_params)).lower()
2935
return requests.get(
3036
self._build_url(path),
3137
params=query_params,

target365_sdk/models/in_message.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
class InMessage(Model):
44

55

6-
def _accepted_params(self) -> list:
6+
def _accepted_params(self):
77

88
return [
99
'messageId',

target365_sdk/models/keyword.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
class Keyword(Model):
44

5-
def _accepted_params(self) -> list:
5+
def _accepted_params(self):
66
return [
77
'keywordId',
88
'shortNumberId',

target365_sdk/models/lookup_result.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
class LookupResult(Model):
44

5-
def _accepted_params(self) -> list:
5+
def _accepted_params(self):
66
return [
77
'created',
88
'msisdn',

target365_sdk/models/model.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
from abc import ABC, abstractmethod
1+
from abc import ABCMeta, abstractmethod
22

33
class Model:
4+
__metaclass__ = ABCMeta
45

56
def __init__(self, **kwargs):
67
for key, value in kwargs.items():
@@ -16,9 +17,10 @@ def _accepted_params(self):
1617

1718

1819
@classmethod
19-
def from_list(cls, items: list) -> list:
20+
def from_list(cls, items):
2021
"""
21-
:param list of dictionaries:
22-
:return list of models:
22+
:param items:
23+
:type items: list
24+
:return: list
2325
"""
2426
return [cls(**item) for item in items]

target365_sdk/models/one_time_password.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
class OneTimePassword(Model):
44

5-
def _accepted_params(self) -> list:
5+
def _accepted_params(self):
66
return [
77
'transactionId',
88
'merchantId',

target365_sdk/models/out_message.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
class OutMessage(Model):
44

55

6-
def _accepted_params(self) -> list:
6+
def _accepted_params(self):
77
return [
88
'id',
99
'accountId',

target365_sdk/models/public_key.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
class PublicKey(Model):
44

5-
def _accepted_params(self) -> list:
5+
def _accepted_params(self):
66
return [
77
'accountId',
88
'name',

target365_sdk/models/strex_merchant.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
class StrexMerchant(Model):
44

5-
def _accepted_params(self) -> list:
5+
def _accepted_params(self):
66
return [
77
'merchantId',
88
'shortNumberId',

0 commit comments

Comments
 (0)