Skip to content

Commit 4582b91

Browse files
author
Georgii Aleksahin
authored
Merge branch 'master' into task/ERP-1225/upgrade_python_to_3_12
2 parents 47be11e + 0ac7d77 commit 4582b91

File tree

7 files changed

+58
-55
lines changed

7 files changed

+58
-55
lines changed

docs/conf.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
import datetime
22
from pathlib import Path
3+
34
from sphinx.ext import apidoc
45

6+
57
copyright = f"{datetime.datetime.now().year}, Evrone"
68

79
# Auto generate documentation
810
if False:
9-
apidoc.main([
10-
'-f', # force overwrite
11-
'-T', # no modules.rst toc
12-
'-e', # Each module on it's own page
13-
'-o', str(Path(__file__).parent), # Output dir relative to "Sphinx root"
14-
str(Path(__file__).parent.parent / 'toggl_python') # Source code root
15-
])
11+
apidoc.main(
12+
[
13+
"-f", # force overwrite
14+
"-T", # no modules.rst toc
15+
"-e", # Each module on it's own page
16+
"-o",
17+
str(Path(__file__).parent), # Output dir relative to "Sphinx root"
18+
str(Path(__file__).parent.parent / "toggl_python"), # Source code root
19+
]
20+
)

poetry.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,4 @@ lines_after_imports = 2
6464

6565
[build-system]
6666
requires = ["poetry>=0.12"]
67-
build-backend = "poetry.masonry.api"
67+
build-backend = "poetry.masonry.api"

tests/test_entities.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ def test_client_entity():
2828

2929

3030
def test_group_entity():
31-
Group(name="foo", wid=1)
32-
Group(name="foo", wid=1, notes="some string")
31+
Group(name="foo", workspace_id=1)
32+
Group(name="foo", workspace_id=1, notes="some string")
3333

3434
with pytest.raises(pydantic.ValidationError):
3535
Group(name="foo")
3636
with pytest.raises(pydantic.ValidationError):
37-
Group(wid=1)
37+
Group(workspace_id=1)
3838
with pytest.raises(pydantic.ValidationError):
3939
Group(name=1, wid=None)
4040

@@ -65,23 +65,23 @@ def test_project_user_entity():
6565

6666

6767
def test_tag_entity():
68-
Tag(name="foo", wid=1)
68+
Tag(name="foo", workspace_id=1)
6969

7070
with pytest.raises(pydantic.ValidationError):
7171
Tag(name="foo")
7272
with pytest.raises(pydantic.ValidationError):
73-
Tag(wid=1)
73+
Tag(workspace_id=1)
7474

7575

7676
def test_task_entity():
77-
Task(name="foo", pid=1, wid=1)
77+
Task(name="foo", project_id=1, workspace_id=1)
7878

7979
with pytest.raises(pydantic.ValidationError):
80-
Task(name="foo", pid=1)
80+
Task(name="foo", project_id=1)
8181
with pytest.raises(pydantic.ValidationError):
82-
Task(name="foo", wid=1)
82+
Task(name="foo", workspace_id=1)
8383
with pytest.raises(pydantic.ValidationError):
84-
Task(pid=1, wid=1)
84+
Task(project_id=1, workspace_id=1)
8585

8686

8787
def test_time_entry_entity():

