blackened (slightly)

master
Marek Isalski 3 years ago
parent 188c4d46c8
commit 167946385a

@ -28,6 +28,7 @@ ACCOUNTTYPE_RESIDENTIAL = "RESIDENTIAL"
class SipcentricException(Exception):
pass
class AuthenticationException(SipcentricException):
pass
@ -48,11 +49,9 @@ class API(object):
if method == "GET":
if params:
r = requests.get(
url, auth=auth, params=params, verify=True, timeout=3.000
)
r = requests.get(url, auth=auth, params=params, verify=True, timeout=3.0)
else:
r = requests.get(url, auth=auth, verify=True, timeout=3.000)
r = requests.get(url, auth=auth, verify=True, timeout=3.0)
elif method == "POST":
headers = {"content-type": "application/json"}
@ -104,20 +103,20 @@ class API(object):
def getMany(self, uri, params=None, startPage=1, pageSize=20):
if params is None:
params = {'pageSize': pageSize, 'page': startPage}
params = {"pageSize": pageSize, "page": startPage}
else:
params['pageSize'] = pageSize
params['page'] = startPage
params["pageSize"] = pageSize
params["page"] = startPage
resp = self._request(uri, "GET", params=params)
for item in resp.get('items', []):
for item in resp.get("items", []):
yield item
nextPage = resp.get('nextPage', None)
nextPage = resp.get("nextPage", None)
while nextPage:
resp = self._request(nextPage, "GET")
for item in resp.get('items', []):
for item in resp.get("items", []):
yield item
nextPage = resp.get('nextPage', None)
nextPage = resp.get("nextPage", None)
def post(self, uri, data=None, params=None):
return self._request(uri, method="POST", data=data, params=params)
@ -134,7 +133,7 @@ class APIObject(object):
self._api = api
self._id = id
if data:
self._id = data.get('id', None)
self._id = data.get("id", None)
self._data = data
@classmethod
@ -153,11 +152,13 @@ class APIObject(object):
def create(self):
if self._id:
raise ValueError("%s ID %d already created" % (self.__class__.__name__, self._id))
raise ValueError(
"%s ID %d already created" % (self.__class__.__name__, self._id)
)
if not self._data:
raise ValueError("No data associated with record.")
self._data = self._api.post(self.__class__.makeUrl(), data=self._data)
self._id = self._data.get('id')
self._id = self._data.get("id")
return self._data
def update(self):
@ -166,7 +167,7 @@ class APIObject(object):
if not self._data:
raise ValueError("No data associated with record.")
self._data = self._api.patch(self.makeUrl(), data=self._data)
self._id = self._data.get('id')
self._id = self._data.get("id")
return self._data
@classmethod
@ -189,11 +190,13 @@ class Account(APIObject):
if parent:
raise ValueError("Account should not have a parent")
if id:
raise NotImplementedError('There can be only one (Partner account)')
raise NotImplementedError("There can be only one (Partner account)")
return "/"
def create(self):
raise NotImplementedError('You need to sign up as a new partner at https://www.simwood.com/partner/')
raise NotImplementedError(
"You need to sign up as a new partner at https://www.simwood.com/partner/"
)
def customers(self):
for c in self._api.getMany(Customer.makeUrl()):

Loading…
Cancel
Save