Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Toggl endpoint. #8

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions tap_toggl/toggl.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def __init__(self, api_token=None, start_date=None, user_agent=None, trailing_da
self.start_date = start_date
self.workspace_ids = []
self.user_agent = user_agent
res = self._get('https://www.toggl.com/api/v8/workspaces')
res = self._get('https://api.track.toggl.com/api/v8/workspaces')
for item in res:
self.workspace_ids.append(item['id'])

Expand Down Expand Up @@ -101,47 +101,47 @@ def _get_from_endpoints(self, endpoints, column_name=None, bookmark=None, key=No


def is_authorized(self):
return self._get('https://www.toggl.com/api/v8/me')
return self._get('https://api.track.toggl.com/api/v8/me')


def workspaces(self, column_name=None, bookmark=None):
res = self._get('https://www.toggl.com/api/v8/workspaces')
res = self._get('https://api.track.toggl.com/api/v8/workspaces')
for item in res:
yield item


def clients(self, column_name=None, bookmark=None):
endpoints = self._get_workspace_endpoints('https://www.toggl.com/api/v8/workspaces/{workspace_id}/clients')
endpoints = self._get_workspace_endpoints('https://api.track.toggl.com/api/v8/workspaces/{workspace_id}/clients')
return self._get_from_endpoints(endpoints, column_name, bookmark)


def groups(self, column_name=None, bookmark=None):
endpoints = self._get_workspace_endpoints('https://www.toggl.com/api/v8/workspaces/{workspace_id}/groups')
endpoints = self._get_workspace_endpoints('https://api.track.toggl.com/api/v8/workspaces/{workspace_id}/groups')
return self._get_from_endpoints(endpoints, column_name, bookmark)


def projects(self, column_name=None, bookmark=None):
endpoints = self._get_workspace_endpoints('https://www.toggl.com/api/v8/workspaces/{workspace_id}/projects')
endpoints = self._get_workspace_endpoints('https://api.track.toggl.com/api/v8/workspaces/{workspace_id}/projects')
return self._get_from_endpoints(endpoints, column_name, bookmark)


def tasks(self, column_name=None, bookmark=None):
endpoints = self._get_workspace_endpoints('https://www.toggl.com/api/v8/workspaces/{workspace_id}/tasks')
endpoints = self._get_workspace_endpoints('https://api.track.toggl.com/api/v8/workspaces/{workspace_id}/tasks')
return self._get_from_endpoints(endpoints, column_name, bookmark)


def tags(self, column_name=None, bookmark=None):
endpoints = self._get_workspace_endpoints('https://www.toggl.com/api/v8/workspaces/{workspace_id}/tags')
endpoints = self._get_workspace_endpoints('https://api.track.toggl.com/api/v8/workspaces/{workspace_id}/tags')
return self._get_from_endpoints(endpoints, column_name, bookmark)


def users(self, column_name=None, bookmark=None):
endpoints = self._get_workspace_endpoints('https://www.toggl.com/api/v8/workspaces/{workspace_id}/users')
endpoints = self._get_workspace_endpoints('https://api.track.toggl.com/api/v8/workspaces/{workspace_id}/users')
return self._get_from_endpoints(endpoints, column_name, bookmark)


def workspace_users(self, column_name=None, bookmark=None):
endpoints = self._get_workspace_endpoints('https://www.toggl.com/api/v8/workspaces/{workspace_id}/workspace_users')
endpoints = self._get_workspace_endpoints('https://api.track.toggl.com/api/v8/workspaces/{workspace_id}/workspace_users')
return self._get_from_endpoints(endpoints, column_name, bookmark)


Expand All @@ -160,7 +160,7 @@ def time_entries(self, column_name=None, bookmark=None):
moving_start_date = utils.strptime_with_tz(start_date)
moving_end_date = moving_start_date + timedelta(days=30)
while moving_start_date <= utils.strptime_with_tz(end_date):
new_endpoints = self._get_workspace_endpoints('https://toggl.com/reports/api/v2/details?workspace_id={{workspace_id}}&since={start_date}&until={end_date}&user_agent={user_agent}'.format(start_date=moving_start_date.strftime(fmt), end_date=moving_end_date.strftime(fmt), user_agent=self.user_agent))
new_endpoints = self._get_workspace_endpoints('https://api.track.toggl.com/reports/api/v2/details?workspace_id={{workspace_id}}&since={start_date}&until={end_date}&user_agent={user_agent}'.format(start_date=moving_start_date.strftime(fmt), end_date=moving_end_date.strftime(fmt), user_agent=self.user_agent))
endpoints.extend(new_endpoints)
moving_start_date += timedelta(days=30)
moving_end_date = moving_start_date + timedelta(days=30)
Expand Down