How to use the zenpy.lib.api.Api 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
Delete (DELETE) one or more tags.

        :param _id: the id of the object to delete tag from
        :param tags: array of tags to delete from object
        """
        return TagRequest(self).delete(tags, id)

    def tags(self, ticket_id):
        """
        Lists the most popular recent tags in decreasing popularity from a specific ticket.
        """
        return self._query_zendesk(self.endpoint.tags, 'tag', id=ticket_id)


# noinspection PyShadowingBuiltins
class RateableApi(Api):
    """
    Supports rating with a SatisfactionRating
    """

    def rate(self, id, rating):
        """
        Add (POST) a satisfaction rating.

        :param id: id of object to rate
        :param rating: SatisfactionRating
        """
        return RateRequest(self).post(rating, id)


class IncrementalApi(Api):
    """
github facetoe / zenpy / zenpy / lib / api.py View on Github external
return CRUDRequest(self).post(organization, create_or_update=True)


class OrganizationMembershipApi(CRUDApi):
    """
    The OrganizationMembershipApi allows the creation and deletion of Organization Memberships
    """

    def __init__(self, config):
        super(OrganizationMembershipApi, self).__init__(config, object_type='organization_membership')

    def update(self, items, **kwargs):
        raise ZenpyException("You cannot update Organization Memberships!")


class SatisfactionRatingApi(Api):
    def __init__(self, config):
        super(SatisfactionRatingApi, self).__init__(config, object_type='satisfaction_rating')

    def create(self, ticket_id, satisfaction_rating):
        """
        Create/update a Satisfaction Rating for a ticket.

        :param ticket_id: id of Ticket to rate
        :param satisfaction_rating: SatisfactionRating object.
        """
        return SatisfactionRatingRequest(self).post(ticket_id, satisfaction_rating)


class MacroApi(CRUDApi):
    def __init__(self, config):
        super(MacroApi, self).__init__(config, object_type='macro')
github facetoe / zenpy / zenpy / lib / api.py View on Github external
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)


class RecipientAddressApi(CRUDApi):
    def __init__(self, config):
        super(RecipientAddressApi, self).__init__(config, object_type='recipient_address')


