Skip to content

Commit 7bd89f9

Browse files
Update of API v3 vs v4.
1 parent e6b7f0c commit 7bd89f9

File tree

5 files changed

+115
-17
lines changed

5 files changed

+115
-17
lines changed

README.md

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# tempo-api-python-client
2+
23
Python bindings for Tempo Rest API.
34

4-
This is a Tempo API client library to simplify the interaction with Tempo timesheets.
5+
This is a Tempo API client library to simplify the interaction with Tempo timesheets. The implementation supports Tempo API v3 and v4.
56

67
Pip release is available: https://pypi.org/project/tempo-api-python-client/
78

@@ -21,21 +22,38 @@ pip install tempo-api-python-client
2122

2223
You need an API token for communicating with tempo REST APIs.
2324

24-
```
25-
from tempoapiclient import client
25+
For v3 use
2626

27-
tempo = client.Tempo(
28-
auth_token="<your_tempo_api_key>",
29-
base_url="https://api.tempo.io/core/3")
27+
from tempoapiclient import client_v3
3028

31-
worklogs = tempo.get_worklogs(
32-
dateFrom="2019-11-10",
33-
dateTo="2019-11-11"
34-
)
29+
tempo = client_v3.Tempo(
30+
auth_token="<your_tempo_api_key>",
31+
)
32+
33+
worklogs = tempo.get_worklogs(
34+
dateFrom="2019-11-10",
35+
dateTo="2019-11-11"
36+
)
37+
38+
for i in worklogs:
39+
print(i)
40+
41+
For v4 use
42+
43+
from tempoapiclient import client_v4
44+
45+
tempo = client_v4.Tempo(
46+
auth_token="<your_tempo_api_key>",
47+
)
48+
49+
worklogs = tempo.get_worklogs(
50+
dateFrom="2019-11-10",
51+
dateTo="2019-11-11"
52+
)
53+
54+
for i in worklogs:
55+
print(i)
3556

36-
for i in worklogs:
37-
print(i)
38-
```
3957

4058
There are also functions to retrieve `user` and `team`-specific worklogs.
4159

@@ -46,6 +64,7 @@ There are also functions to retrieve `user` and `team`-specific worklogs.
4664

4765
- Pylint: `pylint --max-line-length=120 tempoapiclient`
4866

67+
4968
## Contributing
5069

5170
Contribution is welcome. See [CONTRIBUTING.md](CONTRIBUTING.md) for more details.

tempoapiclient/client_v4.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from .rest_client import RestAPIClient
1919

2020

21-
class TempoV4(RestAPIClient):
21+
class Tempo(RestAPIClient):
2222
"""
2323
Basic Client for accessing Tempo Rest API as provided by api.tempo.io.
2424
"""
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,20 @@
22
import os
33
import sys
44

5-
from tempoapiclient import client
5+
from tempoapiclient.client_v3 import Tempo
66

77
# please set TEMPO_AUTH_TOKEN to environment before running this test
88

99

1010
class TestClient(TestCase):
1111

1212
def setUp(self):
13-
self.tempo = client.Tempo(auth_token=os.environ.get('TEMPO_AUTH_TOKEN'))
13+
self.tempo = Tempo(auth_token=os.environ.get('TEMPO_AUTH_TOKEN'))
1414
self.dateFrom = "2020-09-01"
1515
self.dateTo = "2020-10-01"
1616

1717
def test_client_creation(self):
18-
self.assertTrue(isinstance(self.tempo, client.Tempo))
18+
self.assertTrue(isinstance(self.tempo, Tempo))
1919
pass
2020

2121
def test_get_accounts(self):

tests/test_client_v4.py

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
from unittest import TestCase, main
2+
import os
3+
import sys
4+
5+
from tempoapiclient.client_v4 import Tempo
6+
7+
# please set TEMPO_AUTH_TOKEN to environment before running this test
8+
9+
10+
class TestClient(TestCase):
11+
12+
def setUp(self):
13+
self.tempo = Tempo(auth_token=os.environ.get('TEMPO_AUTH_TOKEN'))
14+
self.dateFrom = "2020-09-01"
15+
self.dateTo = "2020-10-01"
16+
17+
def test_client_creation(self):
18+
self.assertTrue(isinstance(self.tempo, Tempo))
19+
pass
20+
21+
def test_get_accounts(self):
22+
l = self.tempo.get_accounts()
23+
print("get_accounts: ", len(l))
24+
pass
25+
26+
def test_get_account_categories(self):
27+
l = self.tempo.get_account_categories()
28+
print("get_account_categories: ", len(l))
29+
pass
30+
31+
def test_get_account_category_types(self):
32+
l = self.tempo.get_account_category_types()
33+
print("get_account_category_types: ", len(l))
34+
35+
def test_get_customers(self):
36+
l = self.tempo.get_customers()
37+
print("get_customers: ", len(l))
38+
39+
def test_get_holiday_schemes(self):
40+
l = self.tempo.get_holiday_schemes()
41+
print("get_holiday_schemes: ", len(l))
42+
43+
def test_get_periods(self):
44+
l = self.tempo.get_periods(dateFrom=self.dateFrom, dateTo=self.dateTo)
45+
print("get_periods: ", len(l))
46+
47+
def test_get_plans(self):
48+
l = self.tempo.get_plans(dateFrom=self.dateFrom, dateTo=self.dateTo)
49+
print("get_plans: ", len(l))
50+
51+
def test_get_teams(self):
52+
l = self.tempo.get_teams()
53+
print("get_teams: ", len(l))
54+
55+
def test_get_team_members(self):
56+
team_id = [int(i['id']) for i in self.tempo.get_teams()][0]
57+
team_members = self.tempo.get_team_members(teamId=team_id)
58+
self.assertIsInstance(team_members, list)
59+
self.assertIsInstance(team_members[0], dict)
60+
self.assertIsInstance(team_members[0]['member'], dict)
61+
62+
#def test_get_team_memberships(self):
63+
# l = self.tempo.get_team_memberships(membershipId=)
64+
# display(l)
65+
66+
#def test_get_account_team_membership(self):
67+
# l = self.tempo.get_account_team_membership(teamId=1, accountId=8)
68+
# print("get_account_team_membership: ", len(l))
69+
70+
#def test_get_account_team_memberships(self):
71+
# l = self.tempo.get_account_team_memberships(teamId=1, accountId=8)
72+
# print("get_account_team_memberships: ", len(l))
73+
74+
def tearDown(self):
75+
self.tempo.close()
76+
77+
78+
if __name__ == "__main__":
79+
main()

0 commit comments

Comments
 (0)