Skip to content
Merged
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
49 changes: 25 additions & 24 deletions target365_sdk/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def loopup(self, msisdn):

### Keyword controller ###

def create_keyword(self, keyword) -> str:
def create_keyword(self, keyword):
"""
POST /api/keywords
Creates a new keyword.
Expand All @@ -82,7 +82,7 @@ def create_keyword(self, keyword) -> str:

return self._get_id_from_header(response.headers)

def get_all_keywords(self, short_number_id=None, keyword=None, mode=None, tag=None) -> list:
def get_all_keywords(self, short_number_id=None, keyword=None, mode=None, tag=None):
"""
GET /api/keywords
Gets all keywords.
Expand All @@ -102,7 +102,7 @@ def get_all_keywords(self, short_number_id=None, keyword=None, mode=None, tag=No
response.raise_for_status()
return Keyword.from_list(response.json())

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

return Keyword(**response.json())

def update_keyword(self, keyword: Keyword):
def update_keyword(self, keyword):
"""
PUT /api/keywords/{keywordId}
Updates a keyword
:keyword: Keyword to update
:param keyword: Keyword
:return:
"""
if keyword is None:
raise ValueError("keyword")
Expand All @@ -136,7 +137,7 @@ def update_keyword(self, keyword: Keyword):

response.raise_for_status()

def delete_keyword(self, keyword_id: str):
def delete_keyword(self, keyword_id):
"""
DELETE /api/keywords/{keywordId}
Deletes a keyword
Expand All @@ -150,7 +151,7 @@ def delete_keyword(self, keyword_id: str):

### OutMessage controller ###

def prepare_msisdns(self, msisdns: str):
def prepare_msisdns(self, msisdns):
"""
POST /api/prepare-msisdns
MSISDNs to prepare as a string array
Expand All @@ -161,7 +162,7 @@ def prepare_msisdns(self, msisdns: str):
response = self.client.post(self.PREPARE_MSISDNS, msisdns)
response.raise_for_status()

def create_out_message(self, out_message: OutMessage):
def create_out_message(self, out_message):
"""
POST /api/out-messages
Creates a new out-message
Expand All @@ -175,7 +176,7 @@ def create_out_message(self, out_message: OutMessage):

return self._get_id_from_header(response.headers)

def create_out_message_batch(self, out_messages: list):
def create_out_message_batch(self, out_messages):
"""
POST /api/out-messages/batch
Creates a new out-message batch.
Expand All @@ -187,7 +188,7 @@ def create_out_message_batch(self, out_messages: list):
response = self.client.post(self.OUT_MESSAGES + "/batch", out_messages)
response.raise_for_status()

def get_out_message(self, transaction_id: str) -> OutMessage:
def get_out_message(self, transaction_id):
"""
GET /api/out-messages/batch/{transactionId}
Gets and out-message
Expand All @@ -205,7 +206,7 @@ def get_out_message(self, transaction_id: str) -> OutMessage:

return OutMessage(**response.json())

def update_out_message(self, out_message: OutMessage):
def update_out_message(self, out_message):
"""
PUT /api/out-messages/batch/{transactionId}
Updates a future scheduled out-message.
Expand All @@ -220,7 +221,7 @@ def update_out_message(self, out_message: OutMessage):
self.OUT_MESSAGES + "/" + out_message.transactionId, out_message)
response.raise_for_status()

def delete_out_message(self, transaction_id: str):
def delete_out_message(self, transaction_id):
"""
DELETE /api/out-messages/batch/{transactionId}
Deletes a future sheduled out-message.
Expand All @@ -234,7 +235,7 @@ def delete_out_message(self, transaction_id: str):

### InMessages controller ###

def get_in_message(self, short_number_id, transaction_id) -> InMessage:
def get_in_message(self, short_number_id, transaction_id):
"""
GET /api/in-messages/{shortNumberId}/{transactionId}
Gets and in-message
Expand All @@ -253,7 +254,7 @@ def get_in_message(self, short_number_id, transaction_id) -> InMessage:

### StrexMerchants controller ###

def get_strex_merchants(self) -> list:
def get_strex_merchants(self):
"""
GET /api/strex/merchants
Gets all merchant ids.
Expand All @@ -263,7 +264,7 @@ def get_strex_merchants(self) -> list:
response.raise_for_status()
return StrexMerchant.from_list(response.json())

def get_strex_merchant(self, merchant_id: str) -> StrexMerchant:
def get_strex_merchant(self, merchant_id):
"""
GET /api/strex/merchants/{merchantId}
Gets a merchant.
Expand All @@ -282,7 +283,7 @@ def get_strex_merchant(self, merchant_id: str) -> StrexMerchant:

return StrexMerchant(**response.json())

def save_strex_merchant(self, strex_merchant: StrexMerchant):
def save_strex_merchant(self, strex_merchant):
"""
PUT /api/strex/merchants/{merchantId}
Creates/updates a merchant.
Expand All @@ -309,7 +310,7 @@ def delete_strex_merchant(self, merchant_id):
response = self.client.delete(self.STREX_MERCHANTS + "/" + merchant_id)
response.raise_for_status()

def create_one_time_password(self, one_time_password: OneTimePassword):
def create_one_time_password(self, one_time_password):
"""
POST /api/strex/one-time-passwords
:return:
Expand All @@ -331,7 +332,7 @@ def create_one_time_password(self, one_time_password: OneTimePassword):
response = self.client.post(self.STREX_ONE_TIME_PASSWORDS, one_time_password)
response.raise_for_status()

