From 3774fed419f95659661b2c4d5baa948692a754dd Mon Sep 17 00:00:00 2001 From: Leo Schick Date: Tue, 6 Sep 2022 08:53:47 +0200 Subject: [PATCH] fix discover + add missing endpoints --- tap_zendesk/streams.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/tap_zendesk/streams.py b/tap_zendesk/streams.py index ffbdfb9..d8393df 100644 --- a/tap_zendesk/streams.py +++ b/tap_zendesk/streams.py @@ -218,6 +218,7 @@ class Users(Stream): name = "users" replication_method = "INCREMENTAL" replication_key = "updated_at" + endpoint = 'https://{}.zendesk.com/api/v2/users' def _add_custom_fields(self, schema): try: @@ -577,6 +578,7 @@ class TicketForms(Stream): name = "ticket_forms" replication_method = "INCREMENTAL" replication_key = "updated_at" + endpoint = 'https://{}.zendesk.com/api/v2/ticket_forms' def sync(self, state): bookmark = self.get_bookmark(state) @@ -628,6 +630,7 @@ def sync(self, state): class SLAPolicies(Stream): name = "sla_policies" replication_method = "FULL_TABLE" + endpoint = 'https://{}.zendesk.com/api/v2/slas/policies' def sync(self, state): # pylint: disable=unused-argument for policy in self.client.sla_policies(): @@ -642,16 +645,18 @@ def check_access(self): class TalkPhoneNumbers(Stream): name = 'talk_phone_numbers' replication_method = "FULL_TABLE" + endpoint = 'https://{}.zendesk.com/api/v2/channels/voice/phone_numbers' def sync(self, state): # pylint: disable=unused-argument for phone_number in self.client.talk.phone_numbers(): yield (self.stream, phone_number) -class TalkCalls(Stream): +class TalkCalls(CursorBasedExportStream): name = 'talk_calls' replication_method = "INCREMENTAL" replication_key = 'updated_at' + endpoint = 'https://{}.zendesk.com/api/v2/channels/voice/stats/incremental/calls' def sync(self, state): bookmark = self.get_bookmark(state) @@ -668,6 +673,17 @@ def sync(self, state): self.update_bookmark(state, call.updated_at) yield (self.stream, call) + def check_access(self): + ''' + Check whether the permission was given to access stream resources or not. + ''' + url = self.endpoint.format(self.config['subdomain']) + # Convert start_date parameter to timestamp to pass with request param + start_time = datetime.datetime.strptime(self.config['start_date'], START_DATE_FORMAT).timestamp() + HEADERS['Authorization'] = 'Bearer {}'.format(self.config["access_token"]) + + http.call_api(url, self.request_timeout, params={'start_time': f'{start_time:00f}', 'per_page': 1}, headers=HEADERS) + STREAMS = { "tickets": Tickets,