toggl_python/api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class Api:
1616
Allow to interact with official Toggl API via httpx.
1717
"""
1818

19-
BASE_URL: httpx.URL = httpx.URL("https://api.track.toggl.com/api/v8/")
19+
BASE_URL: httpx.URL = httpx.URL("https://api.track.toggl.com/api/v9/")
2020
HEADERS = {
2121
"content-type": "application/json",
2222
"user_agent": "toggl-python",

toggl_python/entities.py

Lines changed: 28 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from datetime import datetime
2-
from typing import Any, Callable, Dict, List, Optional, Union
2+
from typing import Callable, List, Optional, Union
33

4-
from pydantic import BaseModel, EmailStr, HttpUrl
4+
from pydantic import BaseModel, EmailStr, Field, HttpUrl
55

66

77
class BaseEntity(BaseModel):
@@ -17,7 +17,7 @@ class Client(BaseEntity):
1717

1818
class Group(BaseEntity):
1919
name: str
20-
wid: int
20+
wid: int = Field(alias="workspace_id")
2121

2222

2323
class Project(BaseEntity):
@@ -28,7 +28,7 @@ class Project(BaseEntity):
2828
is_private: bool = True
2929
template: Optional[bool] = None
3030
template_id: Optional[int] = None
31-
billable: bool = True
31+
billable: Optional[bool] = True
3232
auto_estimates: Optional[bool] = False
3333
estimated_hours: Optional[int] = None
3434
color: Union[str, int] = 0
@@ -48,15 +48,16 @@ class ProjectUser(BaseEntity):
4848

4949
class Tag(BaseEntity):
5050
name: str
51-
wid: int
51+
wid: int = Field(alias="workspace_id")
5252

5353

5454
class Task(BaseEntity):
5555
name: str
56-
pid: int
57-
wid: int
58-
uid: Optional[int] = None
56+
pid: int = Field(alias="project_id")
57+
wid: int = Field(alias="workspace_id")
58+
uid: Optional[int] = Field(alias="user_id", default=None)
5959
estimated_seconds: Optional[int] = None
60+
tracked_seconds: Optional[int] = None
6061
active: Optional[bool] = True
6162

6263

@@ -89,33 +90,11 @@ class ReportTimeEntry(BaseEntity):
8990
tags: List[str] = []
9091

9192

92-
class User(BaseEntity):
93-
api_token: Optional[str] = None
94-
default_wid: Optional[int] = None
95-
email: EmailStr
96-
fullname: str
97-
jquery_timeofday_format: str
98-
jquery_date_format: str
99-
timeofday_format: str
100-
date_format: str
101-
store_start_and_stop_time: bool
102-
beginning_of_week: int = 0
103-
language: str
104-
image_url: HttpUrl
105-
sidebar_piechart: bool
106-
new_blog_post: Optional[Dict[str, Any]] = None
107-
send_product_emails: bool
108-
send_weekly_report: bool
109-
send_timer_notifications: bool
110-
openid_enabled: bool
111-
timezone: str
112-
113-
11493
class Workspace(BaseEntity):
11594
name: str
11695
premium: bool
11796
admin: bool
118-
default_hourly_rate: float
97+
default_hourly_rate: Optional[float] = None
11998
default_currency: str
12099
only_admins_may_create_projects: bool
121100
only_admins_see_billable_rates: bool
@@ -124,6 +103,24 @@ class Workspace(BaseEntity):
124103
logo_url: Optional[HttpUrl] = None
125104

126105

106+
class User(BaseEntity):
107+
api_token: Optional[str] = None
108+
default_wid: Optional[int] = Field(alias="default_workspace_id", default=None)
109+
email: EmailStr
110+
fullname: str
111+
beginning_of_week: int = 0
112+
image_url: Optional[HttpUrl] = None
113+
openid_enabled: Optional[bool] = None
114+
timezone: Optional[str] = None
115+
country_id: Optional[int] = None
116+
projects: Optional[Project] = None
117+
tags: Optional[Tag] = None
118+
tasks: Optional[Task] = None
119+
time_entries: Optional[TimeEntry] = None
120+
updated_at: str
121+
workspaces: Optional[Workspace] = None
122+
123+
127124
class WorkspaceUser(BaseEntity):
128125
uid: int
129126
wid: int

toggl_python/repository.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,15 +106,14 @@ def additionat_method(
106106
if not self.DETAIL_URL:
107107
raise AttributeError("Not defined DETAIL_URL")
108108
_url = (self.DETAIL_URL + "/" + url).format(id=_id)
109-
return self._list(_url, entity, headers=self.HEADERS, param=params)
109+
return self._list(_url, entity, headers=self.HEADERS, param=params, data_key=data_key)
110110
elif single_item:
111-
_url = str(self.BASE_URL) + "/" + url
111+
_url = str(self.BASE_URL) + f"{url}"
112112
return self._retrieve(
113113
_url,
114114
entity,
115115
headers=self.HEADERS,
116116
params=params,
117-
data_key="data",
118117
)
119118
else:
120119
raise NotSupported
@@ -123,7 +122,7 @@ def _retrieve(
123122
self,
124123
_url: Union[str, httpx.URL],
125124
entity_class: Any,
126-
data_key: Optional[str] = "data",
125+
data_key: Optional[str] = None,
127126
**kwargs: Any,
128127
) -> Any:
129128
params = kwargs
@@ -229,7 +228,7 @@ class Tasks(BaseRepository):
229228

230229

231230
class TimeEntries(BaseRepository):
232-
LIST_URL = "time_entries"
231+
LIST_URL = "me/time_entries"
233232
ENTITY_CLASS = TimeEntry
234233

235234

@@ -259,7 +258,7 @@ class Workspaces(BaseRepository):
259258
"users": {"url": "users", "entity": User, "detail": False},
260259
"clients": {"url": "clients", "entity": Client, "detail": False},
261260
"groups": {"url": "groups", "entity": Group, "detail": False},
262-
"tasks": {"url": "tasks", "entity": Task, "detail": False},
261+
"tasks": {"url": "tasks", "entity": Task, "data_key": "data", "detail": False},
263262
"tags": {"url": "tags", "entity": Tag, "detail": False},
264263
"workspace_users": {
265264
"url": "workspace_users",

0 commit comments

Comments
 (0)