Beispiel #1
0
Datei: api.py Projekt: bibz/zenpy
 def _get_fields(self,
                 fields,
                 object_type='ticket_field',
                 endpoint=Endpoint().ticket_fields):
     if any([
             self._query_cache(object_type, field) is None
             for field in [f['id'] for f in fields]
     ]):
         # Populate field cache
         self._get(self._get_url(endpoint=endpoint()))
     for field in fields:
         yield self._query_cache(object_type, field)
Beispiel #2
0
 def get_fields(self,
                fields,
                object_type='ticket_field',
                endpoint=Endpoint().ticket_fields):
     return self._get_fields([f['id'] for f in fields], endpoint,
                             object_type)
Beispiel #3
0
 def get_organization_fields(
         self,
         organization_fields,
         endpoint=Endpoint().organizations.organization_fields,
         object_type='organization_field'):
     return self._get_fields(organization_fields, endpoint, object_type)
Beispiel #4
0
 def get_user_fields(self,
                     user_fields,
                     endpoint=Endpoint().user_fields,
                     object_type='user_field'):
     return self._get_fields(user_fields, endpoint, object_type)
Beispiel #5
0
    def __init__(self,
                 subdomain,
                 email=None,
                 token=None,
                 oauth_token=None,
                 password=None,
                 session=None):
        session = self._init_session(email, token, oauth_token, password,
                                     session)
        endpoint = Endpoint()

        self.users = UserApi(subdomain,
                             session=session,
                             endpoint=endpoint.users)

        self.user_fields = Api(subdomain,
                               session=session,
                               endpoint=endpoint.user_fields,
                               object_type='user_field')

        self.groups = Api(subdomain,
                          session=session,
                          endpoint=endpoint.groups,
                          object_type='group')

        self.organizations = OrganizationApi(subdomain,
                                             session=session,
                                             endpoint=endpoint.organizations)

        self.organization_memberships = OrganizationMembershipApi(
            subdomain,
            session=session,
            endpoint=endpoint.organization_memberships)

        self.tickets = TicketApi(subdomain,
                                 session=session,
                                 endpoint=endpoint.tickets)

        self.suspended_tickets = SuspendedTicketApi(
            subdomain, session=session, endpoint=endpoint.suspended_tickets)

        self.search = Api(subdomain,
                          session=session,
                          endpoint=endpoint.search,
                          object_type='results')

        self.topics = Api(subdomain,
                          session=session,
                          endpoint=endpoint.topics,
                          object_type='topic')

        self.attachments = Api(subdomain,
                               session=session,
                               endpoint=endpoint.attachments,
                               object_type='attachment')

        self.brands = Api(subdomain,
                          session=session,
                          endpoint=endpoint.brands,
                          object_type='brand')

        self.job_status = Api(subdomain,
                              session=session,
                              endpoint=endpoint.job_statuses,
                              object_type='job_status')

        self.tags = Api(subdomain,
                        session=session,
                        endpoint=endpoint.tags,
                        object_type='tag')

        self.satisfaction_ratings = Api(subdomain,
                                        session=session,
                                        endpoint=endpoint.satisfaction_ratings,
                                        object_type='satisfaction_rating')

        self.activities = Api(subdomain,
                              session=session,
                              endpoint=endpoint.activities,
                              object_type='activity')

        self.group_memberships = Api(subdomain,
                                     session=session,
                                     endpoint=endpoint.group_memberships,
                                     object_type='group_membership')

        self.end_user = EndUserApi(subdomain,
                                   session=session,
                                   endpoint=endpoint.end_user)

        self.ticket_metrics = Api(subdomain,
                                  session=session,
                                  endpoint=endpoint.ticket_metrics,
                                  object_type='ticket_metric')

        self.ticket_fields = Api(subdomain,
                                 session=session,
                                 endpoint=endpoint.ticket_fields,
                                 object_type='ticket_field')

        self.ticket_import = TicketImportAPI(subdomain,
                                             session=session,
                                             endpoint=endpoint.ticket_import)

        self.requests = RequestAPI(subdomain,
                                   session=session,
                                   endpoint=endpoint.requests)
