self._id becomes self.id

master
Marek Isalski 3 years ago
parent abfbda8867
commit 34b782ca28

@ -131,13 +131,13 @@ class API(object):
class APIObject(object):
def __init__(self, api, id=None, data=None):
self._api = api
self._id = id
self.id = id
if data:
self._id = data.get("id", None)
self.id = int( data.get("id", None) )
self._data = data
@classmethod
def makeUrl(cls, _id=None):
def makeUrl(cls, id=None):
raise NotImplementedError()
@property
@ -151,23 +151,23 @@ class APIObject(object):
self._data = data
def create(self):
if self._id:
if self.id:
raise ValueError(
"%s ID %d already created" % (self.__class__.__name__, self._id)
"%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 = int( self._data.get("id") )
return self._data
def update(self):
if not self._id:
if not self.id:
raise ValueError("%s not yet created" % (self.__class__.__name__,))
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 = int( self._data.get("id") )
return self._data
@classmethod
@ -181,7 +181,7 @@ class APIObject(object):
return path
def url(self, parent=None):
return self.__class__.makeUrl(self._id, parent)
return self.__class__.makeUrl(self.id, parent)
class Partner(APIObject):

Loading…
Cancel
Save