noko 1.7.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGES.md +14 -0
- data/LICENSE.txt +1 -1
- data/README.md +1 -3
- data/lib/noko/client/account.rb +3 -5
- data/lib/noko/client/current_user.rb +12 -14
- data/lib/noko/client/entries.rb +43 -45
- data/lib/noko/client/expenses.rb +15 -17
- data/lib/noko/client/invoices.rb +35 -37
- data/lib/noko/client/project_groups.rb +21 -23
- data/lib/noko/client/projects.rb +51 -53
- data/lib/noko/client/tags.rb +31 -33
- data/lib/noko/client/teams.rb +43 -0
- data/lib/noko/client/timers.rb +21 -23
- data/lib/noko/client/users.rb +35 -37
- data/lib/noko/client/webhooks.rb +39 -41
- data/lib/noko/client.rb +48 -39
- data/lib/noko/link_header.rb +6 -10
- data/lib/noko/params.rb +12 -22
- data/lib/noko/record.rb +27 -23
- data/lib/noko/response.rb +31 -35
- data/lib/noko.rb +1 -0
- data/noko.gemspec +5 -2
- metadata +48 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 53d47e75f7bdd0e95aa8bc46eb113b6c77ab843a67779d607f80301858d3b7ae
|
4
|
+
data.tar.gz: e8ec80330855516418562ce5e07b67bb965bce7242aaa6be32167acbacc2a8fd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3b33dcf562a83582a1d9fdcbd9a4c3e5d0342e4157663b6d44cbf8d31983f3df4543bf3d17ddaf6d791bb3fec51a34d05d6bd374af796f4b46d48b2aeccba0c1
|
7
|
+
data.tar.gz: 3f70da92e422530ff8d668ff3e638d65715140caab87c01c163ddcb39d5c55f33e218d405bf25a2b1727e294759c8cfdc91e81f4107170e25028620dcd37cf98
|
data/CHANGES.md
CHANGED
@@ -1,3 +1,17 @@
|
|
1
|
+
# 2.0.0
|
2
|
+
|
3
|
+
* **Required ruby version is now 3.1.0**
|
4
|
+
|
5
|
+
* Added methods for team resources
|
6
|
+
|
7
|
+
* Added Noko::Record#inspect method
|
8
|
+
|
9
|
+
* Added support for personal access tokens in ~/.netrc
|
10
|
+
|
11
|
+
* Changed from cgi to uri for encoding query parameters
|
12
|
+
|
13
|
+
* Added dependencies on net/http, json, and uri gems
|
14
|
+
|
1
15
|
# 1.7.0
|
2
16
|
|
3
17
|
* Added methods for webhook endpoints (#7)
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
# noko
|
2
2
|
|
3
|
-
[](https://badge.fury.io/rb/noko)
|
4
|
-

|
5
|
-
|
3
|
+
[](https://badge.fury.io/rb/noko) [](https://github.com/timcraft/noko/actions/workflows/test.yml)
|
6
4
|
|
7
5
|
Ruby client for the [Noko API](https://developer.nokotime.com/v2/).
|
8
6
|
|
data/lib/noko/client/account.rb
CHANGED
@@ -1,21 +1,19 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
end
|
3
|
+
class Noko::Client
|
4
|
+
def get_current_user
|
5
|
+
get('/v2/current_user')
|
6
|
+
end
|
8
7
|
|
9
|
-
|
10
|
-
|
11
|
-
|
8
|
+
def get_current_user_entries(params = nil)
|
9
|
+
get('/v2/current_user/entries', params)
|
10
|
+
end
|
12
11
|
|
13
|
-
|
14
|
-
|
15
|
-
|
12
|
+
def get_current_user_expenses(params = nil)
|
13
|
+
get('/v2/current_user/expenses', params)
|
14
|
+
end
|
16
15
|
|
17
|
-
|
18
|
-
|
19
|
-
end
|
16
|
+
def update_current_user(attributes)
|
17
|
+
put('/v2/current_user', attributes)
|
20
18
|
end
|
21
19
|
end
|
data/lib/noko/client/entries.rb
CHANGED
@@ -1,49 +1,47 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
put('/v2/entries/unapproved', params)
|
47
|
-
end
|
3
|
+
class Noko::Client
|
4
|
+
def get_entries(params = nil)
|
5
|
+
get('/v2/entries', params)
|
6
|
+
end
|
7
|
+
|
8
|
+
def get_entry(id)
|
9
|
+
get("/v2/entries/#{id}")
|
10
|
+
end
|
11
|
+
|
12
|
+
def create_entry(attributes)
|
13
|
+
post('/v2/entries', attributes)
|
14
|
+
end
|
15
|
+
|
16
|
+
def update_entry(id, attributes)
|
17
|
+
put("/v2/entries/#{id}", attributes)
|
18
|
+
end
|
19
|
+
|
20
|
+
def delete_entry(id)
|
21
|
+
delete("/v2/entries/#{id}")
|
22
|
+
end
|
23
|
+
|
24
|
+
def mark_entry_invoiced(id, params)
|
25
|
+
put("/v2/entries/#{id}/marked_as_invoiced", params)
|
26
|
+
end
|
27
|
+
|
28
|
+
def mark_entries_invoiced(params)
|
29
|
+
put('/v2/entries/marked_as_invoiced', params)
|
30
|
+
end
|
31
|
+
|
32
|
+
def mark_entry_approved(id, params = nil)
|
33
|
+
put("/v2/entries/#{id}/approved", params)
|
34
|
+
end
|
35
|
+
|
36
|
+
def mark_entries_approved(params)
|
37
|
+
put('/v2/entries/approved', params)
|
38
|
+
end
|
39
|
+
|
40
|
+
def mark_entry_unapproved(id)
|
41
|
+
put("/v2/entries/#{id}/unapproved")
|
42
|
+
end
|
43
|
+
|
44
|
+
def mark_entries_unapproved(params)
|
45
|
+
put('/v2/entries/unapproved', params)
|
48
46
|
end
|
49
47
|
end
|
data/lib/noko/client/expenses.rb
CHANGED
@@ -1,25 +1,23 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
end
|
3
|
+
class Noko::Client
|
4
|
+
def get_expenses(params = nil)
|
5
|
+
get('/v2/expenses', params)
|
6
|
+
end
|
8
7
|
|
9
|
-
|
10
|
-
|
11
|
-
|
8
|
+
def get_expense(id)
|
9
|
+
get("/v2/expenses/#{id}")
|
10
|
+
end
|
12
11
|
|
13
|
-
|
14
|
-
|
15
|
-
|
12
|
+
def create_expense(attributes)
|
13
|
+
post('/v2/expenses', attributes)
|
14
|
+
end
|
16
15
|
|
17
|
-
|
18
|
-
|
19
|
-
|
16
|
+
def update_expense(id, attributes)
|
17
|
+
put("/v2/expenses/#{id}", attributes)
|
18
|
+
end
|
20
19
|
|
21
|
-
|
22
|
-
|
23
|
-
end
|
20
|
+
def delete_expense(id)
|
21
|
+
delete("/v2/expenses/#{id}")
|
24
22
|
end
|
25
23
|
end
|
data/lib/noko/client/invoices.rb
CHANGED
@@ -1,41 +1,39 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
delete("/v2/invoices/#{id}")
|
39
|
-
end
|
3
|
+
class Noko::Client
|
4
|
+
def get_invoices(params = nil)
|
5
|
+
get('/v2/invoices', params)
|
6
|
+
end
|
7
|
+
|
8
|
+
def get_invoice(id)
|
9
|
+
get("/v2/invoices/#{id}")
|
10
|
+
end
|
11
|
+
|
12
|
+
def create_invoice(attributes)
|
13
|
+
post('/v2/invoices', attributes)
|
14
|
+
end
|
15
|
+
|
16
|
+
def update_invoice(id, attributes)
|
17
|
+
put("/v2/invoices/#{id}", attributes)
|
18
|
+
end
|
19
|
+
|
20
|
+
def mark_invoice_paid(id)
|
21
|
+
put("/v2/invoices/#{id}/paid")
|
22
|
+
end
|
23
|
+
|
24
|
+
def mark_invoice_unpaid(id)
|
25
|
+
put("/v2/invoices/#{id}/unpaid")
|
26
|
+
end
|
27
|
+
|
28
|
+
def get_invoice_entries(id, params = nil)
|
29
|
+
get("/v2/invoices/#{id}/entries", params)
|
30
|
+
end
|
31
|
+
|
32
|
+
def get_invoice_expenses(id, params = nil)
|
33
|
+
get("/v2/invoices/#{id}/expenses", params)
|
34
|
+
end
|
35
|
+
|
36
|
+
def delete_invoice(id)
|
37
|
+
delete("/v2/invoices/#{id}")
|
40
38
|
end
|
41
39
|
end
|
@@ -1,33 +1,31 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
end
|
3
|
+
class Noko::Client
|
4
|
+
def get_project_groups(params = nil)
|
5
|
+
get('/v2/project_groups', params)
|
6
|
+
end
|
8
7
|
|
9
|
-
|
10
|
-
|
11
|
-
|
8
|
+
def get_project_group(id)
|
9
|
+
get("/v2/project_groups/#{id}")
|
10
|
+
end
|
12
11
|
|
13
|
-
|
14
|
-
|
15
|
-
|
12
|
+
def create_project_group(attributes)
|
13
|
+
post('/v2/project_groups', attributes)
|
14
|
+
end
|
16
15
|
|
17
|
-
|
18
|
-
|
19
|
-
|
16
|
+
def get_project_group_entries(id, params = nil)
|
17
|
+
get("/v2/project_groups/#{id}/entries", params)
|
18
|
+
end
|
20
19
|
|
21
|
-
|
22
|
-
|
23
|
-
|
20
|
+
def get_project_group_projects(id, params = nil)
|
21
|
+
get("/v2/project_groups/#{id}/projects", params)
|
22
|
+
end
|
24
23
|
|
25
|
-
|
26
|
-
|
27
|
-
|
24
|
+
def update_project_group(id, attributes)
|
25
|
+
put("/v2/project_groups/#{id}", attributes)
|
26
|
+
end
|
28
27
|
|
29
|
-
|
30
|
-
|
31
|
-
end
|
28
|
+
def delete_project_group(id)
|
29
|
+
delete("/v2/project_groups/#{id}")
|
32
30
|
end
|
33
31
|
end
|
data/lib/noko/client/projects.rb
CHANGED
@@ -1,57 +1,55 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
put('/v2/projects/delete', project_ids: project_ids)
|
55
|
-
end
|
3
|
+
class Noko::Client
|
4
|
+
def get_projects(params = nil)
|
5
|
+
get('/v2/projects', params)
|
6
|
+
end
|
7
|
+
|
8
|
+
def get_project(id)
|
9
|
+
get("/v2/projects/#{id}")
|
10
|
+
end
|
11
|
+
|
12
|
+
def create_project(attributes)
|
13
|
+
post('/v2/projects', attributes)
|
14
|
+
end
|
15
|
+
|
16
|
+
def get_project_entries(id, params = nil)
|
17
|
+
get("/v2/projects/#{id}/entries", params)
|
18
|
+
end
|
19
|
+
|
20
|
+
def get_project_expenses(id, params = nil)
|
21
|
+
get("/v2/projects/#{id}/expenses", params)
|
22
|
+
end
|
23
|
+
|
24
|
+
def update_project(id, attributes)
|
25
|
+
put("/v2/projects/#{id}", attributes)
|
26
|
+
end
|
27
|
+
|
28
|
+
def merge_projects(id, project_id)
|
29
|
+
put("/v2/projects/#{id}/merge", project_id: project_id)
|
30
|
+
end
|
31
|
+
|
32
|
+
def delete_project(id)
|
33
|
+
delete("/v2/projects/#{id}")
|
34
|
+
end
|
35
|
+
|
36
|
+
def archive_project(id)
|
37
|
+
put("/v2/projects/#{id}/archive")
|
38
|
+
end
|
39
|
+
|
40
|
+
def unarchive_project(id)
|
41
|
+
put("/v2/projects/#{id}/unarchive")
|
42
|
+
end
|
43
|
+
|
44
|
+
def archive_projects(project_ids)
|
45
|
+
put('/v2/projects/archive', project_ids: project_ids)
|
46
|
+
end
|
47
|
+
|
48
|
+
def unarchive_projects(project_ids)
|
49
|
+
put('/v2/projects/unarchive', project_ids: project_ids)
|
50
|
+
end
|
51
|
+
|
52
|
+
def delete_projects(project_ids)
|
53
|
+
put('/v2/projects/delete', project_ids: project_ids)
|
56
54
|
end
|
57
55
|
end
|
data/lib/noko/client/tags.rb
CHANGED
@@ -1,37 +1,35 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
put('/v2/tags/delete', tag_ids: tag_ids)
|
35
|
-
end
|
3
|
+
class Noko::Client
|
4
|
+
def get_tags(params = nil)
|
5
|
+
get('/v2/tags', params)
|
6
|
+
end
|
7
|
+
|
8
|
+
def create_tags(names)
|
9
|
+
post('/v2/tags', names: names)
|
10
|
+
end
|
11
|
+
|
12
|
+
def get_tag(id)
|
13
|
+
get("/v2/tags/#{id}")
|
14
|
+
end
|
15
|
+
|
16
|
+
def get_tag_entries(id, params = nil)
|
17
|
+
get("/v2/tags/#{id}/entries", params)
|
18
|
+
end
|
19
|
+
|
20
|
+
def update_tag(id, attributes)
|
21
|
+
put("/v2/tags/#{id}", attributes)
|
22
|
+
end
|
23
|
+
|
24
|
+
def merge_tags(id, tag_id)
|
25
|
+
put("/v2/tags/#{id}/merge", tag_id: tag_id)
|
26
|
+
end
|
27
|
+
|
28
|
+
def delete_tag(id)
|
29
|
+
delete("/v2/tags/#{id}")
|
30
|
+
end
|
31
|
+
|
32
|
+
def delete_tags(tag_ids)
|
33
|
+
put('/v2/tags/delete', tag_ids: tag_ids)
|
36
34
|
end
|
37
35
|
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Noko::Client
|
4
|
+
def get_teams(params = nil)
|
5
|
+
get('/v2/teams', params)
|
6
|
+
end
|
7
|
+
|
8
|
+
def get_team(id)
|
9
|
+
get("/v2/teams/#{id}")
|
10
|
+
end
|
11
|
+
|
12
|
+
def create_team(attributes)
|
13
|
+
post('/v2/teams', attributes)
|
14
|
+
end
|
15
|
+
|
16
|
+
def update_team(id, attributes)
|
17
|
+
put("/v2/teams/#{id}", attributes)
|
18
|
+
end
|
19
|
+
|
20
|
+
def get_team_entries(id, params = nil)
|
21
|
+
get("/v2/teams/#{id}/entries", params)
|
22
|
+
end
|
23
|
+
|
24
|
+
def get_team_users(id, params = nil)
|
25
|
+
get("/v2/teams/#{id}/users", params)
|
26
|
+
end
|
27
|
+
|
28
|
+
def add_team_users(id, params)
|
29
|
+
post("/v2/teams/#{id}/add_users", params)
|
30
|
+
end
|
31
|
+
|
32
|
+
def remove_team_users(id, params)
|
33
|
+
put("/v2/teams/#{id}/remove_users", params)
|
34
|
+
end
|
35
|
+
|
36
|
+
def remove_all_team_users(id)
|
37
|
+
put("/v2/teams/#{id}/remove_all_users")
|
38
|
+
end
|
39
|
+
|
40
|
+
def delete_team(id)
|
41
|
+
delete("/v2/teams/#{id}")
|
42
|
+
end
|
43
|
+
end
|
data/lib/noko/client/timers.rb
CHANGED
@@ -1,33 +1,31 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
end
|
3
|
+
class Noko::Client
|
4
|
+
def get_timers(params = nil)
|
5
|
+
get('/v2/timers', params)
|
6
|
+
end
|
8
7
|
|
9
|
-
|
10
|
-
|
11
|
-
|
8
|
+
def get_timer(project_id)
|
9
|
+
get("/v2/projects/#{project_id}/timer")
|
10
|
+
end
|
12
11
|
|
13
|
-
|
14
|
-
|
15
|
-
|
12
|
+
def update_timer(project_id, attributes)
|
13
|
+
put("/v2/projects/#{project_id}/timer", attributes)
|
14
|
+
end
|
16
15
|
|
17
|
-
|
18
|
-
|
19
|
-
|
16
|
+
def start_timer(project_id)
|
17
|
+
put("/v2/projects/#{project_id}/timer/start")
|
18
|
+
end
|
20
19
|
|
21
|
-
|
22
|
-
|
23
|
-
|
20
|
+
def pause_timer(project_id)
|
21
|
+
put("/v2/projects/#{project_id}/timer/pause")
|
22
|
+
end
|
24
23
|
|
25
|
-
|
26
|
-
|
27
|
-
|
24
|
+
def log_timer(project_id, attributes = {})
|
25
|
+
put("/v2/projects/#{project_id}/timer/log", attributes)
|
26
|
+
end
|
28
27
|
|
29
|
-
|
30
|
-
|
31
|
-
end
|
28
|
+
def discard_timer(project_id)
|
29
|
+
delete("/v2/projects/#{project_id}/timer")
|
32
30
|
end
|
33
31
|
end
|
data/lib/noko/client/users.rb
CHANGED
@@ -1,41 +1,39 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
put("/v2/users/#{id}/deactivate")
|
39
|
-
end
|
3
|
+
class Noko::Client
|
4
|
+
def get_users(params = nil)
|
5
|
+
get('/v2/users', params)
|
6
|
+
end
|
7
|
+
|
8
|
+
def get_user(id)
|
9
|
+
get("/v2/users/#{id}")
|
10
|
+
end
|
11
|
+
|
12
|
+
def get_user_entries(id, params = nil)
|
13
|
+
get("/v2/users/#{id}/entries", params)
|
14
|
+
end
|
15
|
+
|
16
|
+
def get_user_expenses(id, params = nil)
|
17
|
+
get("/v2/users/#{id}/expenses", params)
|
18
|
+
end
|
19
|
+
|
20
|
+
def create_user(attributes)
|
21
|
+
post('/v2/users', attributes)
|
22
|
+
end
|
23
|
+
|
24
|
+
def update_user(id, attributes)
|
25
|
+
put("/v2/users/#{id}", attributes)
|
26
|
+
end
|
27
|
+
|
28
|
+
def delete_user(id)
|
29
|
+
delete("/v2/users/#{id}")
|
30
|
+
end
|
31
|
+
|
32
|
+
def reactivate_user(id)
|
33
|
+
put("/v2/users/#{id}/activate")
|
34
|
+
end
|
35
|
+
|
36
|
+
def deactivate_user(id)
|
37
|
+
put("/v2/users/#{id}/deactivate")
|
40
38
|
end
|
41
39
|
end
|
data/lib/noko/client/webhooks.rb
CHANGED
@@ -1,43 +1,41 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
delete("/v2/webhooks/#{id}")
|
41
|
-
end
|
1
|
+
class Noko::Client
|
2
|
+
def get_webhooks(params = nil)
|
3
|
+
get('/v2/webhooks', params)
|
4
|
+
end
|
5
|
+
|
6
|
+
def get_webhook(id)
|
7
|
+
get("/v2/webhooks/#{id}")
|
8
|
+
end
|
9
|
+
|
10
|
+
def create_webhook(attributes)
|
11
|
+
post('/v2/webhooks', attributes)
|
12
|
+
end
|
13
|
+
|
14
|
+
def update_webhook(id, attributes)
|
15
|
+
put("/v2/webhooks/#{id}", attributes)
|
16
|
+
end
|
17
|
+
|
18
|
+
def add_webhook_events(id, attributes)
|
19
|
+
put("/v2/webhooks/#{id}/add_events", attributes)
|
20
|
+
end
|
21
|
+
|
22
|
+
def remove_webhook_events(id, attributes)
|
23
|
+
put("/v2/webhooks/#{id}/remove_events", attributes)
|
24
|
+
end
|
25
|
+
|
26
|
+
def reroll_webhook_secret(id)
|
27
|
+
put("/v2/webhooks/#{id}/reroll_secret")
|
28
|
+
end
|
29
|
+
|
30
|
+
def disable_webhook(id)
|
31
|
+
put("/v2/webhooks/#{id}/disable")
|
32
|
+
end
|
33
|
+
|
34
|
+
def enable_webhook(id)
|
35
|
+
put("/v2/webhooks/#{id}/enable")
|
36
|
+
end
|
37
|
+
|
38
|
+
def delete_webhook(id)
|
39
|
+
delete("/v2/webhooks/#{id}")
|
42
40
|
end
|
43
41
|
end
|
data/lib/noko/client.rb
CHANGED
@@ -8,58 +8,67 @@ require 'noko/response'
|
|
8
8
|
require 'net/http'
|
9
9
|
require 'json'
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
11
|
+
class Noko::Client
|
12
|
+
def initialize(options = {})
|
13
|
+
if options.key?(:access_token)
|
14
|
+
@auth_header, @auth_value = 'Authorization', "token #{options[:access_token]}"
|
15
|
+
elsif options.key?(:token)
|
16
|
+
@auth_header, @auth_value = 'X-NokoToken', options.fetch(:token)
|
17
|
+
elsif !(netrc = load_netrc_credentials).nil?
|
18
|
+
@auth_header, @auth_value = 'X-NokoToken', netrc.password
|
19
|
+
else
|
20
|
+
raise ArgumentError, 'access_token or token required for authentication'
|
21
|
+
end
|
19
22
|
|
20
|
-
|
23
|
+
@user_agent = options.fetch(:user_agent) { "noko/#{Noko::VERSION} ruby/#{RUBY_VERSION}" }
|
21
24
|
|
22
|
-
|
25
|
+
@host = 'api.nokotime.com'
|
23
26
|
|
24
|
-
|
27
|
+
@http = Net::HTTP.new(@host, Net::HTTP.https_default_port)
|
25
28
|
|
26
|
-
|
27
|
-
|
29
|
+
@http.use_ssl = true
|
30
|
+
end
|
28
31
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
+
def get(path, params = nil)
|
33
|
+
request(Net::HTTP::Get.new(Noko::Params.join(path, params)))
|
34
|
+
end
|
32
35
|
|
33
|
-
|
36
|
+
private
|
34
37
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
+
def post(path, attributes)
|
39
|
+
request(Net::HTTP::Post.new(path), attributes)
|
40
|
+
end
|
38
41
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
+
def put(path, attributes = nil)
|
43
|
+
request(Net::HTTP::Put.new(path), attributes)
|
44
|
+
end
|
42
45
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
+
def delete(path)
|
47
|
+
request(Net::HTTP::Delete.new(path))
|
48
|
+
end
|
46
49
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
+
def request(http_request, body_object = nil)
|
51
|
+
http_request['User-Agent'] = @user_agent
|
52
|
+
http_request[@auth_header] = @auth_value
|
50
53
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
54
|
+
if body_object
|
55
|
+
http_request['Content-Type'] = 'application/json'
|
56
|
+
http_request.body = JSON.generate(body_object)
|
57
|
+
end
|
55
58
|
|
56
|
-
|
59
|
+
response = @http.request(http_request)
|
57
60
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
end
|
61
|
+
if response.is_a?(Net::HTTPSuccess)
|
62
|
+
Noko::Response.parse(response)
|
63
|
+
else
|
64
|
+
raise Noko::Response.error(response)
|
63
65
|
end
|
64
66
|
end
|
67
|
+
|
68
|
+
def load_netrc_credentials
|
69
|
+
require 'net/netrc'
|
70
|
+
|
71
|
+
Net::Netrc.locate('api.nokotime.com')
|
72
|
+
rescue LoadError
|
73
|
+
end
|
65
74
|
end
|
data/lib/noko/link_header.rb
CHANGED
@@ -1,18 +1,14 @@
|
|
1
1
|
require 'noko/record'
|
2
2
|
require 'uri'
|
3
3
|
|
4
|
-
module Noko
|
5
|
-
|
6
|
-
extend self
|
4
|
+
module Noko::LinkHeader
|
5
|
+
extend self
|
7
6
|
|
8
|
-
|
7
|
+
REGEXP = /<([^>]+)>; rel="(\w+)"/
|
9
8
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
end
|
9
|
+
def parse(string)
|
10
|
+
string.scan(REGEXP).each_with_object(Noko::Record.new) do |(uri, rel), record|
|
11
|
+
record[rel.to_sym] = URI.parse(uri).request_uri
|
14
12
|
end
|
15
13
|
end
|
16
|
-
|
17
|
-
private_constant :LinkHeader
|
18
14
|
end
|
data/lib/noko/params.rb
CHANGED
@@ -1,30 +1,20 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
require '
|
2
|
+
require 'uri'
|
3
3
|
|
4
|
-
module Noko
|
5
|
-
|
6
|
-
extend self
|
4
|
+
module Noko::Params
|
5
|
+
extend self
|
7
6
|
|
8
|
-
|
9
|
-
|
7
|
+
def join(path, params = nil)
|
8
|
+
return path if params.nil? || params.empty?
|
10
9
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
def encode(params)
|
15
|
-
params.map { |k, v| "#{escape(k)}=#{array_escape(v)}" }.join('&')
|
16
|
-
end
|
17
|
-
|
18
|
-
private
|
19
|
-
|
20
|
-
def array_escape(object)
|
21
|
-
Array(object).map { |value| escape(value) }.join(',')
|
22
|
-
end
|
10
|
+
path + '?' + encode(params)
|
11
|
+
end
|
23
12
|
|
24
|
-
|
25
|
-
|
26
|
-
end
|
13
|
+
def encode(params)
|
14
|
+
params.map { |k, v| escape(k) + '=' + Array(v).map { escape(_1) }.join(',') }.join('&')
|
27
15
|
end
|
28
16
|
|
29
|
-
|
17
|
+
def escape(value)
|
18
|
+
URI.encode_uri_component(value)
|
19
|
+
end
|
30
20
|
end
|
data/lib/noko/record.rb
CHANGED
@@ -1,31 +1,35 @@
|
|
1
|
-
|
2
|
-
class Record
|
3
|
-
def initialize(attributes = {})
|
4
|
-
@attributes = attributes
|
5
|
-
end
|
1
|
+
# frozen_string_literal: true
|
6
2
|
|
7
|
-
|
8
|
-
|
9
|
-
|
3
|
+
class Noko::Record
|
4
|
+
def initialize(attributes = {})
|
5
|
+
@attributes = attributes
|
6
|
+
end
|
10
7
|
|
11
|
-
|
12
|
-
|
13
|
-
|
8
|
+
def [](name)
|
9
|
+
@attributes[name]
|
10
|
+
end
|
14
11
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
else
|
19
|
-
super name, *args, &block
|
20
|
-
end
|
21
|
-
end
|
12
|
+
def []=(name, value)
|
13
|
+
@attributes[name] = value
|
14
|
+
end
|
22
15
|
|
23
|
-
|
24
|
-
|
25
|
-
|
16
|
+
def inspect
|
17
|
+
'#<' + self.class.name + ' ' + @attributes.map { "#{_1}=#{_2.inspect}" }.join(', ') + '>'
|
18
|
+
end
|
26
19
|
|
27
|
-
|
28
|
-
|
20
|
+
def method_missing(name, *args, &block)
|
21
|
+
if @attributes.key?(name) && args.empty? && block.nil?
|
22
|
+
return @attributes[name]
|
23
|
+
else
|
24
|
+
super name, *args, &block
|
29
25
|
end
|
30
26
|
end
|
27
|
+
|
28
|
+
def respond_to_missing?(name, include_private = false)
|
29
|
+
@attributes.key?(name)
|
30
|
+
end
|
31
|
+
|
32
|
+
def to_h
|
33
|
+
@attributes
|
34
|
+
end
|
31
35
|
end
|
data/lib/noko/response.rb
CHANGED
@@ -2,51 +2,47 @@
|
|
2
2
|
require 'net/http'
|
3
3
|
require 'json'
|
4
4
|
|
5
|
-
module Noko
|
6
|
-
|
7
|
-
extend self
|
5
|
+
module Noko::Response
|
6
|
+
extend self
|
8
7
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
if response.content_type == 'application/json'
|
15
|
-
object = JSON.parse(response.body, symbolize_names: true, object_class: Record)
|
8
|
+
def parse(response)
|
9
|
+
if response.is_a?(Net::HTTPNoContent)
|
10
|
+
return :no_content
|
11
|
+
end
|
16
12
|
|
17
|
-
|
18
|
-
|
19
|
-
object.link = LinkHeader.parse(response['Link'])
|
20
|
-
end
|
13
|
+
if response.content_type == 'application/json'
|
14
|
+
object = JSON.parse(response.body, symbolize_names: true, object_class: Noko::Record)
|
21
15
|
|
22
|
-
|
16
|
+
if response['Link']
|
17
|
+
object.singleton_class.module_eval { attr_accessor :link }
|
18
|
+
object.link = Noko::LinkHeader.parse(response['Link'])
|
23
19
|
end
|
24
20
|
|
25
|
-
|
21
|
+
return object
|
26
22
|
end
|
27
23
|
|
28
|
-
|
29
|
-
|
30
|
-
body = JSON.parse(response.body)
|
24
|
+
response.body
|
25
|
+
end
|
31
26
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
end
|
36
|
-
end
|
27
|
+
def error(response)
|
28
|
+
if response.content_type == 'application/json'
|
29
|
+
body = JSON.parse(response.body)
|
37
30
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
when Net::HTTPUnauthorized then Noko::AuthenticationError
|
42
|
-
when Net::HTTPNotFound then Noko::NotFound
|
43
|
-
when Net::HTTPClientError then Noko::ClientError
|
44
|
-
when Net::HTTPServerError then Noko::ServerError
|
45
|
-
else
|
46
|
-
Noko::Error
|
47
|
-
end
|
31
|
+
error_class(response).new(body['message'])
|
32
|
+
else
|
33
|
+
error_class(response)
|
48
34
|
end
|
49
35
|
end
|
50
36
|
|
51
|
-
|
37
|
+
def error_class(object)
|
38
|
+
case object
|
39
|
+
when Net::HTTPBadRequest then Noko::ClientError
|
40
|
+
when Net::HTTPUnauthorized then Noko::AuthenticationError
|
41
|
+
when Net::HTTPNotFound then Noko::NotFound
|
42
|
+
when Net::HTTPClientError then Noko::ClientError
|
43
|
+
when Net::HTTPServerError then Noko::ServerError
|
44
|
+
else
|
45
|
+
Noko::Error
|
46
|
+
end
|
47
|
+
end
|
52
48
|
end
|
data/lib/noko.rb
CHANGED
data/noko.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'noko'
|
3
|
-
s.version = '
|
3
|
+
s.version = '2.0.0'
|
4
4
|
s.license = 'MIT'
|
5
5
|
s.platform = Gem::Platform::RUBY
|
6
6
|
s.authors = ['Tim Craft']
|
@@ -9,7 +9,7 @@ Gem::Specification.new do |s|
|
|
9
9
|
s.description = 'Ruby client for the Noko API'
|
10
10
|
s.summary = 'See description'
|
11
11
|
s.files = Dir.glob('lib/**/*.rb') + %w(CHANGES.md LICENSE.txt README.md noko.gemspec)
|
12
|
-
s.required_ruby_version = '>= 1.
|
12
|
+
s.required_ruby_version = '>= 3.1.0'
|
13
13
|
s.require_path = 'lib'
|
14
14
|
s.metadata = {
|
15
15
|
'homepage' => 'https://github.com/timcraft/noko',
|
@@ -17,4 +17,7 @@ Gem::Specification.new do |s|
|
|
17
17
|
'bug_tracker_uri' => 'https://github.com/timcraft/noko/issues',
|
18
18
|
'changelog_uri' => 'https://github.com/timcraft/noko/blob/main/CHANGES.md'
|
19
19
|
}
|
20
|
+
s.add_dependency 'net-http'
|
21
|
+
s.add_dependency 'json', '~> 2'
|
22
|
+
s.add_dependency 'uri', '~> 1'
|
20
23
|
end
|
metadata
CHANGED
@@ -1,15 +1,57 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: noko
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tim Craft
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
12
|
-
dependencies:
|
11
|
+
date: 2024-12-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: net-http
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: json
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: uri
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1'
|
13
55
|
description: Ruby client for the Noko API
|
14
56
|
email:
|
15
57
|
- mail@timcraft.com
|
@@ -30,6 +72,7 @@ files:
|
|
30
72
|
- lib/noko/client/project_groups.rb
|
31
73
|
- lib/noko/client/projects.rb
|
32
74
|
- lib/noko/client/tags.rb
|
75
|
+
- lib/noko/client/teams.rb
|
33
76
|
- lib/noko/client/timers.rb
|
34
77
|
- lib/noko/client/users.rb
|
35
78
|
- lib/noko/client/webhooks.rb
|
@@ -56,14 +99,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
56
99
|
requirements:
|
57
100
|
- - ">="
|
58
101
|
- !ruby/object:Gem::Version
|
59
|
-
version: 1.
|
102
|
+
version: 3.1.0
|
60
103
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
104
|
requirements:
|
62
105
|
- - ">="
|
63
106
|
- !ruby/object:Gem::Version
|
64
107
|
version: '0'
|
65
108
|
requirements: []
|
66
|
-
rubygems_version: 3.
|
109
|
+
rubygems_version: 3.5.22
|
67
110
|
signing_key:
|
68
111
|
specification_version: 4
|
69
112
|
summary: See description
|