@@ -14,7 +14,9 @@ class Toggl:
1414
1515 API_BASE_URL = "https://api.track.toggl.com"
1616 API_REPORTS_BASE_URL = "reports/api/v3"
17+ API_VERSION_URL = "api/v9"
1718 API_WORKSPACE = "workspace/{}"
19+ API_WORKSPACES = "workspaces/{}"
1820 API_HEADERS = {"Content-Type" : "application/json" , "User-Agent" : "compilerla/compiler-admin:{}" .format (__version__ )}
1921
2022 def __init__ (self , api_token : str , workspace_id : int , ** kwargs ):
@@ -33,6 +35,11 @@ def workspace_url_fragment(self):
3335 """The workspace portion of an API URL."""
3436 return Toggl .API_WORKSPACE .format (self .workspace_id )
3537
38+ @property
39+ def workspaces_url_fragment (self ):
40+ """The workspaces portion of an API URL."""
41+ return Toggl .API_WORKSPACES .format (self .workspace_id )
42+
3643 def _authorization_header (self ):
3744 """Gets an `Authorization: Basic xyz` header using the Toggl API token.
3845
@@ -42,6 +49,10 @@ def _authorization_header(self):
4249 creds64 = b64encode (bytes (creds , "utf-8" )).decode ("utf-8" )
4350 return {"Authorization" : "Basic {}" .format (creds64 )}
4451
52+ def _make_api_url (self , endpoint : str ):
53+ """Get a fully formed URL for the Toggl API version endpoint."""
54+ return "/" .join ((Toggl .API_BASE_URL , Toggl .API_VERSION_URL , self .workspaces_url_fragment , endpoint ))
55+
4556 def _make_report_url (self , endpoint : str ):
4657 """Get a fully formed URL for the Toggl Reports API v3 endpoint.
4758
@@ -108,3 +119,15 @@ def post_reports(self, endpoint: str, **kwargs) -> requests.Response:
108119 response .raise_for_status ()
109120
110121 return response
122+
123+ def update_workspace_preferences (self , ** kwargs ) -> requests .Response :
124+ """Update workspace preferences.
125+
126+ See https://engineering.toggl.com/docs/api/preferences/#post-update-workspace-preferences.
127+ """
128+ url = self ._make_api_url ("preferences" )
129+
130+ response = self .session .post (url , json = kwargs , timeout = self .timeout )
131+ response .raise_for_status ()
132+
133+ return response
0 commit comments