How to use the zenpy.lib.util.as_singular function in zenpy

To help you get started, we’ve selected a few zenpy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github facetoe / zenpy / zenpy / lib / response.py View on Github external
response_json
            )

        # Locate and store the single objects.
        for zenpy_object_name in self.object_mapping.class_mapping:
            if zenpy_object_name in response_json:
                zenpy_object = self.object_mapping.object_from_json(
                    zenpy_object_name,
                    response_json[zenpy_object_name]
                )
                response_objects[zenpy_object_name] = zenpy_object

        # Locate and store the collections of objects.
        for key, value in response_json.items():
            if isinstance(value, list):
                zenpy_object_name = as_singular(key)
                if zenpy_object_name in self.object_mapping.class_mapping:
                    response_objects[key] = []
                    for object_json in response_json[key]:
                        zenpy_object = self.object_mapping.object_from_json(
                            zenpy_object_name,
                            object_json
                        )
                        response_objects[key].append(zenpy_object)
        return response_objects
github facetoe / zenpy / zenpy / lib / mapping.py View on Github external
def _deserialize(self, key, obj, value):
        if isinstance(value, dict):
            key = self.format_key(key, parent=obj)
            if key in self.class_mapping:
                value = self.object_from_json(key, value, parent=obj)
            elif as_singular(key) in self.class_mapping:
                value = self.object_from_json(
                    as_singular(key), value, parent=obj)
        elif isinstance(value, list) and self.format_key(as_singular(key), parent=obj) in self.class_mapping:
            zenpy_objects = list()
            for item in value:
                object_type = self.format_key(as_singular(key), parent=obj)
                zenpy_objects.append(self.object_from_json(
                    object_type, item, parent=obj))
            value = zenpy_objects
        return key, value
github facetoe / zenpy / zenpy / lib / mapping.py View on Github external
def _deserialize(self, key, obj, value):
        if isinstance(value, dict):
            key = self.format_key(key, parent=obj)
            if key in self.class_mapping:
                value = self.object_from_json(key, value, parent=obj)
            elif as_singular(key) in self.class_mapping:
                value = self.object_from_json(
                    as_singular(key), value, parent=obj)
        elif isinstance(value, list) and self.format_key(as_singular(key), parent=obj) in self.class_mapping:
            zenpy_objects = list()
            for item in value:
                object_type = self.format_key(as_singular(key), parent=obj)
                zenpy_objects.append(self.object_from_json(
                    object_type, item, parent=obj))
            value = zenpy_objects
        return key, value
github facetoe / zenpy / zenpy / lib / mapping.py View on Github external
def _deserialize(self, key, obj, value):
        if isinstance(value, dict):
            key = self.format_key(key, parent=obj)
            if key in self.class_mapping:
                value = self.object_from_json(key, value, parent=obj)
            elif as_singular(key) in self.class_mapping:
                value = self.object_from_json(
                    as_singular(key), value, parent=obj)
        elif isinstance(value, list) and self.format_key(as_singular(key), parent=obj) in self.class_mapping:
            zenpy_objects = list()
            for item in value:
                object_type = self.format_key(as_singular(key), parent=obj)
                zenpy_objects.append(self.object_from_json(
                    object_type, item, parent=obj))
            value = zenpy_objects
        return key, value
github facetoe / zenpy / zenpy / lib / mapping.py View on Github external
def _deserialize(self, key, obj, value):
        if isinstance(value, dict):
            key = self.format_key(key, parent=obj)
            if key in self.class_mapping:
                value = self.object_from_json(key, value, parent=obj)
            elif as_singular(key) in self.class_mapping:
                value = self.object_from_json(
                    as_singular(key), value, parent=obj)
        elif isinstance(value, list) and self.format_key(as_singular(key), parent=obj) in self.class_mapping:
            zenpy_objects = list()
            for item in value:
                object_type = self.format_key(as_singular(key), parent=obj)
                zenpy_objects.append(self.object_from_json(
                    object_type, item, parent=obj))
            value = zenpy_objects
        return key, value