From 2e1c368f537aca1d06093e33b2675a84e8f10ca4 Mon Sep 17 00:00:00 2001 From: Marek Isalski Date: Wed, 20 Jul 2022 10:29:52 +0100 Subject: [PATCH] fix creation of sub-resources --- src/sipcentric/__init__.py | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/src/sipcentric/__init__.py b/src/sipcentric/__init__.py index d15ccb8..f01572f 100644 --- a/src/sipcentric/__init__.py +++ b/src/sipcentric/__init__.py @@ -378,44 +378,49 @@ class OutgoingCallerId(APIObject): TYPE = "outgoingcallerid" -class CreditStatus(APIObject): +class CustomerAPIObject(APIObject): + MANDATORY_FIELDS = () + + def create(self, parent, **kwargs): + if self._data: + self._data.update(**kwargs) + else: + self._data = kwargs + for k in self.__class__.MANDATORY_FIELDS: + if k not in self._data: + raise ValueError('missing mandatory field "%s"' % k) + return self._create(parent=parent, data=self._data) + + +class CreditStatus(CustomerAPIObject): URLPART = "creditstatus" TYPE = "creditstatus" -class CustomerPricing(APIObject): +class CustomerPricing(CustomerAPIObject): URLPART = "pricing" TYPE = "customerpricing" -class Limits(APIObject): +class Limits(CustomerAPIObject): URLPART = "limits" TYPE = "customerlimits" -class CallCharging(APIObject): +class CallCharging(CustomerAPIObject): URLPART = "callcharging" TYPE = "customercallcharging" -class Permissions(APIObject): +class Permissions(CustomerAPIObject): URLPART = "permissions" TYPE = "customerpermissions" -class LinkedUser(APIObject): +class LinkedUser(CustomerAPIObject): URLPART = "linkedusers" TYPE = "linkeduser" - - def create(self, parent, **kwargs): - if self._data: - self._data.update(**kwargs) - else: - self._data = 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) + MANDATORY_FIELDS = ("activateUrl", "email", "recordingAccess", "owner", "enabled") class Sms(APIObject):