Source code for airflow.providers.zendesk.hooks.zendesk
## Licensed to the Apache Software Foundation (ASF) under one# or more contributor license agreements. See the NOTICE file# distributed with this work for additional information# regarding copyright ownership. The ASF licenses this file# to you under the Apache License, Version 2.0 (the# "License"); you may not use this file except in compliance# with the License. You may obtain a copy of the License at## http://www.apache.org/licenses/LICENSE-2.0## Unless required by applicable law or agreed to in writing,# software distributed under the License is distributed on an# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY# KIND, either express or implied. See the License for the# specific language governing permissions and limitations# under the License.from__future__importannotationsfromtypingimportTYPE_CHECKING,AnyfromzenpyimportZenpyfromairflow.hooks.baseimportBaseHookifTYPE_CHECKING:fromzenpy.lib.apiimportBaseApifromzenpy.lib.api_objectsimportJobStatus,Ticket,TicketAuditfromzenpy.lib.generatorimportSearchResultGenerator
[docs]classZendeskHook(BaseHook):""" Interact with Zendesk. This hook uses the Zendesk conn_id. :param zendesk_conn_id: The Airflow connection used for Zendesk credentials. """
def_init_conn(self)->tuple[Zenpy,str]:""" Create the Zenpy Client for our Zendesk connection. :return: zenpy.Zenpy client and the url for the API. """conn=self.get_connection(self.zendesk_conn_id)url="https://"+conn.hostdomain=conn.hostsubdomain:str|None=Noneifconn.host.count(".")>=2:dot_splitted_string=conn.host.rsplit(".",2)subdomain=dot_splitted_string[0]domain=".".join(dot_splitted_string[1:])returnZenpy(domain=domain,subdomain=subdomain,email=conn.login,password=conn.password),url
[docs]defget_conn(self)->Zenpy:""" Get the underlying Zenpy client. :return: zenpy.Zenpy client. """returnself.zenpy_client
[docs]defsearch_tickets(self,**kwargs)->SearchResultGenerator:""" Search tickets. :param kwargs: (optional) Search fields given to the zenpy search method. :return: SearchResultGenerator of Ticket objects. """returnself.zenpy_client.search(type="ticket",**kwargs)
[docs]defcreate_tickets(self,tickets:Ticket|list[Ticket],**kwargs)->TicketAudit|JobStatus:""" Create tickets. :param tickets: Ticket or List of Ticket to create. :param kwargs: (optional) Additional fields given to the zenpy create method. :return: A TicketAudit object containing information about the Ticket created. When sending bulk request, returns a JobStatus object. """returnself.zenpy_client.tickets.create(tickets,**kwargs)
[docs]defupdate_tickets(self,tickets:Ticket|list[Ticket],**kwargs)->TicketAudit|JobStatus:""" Update tickets. :param tickets: Updated Ticket or List of Ticket object to update. :param kwargs: (optional) Additional fields given to the zenpy update method. :return: A TicketAudit object containing information about the Ticket updated. When sending bulk request, returns a JobStatus object. """returnself.zenpy_client.tickets.update(tickets,**kwargs)
[docs]defdelete_tickets(self,tickets:Ticket|list[Ticket],**kwargs)->None:""" Delete tickets, returns nothing on success and raises APIException on failure. :param tickets: Ticket or List of Ticket to delete. :param kwargs: (optional) Additional fields given to the zenpy delete method. :return: """returnself.zenpy_client.tickets.delete(tickets,**kwargs)