Skip to content

Commit

Permalink
fix discover + add missing endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
leo-schick committed Sep 6, 2022
1 parent 4f39f48 commit 3774fed
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion tap_zendesk/streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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():
Expand All @@ -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)
Expand All @@ -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,
Expand Down

0 comments on commit 3774fed

Please sign in to comment.