22from dataclasses import dataclass
33from typing import Dict , List
44
5- import httpx
6-
5+ from unstructured_ingest .utils .dep_check import requires_dependencies
76from unstructured_ingest .v2 .errors import ProviderError , RateLimitError , UserAuthError , UserError
87from unstructured_ingest .v2 .logger import logger
98
@@ -42,7 +41,10 @@ def __lt__(self, other):
4241
4342class ZendeskClient :
4443
44+ @requires_dependencies (["httpx" ], extras = "zendesk" )
4545 def __init__ (self , token : str , subdomain : str , email : str ):
46+ import httpx
47+
4648 # should be okay to be blocking.
4749 url_to_check = f"https://{ subdomain } .zendesk.com/api/v2/groups.json"
4850 auth = f"{ email } /token" , token
@@ -57,7 +59,10 @@ def __init__(self, token: str, subdomain: str, email: str):
5759 self ._email = email
5860 self ._auth = auth
5961
62+ @requires_dependencies (["httpx" ], extras = "zendesk" )
6063 def wrap_error (self , e : Exception ) -> Exception :
64+ import httpx
65+
6166 if not isinstance (e , httpx .HTTPStatusError ):
6267 logger .error (f"unhandled exception from Zendesk client: { e } " , exc_info = True )
6368 return e
@@ -88,10 +93,12 @@ def wrap_error(self, e: Exception) -> Exception:
8893 logger .error (f"unhandled http status error from Zendesk client: { e } " , exc_info = True )
8994 return e
9095
96+ @requires_dependencies (["httpx" ], extras = "zendesk" )
9197 async def get_articles_async (self ) -> List [ZendeskArticle ]:
9298 """
9399 Retrieves article content from Zendesk asynchronously.
94100 """
101+ import httpx
95102
96103 articles : List [ZendeskArticle ] = []
97104
@@ -117,7 +124,10 @@ async def get_articles_async(self) -> List[ZendeskArticle]:
117124 ]
118125 return articles
119126
127+ @requires_dependencies (["httpx" ], extras = "zendesk" )
120128 async def get_comments_async (self , ticket_id : int ) -> List ["Comment" ]:
129+ import httpx
130+
121131 comments_url = f"https://{ self ._subdomain } .zendesk.com/api/v2/tickets/{ ticket_id } /comments"
122132
123133 try :
@@ -138,7 +148,9 @@ async def get_comments_async(self, ticket_id: int) -> List["Comment"]:
138148 for entry in response .json ()["comments" ]
139149 ]
140150
151+ @requires_dependencies (["httpx" ], extras = "zendesk" )
141152 def get_users (self ) -> List [dict ]:
153+ import httpx
142154
143155 users : List [dict ] = []
144156
@@ -154,7 +166,10 @@ def get_users(self) -> List[dict]:
154166
155167 return users
156168
169+ @requires_dependencies (["httpx" ], extras = "zendesk" )
157170 async def get_tickets_async (self ) -> List ["ZendeskTicket" ]:
171+ import httpx
172+
158173 tickets : List ["ZendeskTicket" ] = []
159174 tickets_url = f"https://{ self ._subdomain } .zendesk.com/api/v2/tickets"
160175
@@ -179,10 +194,13 @@ async def get_tickets_async(self) -> List["ZendeskTicket"]:
179194
180195 return tickets
181196
197+ @requires_dependencies (["httpx" ], extras = "zendesk" )
182198 async def get_article_attachments_async (self , article_id : str ):
183199 """
184200 Handles article attachments such as images and stores them as UTF-8 encoded bytes.
185201 """
202+ import httpx
203+
186204 article_attachment_url = (
187205 f"https://{ self ._subdomain } .zendesk.com/api/v2/help_center/"
188206 f"articles/{ article_id } /attachments"
0 commit comments