From 297a67f57e22b928b626b9d97a0a81079251cea0 Mon Sep 17 00:00:00 2001 From: Daniel Date: Sat, 17 Aug 2019 22:34:44 -0400 Subject: [PATCH] getIP endpoint now reachable --- .gitignore | 63 +++++++-------------- voipms/api/__init__.py | 26 ++++++--- voipms/api/accounts/__init__.py | 14 +---- voipms/api/call_detail_records/__init__.py | 5 +- voipms/api/dids/__init__.py | 5 +- voipms/api/general/__init__.py | 22 ++++++- voipms/api/{accounts => general}/balance.py | 0 voipms/api/general/ip.py | 7 +++ voipms/api/voicemail/__init__.py | 5 +- 9 files changed, 78 insertions(+), 69 deletions(-) rename voipms/api/{accounts => general}/balance.py (100%) create mode 100644 voipms/api/general/ip.py diff --git a/.gitignore b/.gitignore index 0f21dc8..3b37653 100644 --- a/.gitignore +++ b/.gitignore @@ -3,58 +3,35 @@ __pycache__/ *.py[cod] *$py.class -# C extensions -*.so +# Installer logs +pip-log.txt # Distribution / packaging -.Python -build/ -develop-eggs/ -dist/ -downloads/ -eggs/ -.eggs/ -lib/ -lib64/ -parts/ -sdist/ -var/ -wheels/ -pip-wheel-metadata/ -share/python-wheels/ -*.egg-info/ +dist +build +eggs +parts +bin +develop-eggs .installed.cfg -*.egg -MANIFEST +scratch +env +venv* +wheels # Unit test / coverage reports -htmlcov/ -.tox/ -.nox/ .coverage -.coverage.* -.cache -nosetests.xml -coverage.xml -*.cover -.hypothesis/ .pytest_cache/ +.tox +test.py + +.DS_Store + +#htmlcov +htmlcov* # pyenv .python-version -# Environments -.env -.venv -env/ -venv/ -ENV/ -env.bak/ -venv.bak/ - # Visual Studio Code -.vscode/* -!.vscode/settings.json -!.vscode/tasks.json -!.vscode/launch.json -!.vscode/extensions.json \ No newline at end of file +.vscode/ \ No newline at end of file diff --git a/voipms/api/__init__.py b/voipms/api/__init__.py index b0d12e2..7c802d5 100644 --- a/voipms/api/__init__.py +++ b/voipms/api/__init__.py @@ -1,6 +1,8 @@ import os import platform +import json import requests + from voipms.base.exceptions import VoipException class Client(object): @@ -30,8 +32,14 @@ class Client(object): params["method"] = method params["content_type"] = "json" - response = requests.get(self.api_base, params=params).json() - return response + response = requests.get(self.api_base, params=params) + data = json.loads(response.text) + + if data['status'] and data['status'] != 'success': + err = data['status'] + raise VoipException("API Call failed with exception: {}".format(err)) + + return data @property def accounts(self): @@ -44,30 +52,34 @@ class Client(object): def call_detail_records(self): if self._call_detail_records is None: from voipms.api.call_detail_records import CallDetailRecords - self._call_detail_records = CallDetailRecords() + self._call_detail_records = CallDetailRecords(self) return self._call_detail_records @property def dids(self): if self._dids is None: from voipms.api.dids import DIDs - self._dids = DIDs() + self._dids = DIDs(self) return self._dids @property def general(self): if self._general is None: from voipms.api.general import General - self._general = General() + self._general = General(self) return self._general @property def voicemail(self): if self._voicemail is None: from voipms.api.voicemail import Voicemail - self._voicemail = Voicemail() + self._voicemail = Voicemail(self) return self._voicemail @property def balance(self): - return self.accounts.balance \ No newline at end of file + return self.general.balance + + @property + def ip(self): + return self.general.ip \ No newline at end of file diff --git a/voipms/api/accounts/__init__.py b/voipms/api/accounts/__init__.py index 91ec980..b3beea9 100644 --- a/voipms/api/accounts/__init__.py +++ b/voipms/api/accounts/__init__.py @@ -1,12 +1,4 @@ -from voipms.api.accounts.balance import Balance - class Accounts(): - def __init__(self, base): - self._balance = None - self.base = base - - @property - def balance(self): - if self._balance is None: - self._balance = Balance(self.base) - return self._balance \ No newline at end of file + def __init__(self, base): + self._balance = None + self.base = base \ No newline at end of file diff --git a/voipms/api/call_detail_records/__init__.py b/voipms/api/call_detail_records/__init__.py index 3a6007b..558addf 100644 --- a/voipms/api/call_detail_records/__init__.py +++ b/voipms/api/call_detail_records/__init__.py @@ -1,3 +1,4 @@ class CallDetailRecords(): - def __init__(self): - pass \ No newline at end of file + def __init__(self, base): + self._balance = None + self.base = base \ No newline at end of file diff --git a/voipms/api/dids/__init__.py b/voipms/api/dids/__init__.py index f6534c7..6bb48d2 100644 --- a/voipms/api/dids/__init__.py +++ b/voipms/api/dids/__init__.py @@ -1,3 +1,4 @@ class DIDs(): - def __init__(self): - pass \ No newline at end of file + def __init__(self, base): + self._balance = None + self.base = base \ No newline at end of file diff --git a/voipms/api/general/__init__.py b/voipms/api/general/__init__.py index 2873d1a..4523125 100644 --- a/voipms/api/general/__init__.py +++ b/voipms/api/general/__init__.py @@ -1,3 +1,21 @@ +from voipms.api.general.balance import Balance +from voipms.api.general.ip import IP + class General(): - def __init__(self): - pass \ No newline at end of file + def __init__(self, base): + self._balance = None + self._ip = None + + self.base = base + + @property + def balance(self): + if self._balance is None: + self._balance = Balance(self.base) + return self._balance + + @property + def ip(self): + if self._ip is None: + self._ip = IP(self.base) + return self._ip \ No newline at end of file diff --git a/voipms/api/accounts/balance.py b/voipms/api/general/balance.py similarity index 100% rename from voipms/api/accounts/balance.py rename to voipms/api/general/balance.py diff --git a/voipms/api/general/ip.py b/voipms/api/general/ip.py new file mode 100644 index 0000000..09bfa06 --- /dev/null +++ b/voipms/api/general/ip.py @@ -0,0 +1,7 @@ +class IP(): + def __init__(self, base): + self.method = "getIP" + self.base = base + + def fetch(self, params={}): + return self.base.request(self.method) \ No newline at end of file diff --git a/voipms/api/voicemail/__init__.py b/voipms/api/voicemail/__init__.py index 41b8da1..00e23aa 100644 --- a/voipms/api/voicemail/__init__.py +++ b/voipms/api/voicemail/__init__.py @@ -1,3 +1,4 @@ class Voicemail(): - def __init__(self): - self._balance = None \ No newline at end of file + def __init__(self, base): + self._balance = None + self.base = base \ No newline at end of file