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))
def applies_to(api, response): try: return get_endpoint_path( api, response).startswith('/dynamic') and ( 'items' in response.json() or 'item' in response.json()) except ValueError: return False
def applies_to(api, response): return 'translations/missing.json' in get_endpoint_path(api, response)
def applies_to(api, response): return get_endpoint_path(api, response).startswith('/goals')
def applies_to(api, response): return get_endpoint_path(api, response).startswith('/departments')
def applies_to(api, response): return get_endpoint_path(api, response).startswith('/chats/search')
def applies_to(api, response): path = get_endpoint_path(api, response) return path.startswith('/chats') or path.startswith( '/incremental/chats')
def applies_to(api, response): endpoint_path = get_endpoint_path(api, response) return endpoint_path.startswith( '/requests') and endpoint_path.endswith('comments.json')