self._id becomes self.id
This commit is contained in:
parent
abfbda8867
commit
34b782ca28
@ -131,13 +131,13 @@ class API(object):
|
|||||||
class APIObject(object):
|
class APIObject(object):
|
||||||
def __init__(self, api, id=None, data=None):
|
def __init__(self, api, id=None, data=None):
|
||||||
self._api = api
|
self._api = api
|
||||||
self._id = id
|
self.id = id
|
||||||
if data:
|
if data:
|
||||||
self._id = data.get("id", None)
|
self.id = int( data.get("id", None) )
|
||||||
self._data = data
|
self._data = data
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def makeUrl(cls, _id=None):
|
def makeUrl(cls, id=None):
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -151,23 +151,23 @@ class APIObject(object):
|
|||||||
self._data = data
|
self._data = data
|
||||||
|
|
||||||
def create(self):
|
def create(self):
|
||||||
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)
|
||||||
)
|
)
|
||||||
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)
|
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
|
return self._data
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
if not self._id:
|
if not self.id:
|
||||||
raise ValueError("%s not yet created" % (self.__class__.__name__,))
|
raise ValueError("%s not yet created" % (self.__class__.__name__,))
|
||||||
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.patch(self.makeUrl(), data=self._data)
|
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
|
return self._data
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@ -181,7 +181,7 @@ class APIObject(object):
|
|||||||
return path
|
return path
|
||||||
|
|
||||||
def url(self, parent=None):
|
def url(self, parent=None):
|
||||||
return self.__class__.makeUrl(self._id, parent)
|
return self.__class__.makeUrl(self.id, parent)
|
||||||
|
|
||||||
|
|
||||||
class Partner(APIObject):
|
class Partner(APIObject):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user