How to use the zenpy.lib.api.CRUDApi 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 / api.py View on Github external
def __init__(self, config):
        super(TicketImportAPI, self).__init__(config,
                                              object_type='ticket',
                                              endpoint=EndpointFactory('ticket_import'))

    def __call__(self, *args, **kwargs):
        raise ZenpyException("You must pass ticket objects to this endpoint!")

    def update(self, items, **kwargs):
        raise ZenpyException("You cannot update objects using ticket_import endpoint!")

    def delete(self, api_objects, **kwargs):
        raise ZenpyException("You cannot delete objects using the ticket_import endpoint!")


class TicketFieldApi(CRUDApi):
    pass


class RequestAPI(CRUDApi):
    def __init__(self, config):
        super(RequestAPI, self).__init__(config, object_type='request')

    def open(self):
        """
        Return all open requests
        """
        return self._query_zendesk(self.endpoint.open, 'request')

    def solved(self):
        """
        Return all solved requests
github facetoe / zenpy / zenpy / lib / api.py View on Github external
raise ZenpyException("You cannot delete requests!")

    def search(self, *args, **kwargs):
        """
        Search for requests. See the Zendesk docs for more information on the syntax
         https://developer.zendesk.com/rest_api/docs/core/requests#searching-requests
        """
        return self._query_zendesk(self.endpoint.search, 'request', *args, **kwargs)


class SharingAgreementAPI(CRUDApi):
    def __init__(self, config):
        super(SharingAgreementAPI, self).__init__(config, object_type='sharing_agreement')


class GroupApi(CRUDApi):
    def __init__(self, config):
        super(GroupApi, self).__init__(config, object_type='group')

    def memberships(self, group_id):
        """
        Return the GroupMemberships for this group

        :param group_id
        """
        return self._get(self._build_url(self.endpoint.memberships(id=group_id)))

    def memberships_assignable(self, group_id):
        """
        Return memberships that are assignable for this group.

        :param group_id: group or group_id
github facetoe / zenpy / zenpy / lib / api.py View on Github external
"""
        Merge the ticket(s) or ticket ID(s) in source into the target ticket.

        :param target: ticket id or object to merge tickets into
        :param source: ticket id, object or list of tickets or ids to merge into target
        :param source_comment: optional comment for the source ticket(s)
        :param target_comment: optional comment for the target ticket

        :return: a JobStatus object
        """
        return TicketMergeRequest(self).post(target, source,
                                             target_comment=target_comment,
                                             source_comment=source_comment)


class TicketImportAPI(CRUDApi):
    def __init__(self, config):
        super(TicketImportAPI, self).__init__(config,
                                              object_type='ticket',
                                              endpoint=EndpointFactory('ticket_import'))

    def __call__(self, *args, **kwargs):
        raise ZenpyException("You must pass ticket objects to this endpoint!")

    def update(self, items, **kwargs):
        raise ZenpyException("You cannot update objects using ticket_import endpoint!")

    def delete(self, api_objects, **kwargs):
        raise ZenpyException("You cannot delete objects using the ticket_import endpoint!")


class TicketFieldApi(CRUDApi):
github facetoe / zenpy / zenpy / lib / api.py View on Github external
:param api_objects: object or objects to update
        """
        return CRUDRequest(self).put(api_objects)

    def delete(self, api_objects, **kwargs):
        """
        Delete (DELETE) one or more API objects. After successfully deleting the objects from the API
        they will also be removed from the relevant Zenpy caches.

        :param api_objects: object or objects to delete
        """

        return CRUDRequest(self).delete(api_objects)


class CRUDExternalApi(CRUDApi):
    """
    The CRUDExternalApi exposes some extra methods for operating on external ids.
    """

    def update_by_external_id(self, api_objects):
        """
        Update (PUT) one or more API objects by external_id.

        :param api_objects:
        """
        if not isinstance(api_objects, collections.Iterable):
            api_objects = [api_objects]
        return CRUDRequest(self).put(api_objects, update_many_external=True)

    def delete_by_external_id(self, api_objects):
        """
