Open Anuril opened 1 year ago
Easiest way to do this by having the response saved in a dict of Resource
class and return instance of resource class itself. Then we can have methods like save / destroy which act on these resource class.
Check ruby code here.
class Resource(ABC):
....
def find(self, id):
response = self._connection.session.get(self.url + "/%s" % id)
data = {}
try:
data = self._raise_or_return_json(response)
except HTTPError:
raise
else:
self._new_instance = False
self._attributes = data
return self
def save(self):
...
def destroy(self):
...
How about using Pydantic (https://docs.pydantic.dev/) for representing the data? It's main purpose is data validation but it's also easy to parse and represent JSON data with its model classes and converting them back to a dict.
Adding the possibility to instanciate Zammad Objects, instead of having to handle dicts. (See Issue #202)