Beispiel #6
0
    def __init__(self,
                 subdomain,
                 email=None,
                 token=None,
                 oauth_token=None,
                 password=None,
                 session=None,
                 timeout=None):
        """
        Python Wrapper for the Zendesk API.

        There are several ways to authenticate with the Zendesk API:
            * Email and password
            * Email and Zendesk API token
            * Email and OAuth token
            * Existing authenticated Requests Session object.


        :param subdomain: your Zendesk subdomain
        :param email: email address
        :param token: Zendesk API token
        :param oauth_token: OAuth token
        :param password: Zendesk password
        :param session: Existing Requests Session object
        :param timeout: Global timeout on API requests.
        """

        session = self._init_session(email, token, oauth_token, password,
                                     session)
        timeout = timeout or self.DEFAULT_TIMEOUT
        endpoint = Endpoint()

        self.users = UserApi(subdomain=subdomain,
                             session=session,
                             timeout=timeout,
                             endpoint=endpoint.users)

        self.user_fields = Api(subdomain=subdomain,
                               session=session,
                               timeout=timeout,
                               endpoint=endpoint.user_fields,
                               object_type='user_field')

        self.groups = Api(subdomain=subdomain,
                          session=session,
                          timeout=timeout,
                          endpoint=endpoint.groups,
                          object_type='group')

        self.organizations = OrganizationApi(subdomain=subdomain,
                                             session=session,
                                             timeout=timeout,
                                             endpoint=endpoint.organizations)

        self.organization_memberships = OrganizationMembershipApi(
            subdomain=subdomain,
            session=session,
            timeout=timeout,
            endpoint=endpoint.organization_memberships)

        self.tickets = TicketApi(subdomain=subdomain,
                                 session=session,
                                 timeout=timeout,
                                 endpoint=endpoint.tickets)

        self.suspended_tickets = SuspendedTicketApi(
            subdomain=subdomain,
            session=session,
            timeout=timeout,
            object_type='suspended_ticket',
            endpoint=endpoint.suspended_tickets)

        self.search = Api(subdomain=subdomain,
                          session=session,
                          timeout=timeout,
                          endpoint=endpoint.search,
                          object_type='results')

        self.topics = Api(subdomain=subdomain,
                          session=session,
                          timeout=timeout,
                          endpoint=endpoint.topics,
                          object_type='topic')

        self.attachments = AttachmentApi(subdomain=subdomain,
                                         session=session,
                                         timeout=timeout,
                                         endpoint=endpoint.attachments)

        self.brands = Api(subdomain=subdomain,
                          session=session,
                          timeout=timeout,
                          endpoint=endpoint.brands,
                          object_type='brand')

        self.job_status = Api(subdomain=subdomain,
                              session=session,
                              timeout=timeout,
                              endpoint=endpoint.job_statuses,
                              object_type='job_status')

        self.tags = Api(subdomain=subdomain,
                        session=session,
                        timeout=timeout,
                        endpoint=endpoint.tags,
                        object_type='tag')

        self.satisfaction_ratings = Api(subdomain=subdomain,
                                        session=session,
                                        timeout=timeout,
                                        endpoint=endpoint.satisfaction_ratings,
                                        object_type='satisfaction_rating')

        self.activities = Api(subdomain=subdomain,
                              session=session,
                              timeout=timeout,
                              endpoint=endpoint.activities,
                              object_type='activity')

        self.group_memberships = Api(subdomain=subdomain,
                                     session=session,
                                     timeout=timeout,
                                     endpoint=endpoint.group_memberships,
                                     object_type='group_membership')

        self.end_user = EndUserApi(subdomain=subdomain,
                                   session=session,
                                   timeout=timeout,
                                   endpoint=endpoint.end_user)

        self.ticket_metrics = Api(subdomain=subdomain,
                                  session=session,
                                  timeout=timeout,
                                  endpoint=endpoint.ticket_metrics,
                                  object_type='ticket_metric')

        self.ticket_fields = Api(subdomain=subdomain,
                                 session=session,
                                 timeout=timeout,
                                 endpoint=endpoint.ticket_fields,
                                 object_type='ticket_field')

        self.ticket_import = TicketImportAPI(subdomain=subdomain,
                                             session=session,
                                             timeout=timeout,
                                             endpoint=endpoint.ticket_import)

        self.requests = RequestAPI(subdomain=subdomain,
                                   session=session,
                                   timeout=timeout,
                                   endpoint=endpoint.requests)