github facetoe / zenpy / zenpy / lib / api.py View on Github external
def search(self, *args, **kwargs):
        """
        Search views. See - https://developer.zendesk.com/rest_api/docs/core/views#search-views.

        :param args: query is the only accepted arg.
        :param kwargs: search parameters
        """
        return self._get(self._build_url(self.endpoint.search(*args, **kwargs)))

    # TODO: https://github.com/facetoe/zenpy/issues/123
    def _get_sla(self, sla_id):
        pass


class GroupMembershipApi(CRUDApi):
    def __init__(self, config):
        super(GroupMembershipApi, self).__init__(config, object_type='group_membership')

    def update(self, api_objects, **kwargs):
        raise ZenpyException("Cannot update GroupMemberships")

    def assignable(self):
        """
        Return GroupMemberships that are assignable.
        """
        return self._get(self._build_url(self.endpoint.assignable()))

    def make_default(self, user_id, group_membership_id):
        """
        Set the passed GroupMembership as default for the specified user.
github facetoe / zenpy / zenpy / lib / api.py View on Github external
"""
        Return GroupMemberships that are assignable.
        """
        return self._get(self._build_url(self.endpoint.assignable()))

    def make_default(self, user_id, group_membership_id):
        """
        Set the passed GroupMembership as default for the specified user.

        :param user_id:
        :param group_membership_id:
        """
        return self._put(self._build_url(self.endpoint.make_default(user_id, group_membership_id)), payload={})


class SlaPolicyApi(CRUDApi):
    def __init__(self, config):
        super(SlaPolicyApi, self).__init__(config, object_type='sla_policy')

    def create(self, api_objects, **kwargs):
        if isinstance(api_objects, collections.Iterable):
            raise ZenpyException("Cannot create multiple sla policies!")
        super(SlaPolicyApi, self).create(api_objects, **kwargs)

    def update(self, api_objects, **kwargs):
        if isinstance(api_objects, collections.Iterable):
            raise ZenpyException("Cannot update multiple sla policies!")
        super(SlaPolicyApi, self).update(api_objects, **kwargs)

    def definitions(self):
        url = self._build_url(self.endpoint.definitions())
        return self._get(url)
github facetoe / zenpy / zenpy / lib / api.py View on Github external
def __call__(self, *args, **kwargs):
        raise ZenpyException("You must pass ticket objects to this endpoint!")

    def update(self, items, **kwargs):
        raise ZenpyException("You cannot update objects using ticket_import endpoint!")

    def delete(self, api_objects, **kwargs):
        raise ZenpyException("You cannot delete objects using the ticket_import endpoint!")


class TicketFieldApi(CRUDApi):
    pass


class RequestAPI(CRUDApi):
    def __init__(self, config):
        super(RequestAPI, self).__init__(config, object_type='request')

    def open(self):
        """
        Return all open requests
        """
        return self._query_zendesk(self.endpoint.open, 'request')

    def solved(self):
        """
        Return all solved requests
        """
        return self._query_zendesk(self.endpoint.solved, 'request')

    def ccd(self):
github facetoe / zenpy / zenpy / lib / api.py View on Github external
Return comments for request
        """
        return self._query_zendesk(self.endpoint.comments, 'comment', id=request_id)

    def delete(self, api_objects, **kwargs):
        raise ZenpyException("You cannot delete requests!")

    def search(self, *args, **kwargs):
        """
        Search for requests. See the Zendesk docs for more information on the syntax
         https://developer.zendesk.com/rest_api/docs/core/requests#searching-requests
        """
        return self._query_zendesk(self.endpoint.search, 'request', *args, **kwargs)


class SharingAgreementAPI(CRUDApi):
    def __init__(self, config):
        super(SharingAgreementAPI, self).__init__(config, object_type='sharing_agreement')


class GroupApi(CRUDApi):
    def __init__(self, config):
        super(GroupApi, self).__init__(config, object_type='group')

    def memberships(self, group_id):
        """
        Return the GroupMemberships for this group

        :param group_id
        """
        return self._get(self._build_url(self.endpoint.memberships(id=group_id)))