Skip to content

Commit

Permalink
chore: use subdomain in the base url for zendesk chat api. Also, the …
Browse files Browse the repository at this point in the history
…subdomain will be a required field
  • Loading branch information
am6010 committed Sep 27, 2024
1 parent ed5958e commit 758d0f3
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from setuptools import find_packages, setup

MAIN_REQUIREMENTS = ["airbyte-cdk", "pendulum"]
MAIN_REQUIREMENTS = ["airbyte-cdk==0.67", "pendulum"]

TEST_REQUIREMENTS = ["pytest~=6.1", "pytest-mock", "requests_mock"]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,28 +34,30 @@ def get_auth(self) -> TokenAuthenticator:
class SourceZendeskChat(AbstractSource):
def check_connection(self, logger, config) -> Tuple[bool, any]:
authenticator = ZendeskAuthentication(config).get_auth()
subdomain = config.get("subdomain", None)
try:
records = RoutingSettings(authenticator=authenticator).read_records(sync_mode=SyncMode.full_refresh)
records = RoutingSettings(authenticator=authenticator, subdomain=subdomain).read_records(sync_mode=SyncMode.full_refresh)
next(records)
return True, None
except Exception as error:
return False, f"Unable to connect to Zendesk Chat API with the provided credentials - {error}"

def streams(self, config: Mapping[str, Any]) -> List[Stream]:
authenticator = ZendeskAuthentication(config).get_auth()
subdomain = config.get("subdomain", None)
return [
Accounts(authenticator=authenticator),
AgentTimelines(authenticator=authenticator, start_date=config["start_date"]),
Agents(authenticator=authenticator),
Bans(authenticator=authenticator),
Chats(authenticator=authenticator, start_date=config["start_date"]),
Conversions(authenticator=authenticator, start_date=config["start_date"]),
Departments(authenticator=authenticator),
DepartmentEvents(authenticator=authenticator, start_date=config["start_date"]),
Goals(authenticator=authenticator),
Roles(authenticator=authenticator),
RoutingSettings(authenticator=authenticator),
Shortcuts(authenticator=authenticator),
Skills(authenticator=authenticator),
Triggers(authenticator=authenticator),
Accounts(authenticator=authenticator, subdomain=subdomain),
AgentTimelines(authenticator=authenticator, subdomain=subdomain, start_date=config["start_date"]),
Agents(authenticator=authenticator, subdomain=subdomain),
Bans(authenticator=authenticator, subdomain=subdomain),
Chats(authenticator=authenticator, subdomain=subdomain, start_date=config["start_date"]),
Conversions(authenticator=authenticator, subdomain=subdomain, start_date=config["start_date"]),
Departments(authenticator=authenticator, subdomain=subdomain),
DepartmentEvents(authenticator=authenticator, subdomain=subdomain, start_date=config["start_date"]),
Goals(authenticator=authenticator, subdomain=subdomain),
Roles(authenticator=authenticator, subdomain=subdomain),
RoutingSettings(authenticator=authenticator, subdomain=subdomain),
Shortcuts(authenticator=authenticator, subdomain=subdomain),
Skills(authenticator=authenticator, subdomain=subdomain),
Triggers(authenticator=authenticator, subdomain=subdomain),
]
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Zendesk Chat Spec",
"type": "object",
"required": ["start_date"],
"required": ["start_date", "subdomain"],
"additionalProperties": true,
"properties": {
"start_date": {
Expand All @@ -18,7 +18,7 @@
"subdomain": {
"type": "string",
"title": "Subdomain",
"description": "Required if you access Zendesk Chat from a Zendesk Support subdomain.",
"description": "This is your Zendesk subdomain that can be found in your account URL. For example, in https://{MY_SUBDOMAIN}.zendesk.com/, where MY_SUBDOMAIN is the value of your subdomain.",
"default": ""
},
"credentials": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,24 @@


class Stream(HttpStream, ABC):
url_base = "https://www.zopim.com/api/v2/"
def __init__(self, subdomain, **kwargs):
super().__init__(**kwargs)
self.subdomain = subdomain

primary_key = "id"

data_field = None

limit = 100

@property
def url_base(self):
# We need to use the subdomain to build the URL. As the zopim API is deprecated and will phase out on 29/10/2024
# https://developer.zendesk.com/api-reference/live-chat/introduction/
if self.subdomain:
return f"https://{self.subdomain}.zendesk.com/api/v2/chat/"
return "https://www.zopim.com/api/v2/"

@property
def availability_strategy(self) -> Optional["AvailabilityStrategy"]:
return None
Expand Down

0 comments on commit 758d0f3

Please sign in to comment.