Esempio n. 1
0
    def build(self, response):
        """
        Deserialize the returned objects and return either a single Zenpy object, or a ResultGenerator in
        the case of multiple results.

        :param response: the requests Response object.
        """
        response_json = response.json()

        zenpy_objects = self.deserialize(response_json)

        # Collection of objects (eg, users/tickets)
        plural_object_type = as_plural(self.api.object_type)
        if plural_object_type in zenpy_objects:
            return ZendeskResultGenerator(self, response_json)

        # Here the response matches the API object_type, seems legit.
        if self.api.object_type in zenpy_objects:
            return zenpy_objects[self.api.object_type]

        # Could be anything, if we know of this object then return it.
        for zenpy_object_name in self.api._object_mapping.class_mapping:
            if zenpy_object_name in zenpy_objects:
                return zenpy_objects[zenpy_object_name]

        # Maybe a collection of known objects?
        for zenpy_object_name in self.api._object_mapping.class_mapping:
            plural_zenpy_object_name = as_plural(zenpy_object_name)
            if plural_zenpy_object_name in zenpy_objects:
                return ZendeskResultGenerator(
                    self, response_json, object_type=plural_zenpy_object_name)
        # Bummer, bail out with an informative message.
        raise ZenpyException("Unknown Response: " + str(response_json))
Esempio n. 2
0
    def build(self, response):
        """
        Deserialize the returned objects and return either a single Zenpy object, or a ResultGenerator in
        the case of multiple results.

        :param response: the requests Response object.
        """
        response_json = response.json()

        # Special case for incremental cursor based ticket audits export.
        if get_endpoint_path(self.api,
                             response).startswith('/ticket_audits.json'):
            return TicketCursorGenerator(self,
                                         response_json,
                                         object_type="audit")

        # Special case for incremental cursor based tickets export.
        if get_endpoint_path(
                self.api,
                response).startswith('/incremental/tickets/cursor.json'):
            return TicketCursorGenerator(self,
                                         response_json,
                                         object_type="ticket")

        # Special case for Jira links.
        if get_endpoint_path(self.api,
                             response).startswith('/services/jira/links'):
            return JiraLinkGenerator(self, response_json, response)

        zenpy_objects = self.deserialize(response_json)

        # Collection of objects (eg, users/tickets)
        plural_object_type = as_plural(self.api.object_type)
        if plural_object_type in zenpy_objects:
            return ZendeskResultGenerator(
                self,
                response_json,
                response_objects=zenpy_objects[plural_object_type])

        # Here the response matches the API object_type, seems legit.
        if self.api.object_type in zenpy_objects:
            return zenpy_objects[self.api.object_type]

        # Could be anything, if we know of this object then return it.
        for zenpy_object_name in self.object_mapping.class_mapping:
            if zenpy_object_name in zenpy_objects:
                return zenpy_objects[zenpy_object_name]

        # Maybe a collection of known objects?
        for zenpy_object_name in self.object_mapping.class_mapping:
            plural_zenpy_object_name = as_plural(zenpy_object_name)
            if plural_zenpy_object_name in zenpy_objects:
                return ZendeskResultGenerator(
                    self, response_json, object_type=plural_zenpy_object_name)

        # Bummer, bail out.
        raise ZenpyException("Unknown Response: " + str(response_json))
Esempio n. 3
0
 def build(self, response):
     response_json = response.json()
     response_objects = self.deserialize(response_json)
     return ZendeskResultGenerator(self,
                                   response_json,
                                   response_objects['comments'],
                                   object_type='comment')
Esempio n. 4
0
 def build(self, response):
     response_json = response.json()
     response_objects = self.deserialize(response_json)
     if 'sla_policies' in response_objects:
         return ZendeskResultGenerator(self, response.json(), response_objects=response_objects['sla_policies'])
     elif 'sla_policy' in response_objects:
         return response_objects['sla_policy']
     elif response_objects:
         return response_objects['definitions']
     raise ZenpyException("Could not handle response: {}".format(response_json))