Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[New Feature] Add instanciation of Zammad Objects #208

Open
Anuril opened this issue Apr 12, 2023 · 2 comments
Open

[New Feature] Add instanciation of Zammad Objects #208

Anuril opened this issue Apr 12, 2023 · 2 comments
Assignees
Milestone

Comments

@Anuril
Copy link
Collaborator

Anuril commented Apr 12, 2023

Adding the possibility to instanciate Zammad Objects, instead of having to handle dicts. (See Issue #202)

@Anuril Anuril self-assigned this Apr 12, 2023
@Anuril Anuril added this to the v2.1.0 milestone Apr 12, 2023
@joeirimpan
Copy link
Owner

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):
        ...

@jvllmr
Copy link

jvllmr commented Apr 28, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: In Progress
Development

No branches or pull requests

3 participants