def get_one_time_password(self, transaction_id) -> OneTimePassword:
def get_one_time_password(self, transaction_id):
"""
GET /api/strex/one-time-passwords/{transactionId}

Expand All @@ -345,7 +346,7 @@ def get_one_time_password(self, transaction_id) -> OneTimePassword:

return OneTimePassword(**response.json())

def create_strex_transaction(self, transaction: StrexTransaction) -> str:
def create_strex_transaction(self, transaction):
"""
POST /api/strex/transactions
:return str:
Expand All @@ -356,7 +357,7 @@ def create_strex_transaction(self, transaction: StrexTransaction) -> str:

return self._get_id_from_header(response.headers)

def get_strex_transaction(self, transaction_id: str) -> StrexTransaction:
def get_strex_transaction(self, transaction_id):
"""
GET /api/strex/transactions/{transactionId}
:return:
Expand All @@ -367,7 +368,7 @@ def get_strex_transaction(self, transaction_id: str) -> StrexTransaction:

return StrexTransaction(**response.json())

def delete_strex_transaction(self, transaction_id: str):
def delete_strex_transaction(self, transaction_id):
"""
DELETE /api/strex/transactions/{transactionId}
:param transaction_id:
Expand All @@ -379,7 +380,7 @@ def delete_strex_transaction(self, transaction_id: str):

### PublicKey controller ###

def get_server_public_key(self, key_name: str) -> PublicKey:
def get_server_public_key(self, key_name):
"""
GET /api/server/public-keys/{key_name}
:param key_name:
Expand All @@ -400,7 +401,7 @@ def get_client_public_keys(self):

return PublicKey.from_list(response.json())

def get_client_public_key(self, key_name: str) -> PublicKey:
def get_client_public_key(self, key_name):
"""
GET /api/client/public-keys/{key_name}
:return: Dict
Expand All @@ -410,7 +411,7 @@ def get_client_public_key(self, key_name: str) -> PublicKey:

return PublicKey(**response.json())

def delete_client_public_key(self, key_name: str):
def delete_client_public_key(self, key_name):
"""
DELETE /api/client/public-keys/{key_name}
:return:
Expand Down
10 changes: 8 additions & 2 deletions target365_sdk/helpers/http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@
import uuid
import base64
import hashlib
import urllib
import jsonpickle

try:
#python2
from urllib import urlencode
except ImportError:
#python3
from urllib.parse import urlencode

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

def get_with_params(self, path, query_params):

url = self._build_url(path)
if len(query_params.keys()) > 0:
url += "?"

absolute_uri = (url + urllib.parse.urlencode(query_params)).lower()
absolute_uri = (url + urlencode(query_params)).lower()
return requests.get(
self._build_url(path),
params=query_params,
Expand Down
2 changes: 1 addition & 1 deletion target365_sdk/models/in_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
class InMessage(Model):


def _accepted_params(self) -> list:
def _accepted_params(self):

return [
'messageId',
Expand Down
2 changes: 1 addition & 1 deletion target365_sdk/models/keyword.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class Keyword(Model):

def _accepted_params(self) -> list:
def _accepted_params(self):
return [
'keywordId',
'shortNumberId',
Expand Down
2 changes: 1 addition & 1 deletion target365_sdk/models/lookup_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class LookupResult(Model):

def _accepted_params(self) -> list:
def _accepted_params(self):
return [
'created',
'msisdn',
Expand Down
10 changes: 6 additions & 4 deletions target365_sdk/models/model.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from abc import ABC, abstractmethod
from abc import ABCMeta, abstractmethod

class Model:
__metaclass__ = ABCMeta

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


@classmethod
def from_list(cls, items: list) -> list:
def from_list(cls, items):
"""
:param list of dictionaries:
:return list of models:
:param items:
:type items: list
:return: list
"""
return [cls(**item) for item in items]
2 changes: 1 addition & 1 deletion target365_sdk/models/one_time_password.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class OneTimePassword(Model):

def _accepted_params(self) -> list:
def _accepted_params(self):
return [
'transactionId',
'merchantId',
Expand Down
2 changes: 1 addition & 1 deletion target365_sdk/models/out_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
class OutMessage(Model):


def _accepted_params(self) -> list:
def _accepted_params(self):
return [
'id',
'accountId',
Expand Down
2 changes: 1 addition & 1 deletion target365_sdk/models/public_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class PublicKey(Model):

def _accepted_params(self) -> list:
def _accepted_params(self):
return [
'accountId',
'name',
Expand Down
2 changes: 1 addition & 1 deletion target365_sdk/models/strex_merchant.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class StrexMerchant(Model):

def _accepted_params(self) -> list:
def _accepted_params(self):
return [
'merchantId',
'shortNumberId',
Expand Down
2 changes: 1 addition & 1 deletion target365_sdk/models/strex_transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class StrexTransaction(Model):

def _accepted_params(self) -> list:
def _accepted_params(self):
return [
'transactionId',
'invoiceText',
Expand Down
5 changes: 5 additions & 0 deletions test-py2
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

source test_secrets.sh

python2 -m pytest -v -x --capture=no