|
|
@ -23,6 +23,11 @@ API_BASE = "https://pbx.sipcentric.com/api/v1"
|
|
|
|
|
|
|
|
|
|
|
|
ACCOUNTTYPE_BUSINESS = "BUSINESS"
|
|
|
|
ACCOUNTTYPE_BUSINESS = "BUSINESS"
|
|
|
|
ACCOUNTTYPE_RESIDENTIAL = "RESIDENTIAL"
|
|
|
|
ACCOUNTTYPE_RESIDENTIAL = "RESIDENTIAL"
|
|
|
|
|
|
|
|
ACCOUNTTYPE_WLR = "WLR"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
RECORDINGACCESS_ALL = "ALL"
|
|
|
|
|
|
|
|
RECORDINGACCESS_OWN = "OWN"
|
|
|
|
|
|
|
|
RECORDINGACCESS_NONE = "NONE"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class SipcentricException(Exception):
|
|
|
|
class SipcentricException(Exception):
|
|
|
@ -149,15 +154,19 @@ class APIObject(object):
|
|
|
|
def set_data(self, data):
|
|
|
|
def set_data(self, data):
|
|
|
|
self._data = data
|
|
|
|
self._data = data
|
|
|
|
|
|
|
|
|
|
|
|
def create(self):
|
|
|
|
def create(self, parent=None, **kwargs):
|
|
|
|
if self.id:
|
|
|
|
if self.id:
|
|
|
|
raise ValueError(
|
|
|
|
raise ValueError(
|
|
|
|
"%s ID %d already created" % (self.__class__.__name__, self.id)
|
|
|
|
"%s ID %d already created" % (self.__class__.__name__, self.id)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
self._data.update(**kwargs)
|
|
|
|
if not self._data:
|
|
|
|
if not self._data:
|
|
|
|
raise ValueError("No data associated with record.")
|
|
|
|
raise ValueError("No data associated with record.")
|
|
|
|
self._data = self._api.post(self.__class__.makeUrl(), data=self._data)
|
|
|
|
return self._create(parent=parent,data=self._data)
|
|
|
|
self.id = int( self._data.get("id") )
|
|
|
|
|
|
|
|
|
|
|
|
def _create(self, parent, data):
|
|
|
|
|
|
|
|
self._data = self._api.post(self.__class__.makeUrl(parent=parent), data=data)
|
|
|
|
|
|
|
|
self.id = int(self._data.get("id"))
|
|
|
|
return self._data
|
|
|
|
return self._data
|
|
|
|
|
|
|
|
|
|
|
|
def update(self):
|
|
|
|
def update(self):
|
|
|
@ -192,7 +201,7 @@ class Partner(APIObject):
|
|
|
|
raise NotImplementedError("There can be only one (Partner account)")
|
|
|
|
raise NotImplementedError("There can be only one (Partner account)")
|
|
|
|
return "/"
|
|
|
|
return "/"
|
|
|
|
|
|
|
|
|
|
|
|
def create(self):
|
|
|
|
def create(self, **kwargs):
|
|
|
|
raise NotImplementedError(
|
|
|
|
raise NotImplementedError(
|
|
|
|
"You need to sign up as a new partner at https://www.simwood.com/partner/"
|
|
|
|
"You need to sign up as a new partner at https://www.simwood.com/partner/"
|
|
|
|
)
|
|
|
|
)
|
|
|
@ -258,12 +267,18 @@ class Customer(APIObject):
|
|
|
|
for c in self._api.getMany(CreditStatus.makeUrl(parent=self.url())):
|
|
|
|
for c in self._api.getMany(CreditStatus.makeUrl(parent=self.url())):
|
|
|
|
yield CreditStatus(self._api, data=c)
|
|
|
|
yield CreditStatus(self._api, data=c)
|
|
|
|
|
|
|
|
|
|
|
|
def create(self, **kwargs):
|
|
|
|
def linkedusers(self):
|
|
|
|
self._data = kwargs
|
|
|
|
for c in self._api.getMany(LinkedUser.makeUrl(parent=self.url())):
|
|
|
|
|
|
|
|
yield LinkedUser(self._api, data=c)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def create(self, parent=None, **kwargs):
|
|
|
|
|
|
|
|
if parent:
|
|
|
|
|
|
|
|
raise ValueError("Customer cannot have a parent")
|
|
|
|
|
|
|
|
self._data.update(**kwargs)
|
|
|
|
for k in ("accountType", "company", "firstName", "lastName", "email", "address1", "city", "postcode", "telephone"):
|
|
|
|
for k in ("accountType", "company", "firstName", "lastName", "email", "address1", "city", "postcode", "telephone"):
|
|
|
|
if k not in self._data:
|
|
|
|
if k not in self._data:
|
|
|
|
raise ValueError('missing mandatory field "%s"' % k)
|
|
|
|
raise ValueError('missing mandatory field "%s"' % k)
|
|
|
|
return super(Customer, self).create()
|
|
|
|
return self._create(parent=parent, data=self._data)
|
|
|
|
|
|
|
|
|
|
|
|
# {
|
|
|
|
# {
|
|
|
|
# "type": "customer",
|
|
|
|
# "type": "customer",
|
|
|
@ -326,6 +341,18 @@ class CreditStatus(APIObject):
|
|
|
|
URLPART = "creditstatus"
|
|
|
|
URLPART = "creditstatus"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class LinkedUser(APIObject):
|
|
|
|
|
|
|
|
URLPART = "linkedusers"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def create(self, parent, **kwargs):
|
|
|
|
|
|
|
|
kwargs['type'] = "linkeduser"
|
|
|
|
|
|
|
|
self._data.update(**kwargs)
|
|
|
|
|
|
|
|
for k in ("activateUrl", "email", "recordingAccess", "owner", "enabled"):
|
|
|
|
|
|
|
|
if k not in self._data:
|
|
|
|
|
|
|
|
raise ValueError('missing mandatory field "%s"' % k)
|
|
|
|
|
|
|
|
return self._create(parent=parent, data=self._data)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Sms(APIObject):
|
|
|
|
class Sms(APIObject):
|
|
|
|
URLPART = "sms"
|
|
|
|
URLPART = "sms"
|
|
|
|
|
|
|
|
|
|
|
@ -337,3 +364,9 @@ class Sms(APIObject):
|
|
|
|
if __name__ == "__main__":
|
|
|
|
if __name__ == "__main__":
|
|
|
|
logging.error("Do not run directly, import module first!")
|
|
|
|
logging.error("Do not run directly, import module first!")
|
|
|
|
sys.exit()
|
|
|
|
sys.exit()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|