class ChatApiBase(Api):
    """
    Implements most generic ChatApi functionality. Most if the actual work is delegated to
    Request and Response handlers.
    """

    def __init__(self, config, endpoint, request_handler=None):
        super(ChatApiBase, self).__init__(config,
                                          object_type='chat',
                                          endpoint=endpoint)
        self._request_handler = request_handler or ChatApiRequest
        self._object_mapping = ChatObjectMapping(self)
        self._url_template = "%(protocol)s://www.zopim.com/%(api_prefix)s"
        self._response_handlers = (
            DeleteResponseHandler,
            ChatSearchResponseHandler,
            ChatResponseHandler,
github facetoe / zenpy / zenpy / lib / api.py View on Github external
def __init__(self, config, object_type, endpoint=None):
        self.object_type = object_type
        self.endpoint = endpoint or EndpointFactory(as_plural(object_type))
        super(Api, self).__init__(**config)
        self._object_mapping = ZendeskObjectMapping(self)
github facetoe / zenpy / zenpy / lib / chat_api.py View on Github external
from zenpy.lib.response import (
    ChatResponseHandler,
    AccountResponseHandler,
    AgentResponseHandler,
    DeleteResponseHandler,
    VisitorResponseHandler,
    ChatSearchResponseHandler,
    ShortcutResponseHandler,
    TriggerResponseHandler,
    BanResponseHandler,
    GoalResponseHandler,
    DepartmentResponseHandler
)


class ChatApiBase(Api):
    """
    Implements most generic ChatApi functionality. Most if the actual work is delegated to 
    Request and Response handlers. 
    """

    def __init__(self, config, endpoint, request_handler=None):
        super(ChatApiBase, self).__init__(config,
                                          object_type='chat',
                                          endpoint=endpoint)
        self._request_handler = request_handler or ChatApiRequest
        self._object_manager = ChatObjectManager(self)
        self._url_template = "%(protocol)s://www.zopim.com/%(api_prefix)s"
        self._response_handlers = (
            DeleteResponseHandler,
            ChatSearchResponseHandler,
            ChatResponseHandler,
github facetoe / zenpy / zenpy / __init__.py View on Github external
self.tickets = TicketApi(config)
        self.suspended_tickets = SuspendedTicketApi(config, object_type='suspended_ticket')
        self.search = SearchApi(config)
        self.topics = Api(config, object_type='topic')
        self.attachments = AttachmentApi(config)
        self.brands = BrandApi(config, object_type='brand')
        self.job_status = Api(config, object_type='job_status', endpoint=EndpointFactory('job_statuses'))
        self.jira_links = JiraLinkApi(config)
        self.tags = Api(config, object_type='tag')
        self.satisfaction_ratings = SatisfactionRatingApi(config)
        self.sharing_agreements = SharingAgreementAPI(config)
        self.skips = SkipApi(config)
        self.activities = Api(config, object_type='activity')
        self.group_memberships = GroupMembershipApi(config)
        self.end_user = EndUserApi(config)
        self.ticket_metrics = Api(config, object_type='ticket_metric')
        self.ticket_metric_events = Api(config, object_type='ticket_metric_events')
        self.ticket_fields = TicketFieldApi(config)
        self.ticket_forms = TicketFormApi(config, object_type='ticket_form')
        self.ticket_import = TicketImportAPI(config)
        self.requests = RequestAPI(config)
        self.chats = ChatApi(config, endpoint=EndpointFactory('chats'))
        self.views = ViewApi(config)
        self.sla_policies = SlaPolicyApi(config)
        self.help_center = HelpCentreApi(config)
        self.recipient_addresses = RecipientAddressApi(config)
        self.nps = NpsApi(config)
        self.triggers = TriggerApi(config, object_type='trigger')
        self.automations = AutomationApi(config, object_type='automation')
        self.dynamic_content = DynamicContentApi(config)
        self.targets = TargetApi(config, object_type='target')
        self.talk = TalkApi(config)
github facetoe / zenpy / zenpy / lib / api.py View on Github external
self.accounts = ChatApiBase(config, endpoint.account, request_handler=AccountRequest)
        self.agents = AgentApi(config, endpoint.agents)
        self.visitors = ChatApiBase(config, endpoint.visitors, request_handler=VisitorRequest)
        self.shortcuts = ChatApiBase(config, endpoint.shortcuts)
        self.triggers = ChatApiBase(config, endpoint.triggers)
        self.bans = ChatApiBase(config, endpoint.bans)
        self.departments = ChatApiBase(config, endpoint.departments)
        self.goals = ChatApiBase(config, endpoint.goals)
        self.stream = ChatApiBase(config, endpoint.stream)

    def search(self, *args, **kwargs):
        url = self._build_url(self.endpoint.search(*args, **kwargs))
        return self._get(url)


class HelpCentreApiBase(Api):
    def __init__(self, config, endpoint, object_type):
        super(HelpCentreApiBase, self).__init__(config, object_type=object_type, endpoint=endpoint)

        self._response_handlers = (MissingTranslationHandler,) + self._response_handlers

        self._object_mapping = HelpCentreObjectMapping(self)
        self._url_template = "%(protocol)s://%(subdomain)s.zendesk.com/%(api_prefix)s%(locale)s"
        self.locale = ''

    def _process_response(self, response):
        endpoint_path = get_endpoint_path(self, response)
        if endpoint_path.startswith('/help_center') or endpoint_path.startswith('/community'):
            object_mapping = self._object_mapping
        else:
            object_mapping = ZendeskObjectMapping(self)
        return super(HelpCentreApiBase, self)._process_response(response, object_mapping)
github facetoe / zenpy / zenpy / __init__.py View on Github external
)

        self.users = UserApi(config)
        self.user_fields = Api(config, object_type='user_field')
        self.groups = GroupApi(config)
        self.macros = MacroApi(config)
        self.organizations = OrganizationApi(config)
        self.organization_memberships = OrganizationMembershipApi(config)
        self.organization_fields = OrganizationFieldsApi(config)
        self.tickets = TicketApi(config)
        self.suspended_tickets = SuspendedTicketApi(config, object_type='suspended_ticket')
        self.search = SearchApi(config)
        self.topics = Api(config, object_type='topic')
        self.attachments = AttachmentApi(config)
        self.brands = BrandApi(config, object_type='brand')
        self.job_status = Api(config, object_type='job_status', endpoint=EndpointFactory('job_statuses'))
        self.jira_links = JiraLinkApi(config)
        self.tags = Api(config, object_type='tag')
        self.satisfaction_ratings = SatisfactionRatingApi(config)
        self.sharing_agreements = SharingAgreementAPI(config)
        self.skips = SkipApi(config)
        self.activities = Api(config, object_type='activity')
        self.group_memberships = GroupMembershipApi(config)
        self.end_user = EndUserApi(config)
        self.ticket_metrics = Api(config, object_type='ticket_metric')
        self.ticket_metric_events = Api(config, object_type='ticket_metric_events')
        self.ticket_fields = TicketFieldApi(config)
        self.ticket_forms = TicketFormApi(config, object_type='ticket_form')
        self.ticket_import = TicketImportAPI(config)
        self.requests = RequestAPI(config)
        self.chats = ChatApi(config, endpoint=EndpointFactory('chats'))
        self.views = ViewApi(config)
github facetoe / zenpy / zenpy / __init__.py View on Github external
timeout = timeout or self.DEFAULT_TIMEOUT

        self.cache = ZenpyCacheManager(disable_cache)

        config = dict(
            subdomain=subdomain,
            session=session,
            timeout=timeout,
            ratelimit=int(proactive_ratelimit) if proactive_ratelimit is not None else None,
            ratelimit_budget=int(ratelimit_budget) if ratelimit_budget is not None else None,
            ratelimit_request_interval=int(proactive_ratelimit_request_interval),
            cache=self.cache
        )

        self.users = UserApi(config)
        self.user_fields = Api(config, object_type='user_field')
        self.groups = GroupApi(config)
        self.macros = MacroApi(config)
        self.organizations = OrganizationApi(config)
        self.organization_memberships = OrganizationMembershipApi(config)
        self.organization_fields = OrganizationFieldsApi(config)
        self.tickets = TicketApi(config)
        self.suspended_tickets = SuspendedTicketApi(config, object_type='suspended_ticket')
        self.search = SearchApi(config)
        self.topics = Api(config, object_type='topic')
        self.attachments = AttachmentApi(config)
        self.brands = BrandApi(config, object_type='brand')
        self.job_status = Api(config, object_type='job_status', endpoint=EndpointFactory('job_statuses'))
        self.jira_links = JiraLinkApi(config)
        self.tags = Api(config, object_type='tag')
        self.satisfaction_ratings = SatisfactionRatingApi(config)
        self.sharing_agreements = SharingAgreementAPI(config)
github facetoe / zenpy / zenpy / __init__.py View on Github external
self.suspended_tickets = SuspendedTicketApi(config, object_type='suspended_ticket')
        self.search = SearchApi(config)
        self.topics = Api(config, object_type='topic')
        self.attachments = AttachmentApi(config)
        self.brands = BrandApi(config, object_type='brand')
        self.job_status = Api(config, object_type='job_status', endpoint=EndpointFactory('job_statuses'))
        self.jira_links = JiraLinkApi(config)
        self.tags = Api(config, object_type='tag')
        self.satisfaction_ratings = SatisfactionRatingApi(config)
        self.sharing_agreements = SharingAgreementAPI(config)
        self.skips = SkipApi(config)
        self.activities = Api(config, object_type='activity')
        self.group_memberships = GroupMembershipApi(config)
        self.end_user = EndUserApi(config)
        self.ticket_metrics = Api(config, object_type='ticket_metric')
        self.ticket_metric_events = Api(config, object_type='ticket_metric_events')
        self.ticket_fields = TicketFieldApi(config)
        self.ticket_forms = TicketFormApi(config, object_type='ticket_form')
        self.ticket_import = TicketImportAPI(config)
        self.requests = RequestAPI(config)
        self.chats = ChatApi(config, endpoint=EndpointFactory('chats'))
        self.views = ViewApi(config)
        self.sla_policies = SlaPolicyApi(config)
        self.help_center = HelpCentreApi(config)
        self.recipient_addresses = RecipientAddressApi(config)
        self.nps = NpsApi(config)
        self.triggers = TriggerApi(config, object_type='trigger')
        self.automations = AutomationApi(config, object_type='automation')
        self.dynamic_content = DynamicContentApi(config)
        self.targets = TargetApi(config, object_type='target')
        self.talk = TalkApi(config)
        self.custom_agent_roles = CustomAgentRolesApi(config, object_type='custom_agent_role')