diff --git a/src/sipcentric/__init__.py b/src/sipcentric/__init__.py index 3005fdc..7ce8006 100644 --- a/src/sipcentric/__init__.py +++ b/src/sipcentric/__init__.py @@ -23,6 +23,11 @@ API_BASE = "https://pbx.sipcentric.com/api/v1" ACCOUNTTYPE_BUSINESS = "BUSINESS" ACCOUNTTYPE_RESIDENTIAL = "RESIDENTIAL" +ACCOUNTTYPE_WLR = "WLR" + +RECORDINGACCESS_ALL = "ALL" +RECORDINGACCESS_OWN = "OWN" +RECORDINGACCESS_NONE = "NONE" class SipcentricException(Exception): @@ -149,15 +154,19 @@ class APIObject(object): def set_data(self, data): self._data = data - def create(self): + def create(self, parent=None, **kwargs): if self.id: raise ValueError( "%s ID %d already created" % (self.__class__.__name__, self.id) ) + self._data.update(**kwargs) if not self._data: raise ValueError("No data associated with record.") - self._data = self._api.post(self.__class__.makeUrl(), data=self._data) - self.id = int( self._data.get("id") ) + return self._create(parent=parent,data=self._data) + + 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 def update(self): @@ -192,7 +201,7 @@ class Partner(APIObject): raise NotImplementedError("There can be only one (Partner account)") return "/" - def create(self): + def create(self, **kwargs): raise NotImplementedError( "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())): yield CreditStatus(self._api, data=c) - def create(self, **kwargs): - self._data = kwargs + def linkedusers(self): + 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"): if k not in self._data: raise ValueError('missing mandatory field "%s"' % k) - return super(Customer, self).create() + return self._create(parent=parent, data=self._data) # { # "type": "customer", @@ -326,6 +341,18 @@ class CreditStatus(APIObject): 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): URLPART = "sms" @@ -337,3 +364,9 @@ class Sms(APIObject): if __name__ == "__main__": logging.error("Do not run directly, import module first!") sys.exit() + + + + + +