noko 1.6.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1ff0fcc7691e060653275c30cdfb02fd4e19da5ee2f4e1468c6935f26d0c3454
4
- data.tar.gz: 622da78be984693f095e5f931c32a52606d1a1cd8f440e53025251c20ebe3f4b
3
+ metadata.gz: 53d47e75f7bdd0e95aa8bc46eb113b6c77ab843a67779d607f80301858d3b7ae
4
+ data.tar.gz: e8ec80330855516418562ce5e07b67bb965bce7242aaa6be32167acbacc2a8fd
5
5
  SHA512:
6
- metadata.gz: 63232176cc36783f3891245dcc44a0ee800312038ae904216cc7f219533d2ce4df9382acc80b5b2f1b8bfc722aa29f924e8efda411e8281c912ca78f32cebbcf
7
- data.tar.gz: bcb26ccd331dbc71c88193aba038c5f1c06272c0c93590d11486229bf77fdfb795010aa05d18d93b3bd8cdceff51b922bc4b52ad69cd5f6cf8c7c7a9e83d0701
6
+ metadata.gz: 3b33dcf562a83582a1d9fdcbd9a4c3e5d0342e4157663b6d44cbf8d31983f3df4543bf3d17ddaf6d791bb3fec51a34d05d6bd374af796f4b46d48b2aeccba0c1
7
+ data.tar.gz: 3f70da92e422530ff8d668ff3e638d65715140caab87c01c163ddcb39d5c55f33e218d405bf25a2b1727e294759c8cfdc91e81f4107170e25028620dcd37cf98
data/CHANGES.md CHANGED
@@ -1,3 +1,23 @@
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
+
15
+ # 1.7.0
16
+
17
+ * Added methods for webhook endpoints (#7)
18
+
19
+ * Fixed outdated changelog_uri
20
+
1
21
  # 1.6.0
2
22
 
3
23
  * Added Noko::NotFound for 404 responses
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2015-2020 TIMCRAFT
1
+ Copyright (c) 2015-2024 TIMCRAFT
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person
4
4
  obtaining a copy of this software and associated documentation
data/README.md CHANGED
@@ -1,8 +1,6 @@
1
1
  # noko
2
2
 
3
- [![Gem Version](https://badge.fury.io/rb/noko.svg)](https://badge.fury.io/rb/noko)
4
- ![Build Status](https://github.com/timcraft/noko/workflows/Test/badge.svg)
5
-
3
+ [![Gem Version](https://badge.fury.io/rb/noko.svg)](https://badge.fury.io/rb/noko) [![Test Status](https://github.com/timcraft/noko/actions/workflows/test.yml/badge.svg)](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
 
@@ -1,9 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Noko
4
- class Client
5
- def get_account
6
- get('/v2/account')
7
- end
3
+ class Noko::Client
4
+ def get_account
5
+ get('/v2/account')
8
6
  end
9
7
  end
@@ -1,21 +1,19 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Noko
4
- class Client
5
- def get_current_user
6
- get('/v2/current_user')
7
- end
3
+ class Noko::Client
4
+ def get_current_user
5
+ get('/v2/current_user')
6
+ end
8
7
 
9
- def get_current_user_entries(params = nil)
10
- get('/v2/current_user/entries', params)
11
- end
8
+ def get_current_user_entries(params = nil)
9
+ get('/v2/current_user/entries', params)
10
+ end
12
11
 
13
- def get_current_user_expenses(params = nil)
14
- get('/v2/current_user/expenses', params)
15
- end
12
+ def get_current_user_expenses(params = nil)
13
+ get('/v2/current_user/expenses', params)
14
+ end
16
15
 
17
- def update_current_user(attributes)
18
- put('/v2/current_user', attributes)
19
- end
16
+ def update_current_user(attributes)
17
+ put('/v2/current_user', attributes)
20
18
  end
21
19
  end
@@ -1,49 +1,47 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Noko
4
- class Client
5
- def get_entries(params = nil)
6
- get('/v2/entries', params)
7
- end
8
-
9
- def get_entry(id)
10
- get("/v2/entries/#{id}")
11
- end
12
-
13
- def create_entry(attributes)
14
- post('/v2/entries', attributes)
15
- end
16
-
17
- def update_entry(id, attributes)
18
- put("/v2/entries/#{id}", attributes)
19
- end
20
-
21
- def delete_entry(id)
22
- delete("/v2/entries/#{id}")
23
- end
24
-
25
- def mark_entry_invoiced(id, params)
26
- put("/v2/entries/#{id}/marked_as_invoiced", params)
27
- end
28
-
29
- def mark_entries_invoiced(params)
30
- put('/v2/entries/marked_as_invoiced', params)
31
- end
32
-
33
- def mark_entry_approved(id, params = nil)
34
- put("/v2/entries/#{id}/approved", params)
35
- end
36
-
37
- def mark_entries_approved(params)
38
- put('/v2/entries/approved', params)
39
- end
40
-
41
- def mark_entry_unapproved(id)
42
- put("/v2/entries/#{id}/unapproved")
43
- end
44
-
45
- def mark_entries_unapproved(params)
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
@@ -1,25 +1,23 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Noko
4
- class Client
5
- def get_expenses(params = nil)
6
- get('/v2/expenses', params)
7
- end
3
+ class Noko::Client
4
+ def get_expenses(params = nil)
5
+ get('/v2/expenses', params)
6
+ end
8
7
 
9
- def get_expense(id)
10
- get("/v2/expenses/#{id}")
11
- end
8
+ def get_expense(id)
9
+ get("/v2/expenses/#{id}")
10
+ end
12
11
 
13
- def create_expense(attributes)
14
- post('/v2/expenses', attributes)
15
- end
12
+ def create_expense(attributes)
13
+ post('/v2/expenses', attributes)
14
+ end
16
15
 
17
- def update_expense(id, attributes)
18
- put("/v2/expenses/#{id}", attributes)
19
- end
16
+ def update_expense(id, attributes)
17
+ put("/v2/expenses/#{id}", attributes)
18
+ end
20
19
 
21
- def delete_expense(id)
22
- delete("/v2/expenses/#{id}")
23
- end
20
+ def delete_expense(id)
21
+ delete("/v2/expenses/#{id}")
24
22
  end
25
23
  end
@@ -1,41 +1,39 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Noko
4
- class Client
5
- def get_invoices(params = nil)
6
- get('/v2/invoices', params)
7
- end
8
-
9
- def get_invoice(id)
10
- get("/v2/invoices/#{id}")
11
- end
12
-
13
- def create_invoice(attributes)
14
- post('/v2/invoices', attributes)
15
- end
16
-
17
- def update_invoice(id, attributes)
18
- put("/v2/invoices/#{id}", attributes)
19
- end
20
-
21
- def mark_invoice_paid(id)
22
- put("/v2/invoices/#{id}/paid")
23
- end
24
-
25
- def mark_invoice_unpaid(id)
26
- put("/v2/invoices/#{id}/unpaid")
27
- end
28
-
29
- def get_invoice_entries(id, params = nil)
30
- get("/v2/invoices/#{id}/entries", params)
31
- end
32
-
33
- def get_invoice_expenses(id, params = nil)
34
- get("/v2/invoices/#{id}/expenses", params)
35
- end
36
-
37
- def delete_invoice(id)
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
- module Noko
4
- class Client
5
- def get_project_groups(params = nil)
6
- get('/v2/project_groups', params)
7
- end
3
+ class Noko::Client
4
+ def get_project_groups(params = nil)
5
+ get('/v2/project_groups', params)
6
+ end
8
7
 
9
- def get_project_group(id)
10
- get("/v2/project_groups/#{id}")
11
- end
8
+ def get_project_group(id)
9
+ get("/v2/project_groups/#{id}")
10
+ end
12
11
 
13
- def create_project_group(attributes)
14
- post('/v2/project_groups', attributes)
15
- end
12
+ def create_project_group(attributes)
13
+ post('/v2/project_groups', attributes)
14
+ end
16
15
 
17
- def get_project_group_entries(id, params = nil)
18
- get("/v2/project_groups/#{id}/entries", params)
19
- end
16
+ def get_project_group_entries(id, params = nil)
17
+ get("/v2/project_groups/#{id}/entries", params)
18
+ end
20
19
 
21
- def get_project_group_projects(id, params = nil)
22
- get("/v2/project_groups/#{id}/projects", params)
23
- end
20
+ def get_project_group_projects(id, params = nil)
21
+ get("/v2/project_groups/#{id}/projects", params)
22
+ end
24
23
 
25
- def update_project_group(id, attributes)
26
- put("/v2/project_groups/#{id}", attributes)
27
- end
24
+ def update_project_group(id, attributes)
25
+ put("/v2/project_groups/#{id}", attributes)
26
+ end
28
27
 
29
- def delete_project_group(id)
30
- delete("/v2/project_groups/#{id}")
31
- end
28
+ def delete_project_group(id)
29
+ delete("/v2/project_groups/#{id}")
32
30
  end
33
31
  end
@@ -1,57 +1,55 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Noko
4
- class Client
5
- def get_projects(params = nil)
6
- get('/v2/projects', params)
7
- end
8
-
9
- def get_project(id)
10
- get("/v2/projects/#{id}")
11
- end
12
-
13
- def create_project(attributes)
14
- post('/v2/projects', attributes)
15
- end
16
-
17
- def get_project_entries(id, params = nil)
18
- get("/v2/projects/#{id}/entries", params)
19
- end
20
-
21
- def get_project_expenses(id, params = nil)
22
- get("/v2/projects/#{id}/expenses", params)
23
- end
24
-
25
- def update_project(id, attributes)
26
- put("/v2/projects/#{id}", attributes)
27
- end
28
-
29
- def merge_projects(id, project_id)
30
- put("/v2/projects/#{id}/merge", project_id: project_id)
31
- end
32
-
33
- def delete_project(id)
34
- delete("/v2/projects/#{id}")
35
- end
36
-
37
- def archive_project(id)
38
- put("/v2/projects/#{id}/archive")
39
- end
40
-
41
- def unarchive_project(id)
42
- put("/v2/projects/#{id}/unarchive")
43
- end
44
-
45
- def archive_projects(project_ids)
46
- put('/v2/projects/archive', project_ids: project_ids)
47
- end
48
-
49
- def unarchive_projects(project_ids)
50
- put('/v2/projects/unarchive', project_ids: project_ids)
51
- end
52
-
53
- def delete_projects(project_ids)
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
@@ -1,37 +1,35 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Noko
4
- class Client
5
- def get_tags(params = nil)
6
- get('/v2/tags', params)
7
- end
8
-
9
- def create_tags(names)
10
- post('/v2/tags', names: names)
11
- end
12
-
13
- def get_tag(id)
14
- get("/v2/tags/#{id}")
15
- end
16
-
17
- def get_tag_entries(id, params = nil)
18
- get("/v2/tags/#{id}/entries", params)
19
- end
20
-
21
- def update_tag(id, attributes)
22
- put("/v2/tags/#{id}", attributes)
23
- end
24
-
25
- def merge_tags(id, tag_id)
26
- put("/v2/tags/#{id}/merge", tag_id: tag_id)
27
- end
28
-
29
- def delete_tag(id)
30
- delete("/v2/tags/#{id}")
31
- end
32
-
33
- def delete_tags(tag_ids)
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
@@ -1,33 +1,31 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Noko
4
- class Client
5
- def get_timers(params = nil)
6
- get('/v2/timers', params)
7
- end
3
+ class Noko::Client
4
+ def get_timers(params = nil)
5
+ get('/v2/timers', params)
6
+ end
8
7
 
9
- def get_timer(project_id)
10
- get("/v2/projects/#{project_id}/timer")
11
- end
8
+ def get_timer(project_id)
9
+ get("/v2/projects/#{project_id}/timer")
10
+ end
12
11
 
13
- def update_timer(project_id, attributes)
14
- put("/v2/projects/#{project_id}/timer", attributes)
15
- end
12
+ def update_timer(project_id, attributes)
13
+ put("/v2/projects/#{project_id}/timer", attributes)
14
+ end
16
15
 
17
- def start_timer(project_id)
18
- put("/v2/projects/#{project_id}/timer/start")
19
- end
16
+ def start_timer(project_id)
17
+ put("/v2/projects/#{project_id}/timer/start")
18
+ end
20
19
 
21
- def pause_timer(project_id)
22
- put("/v2/projects/#{project_id}/timer/pause")
23
- end
20
+ def pause_timer(project_id)
21
+ put("/v2/projects/#{project_id}/timer/pause")
22
+ end
24
23
 
25
- def log_timer(project_id, attributes = {})
26
- put("/v2/projects/#{project_id}/timer/log", attributes)
27
- end
24
+ def log_timer(project_id, attributes = {})
25
+ put("/v2/projects/#{project_id}/timer/log", attributes)
26
+ end
28
27
 
29
- def discard_timer(project_id)
30
- delete("/v2/projects/#{project_id}/timer")
31
- end
28
+ def discard_timer(project_id)
29
+ delete("/v2/projects/#{project_id}/timer")
32
30
  end
33
31
  end
@@ -1,41 +1,39 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Noko
4
- class Client
5
- def get_users(params = nil)
6
- get('/v2/users', params)
7
- end
8
-
9
- def get_user(id)
10
- get("/v2/users/#{id}")
11
- end
12
-
13
- def get_user_entries(id, params = nil)
14
- get("/v2/users/#{id}/entries", params)
15
- end
16
-
17
- def get_user_expenses(id, params = nil)
18
- get("/v2/users/#{id}/expenses", params)
19
- end
20
-
21
- def create_user(attributes)
22
- post('/v2/users', attributes)
23
- end
24
-
25
- def update_user(id, attributes)
26
- put("/v2/users/#{id}", attributes)
27
- end
28
-
29
- def delete_user(id)
30
- delete("/v2/users/#{id}")
31
- end
32
-
33
- def reactivate_user(id)
34
- put("/v2/users/#{id}/activate")
35
- end
36
-
37
- def deactivate_user(id)
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
@@ -0,0 +1,41 @@
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}")
40
+ end
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
- module Noko
12
- class Client
13
- def initialize(options = {})
14
- if options.key?(:access_token)
15
- @auth_header, @auth_value = 'Authorization', "token #{options[:access_token]}"
16
- else
17
- @auth_header, @auth_value = 'X-NokoToken', options.fetch(:token)
18
- end
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
- @user_agent = options.fetch(:user_agent) { "noko/#{VERSION} ruby/#{RUBY_VERSION}" }
23
+ @user_agent = options.fetch(:user_agent) { "noko/#{Noko::VERSION} ruby/#{RUBY_VERSION}" }
21
24
 
22
- @host = 'api.nokotime.com'
25
+ @host = 'api.nokotime.com'
23
26
 
24
- @http = Net::HTTP.new(@host, Net::HTTP.https_default_port)
27
+ @http = Net::HTTP.new(@host, Net::HTTP.https_default_port)
25
28
 
26
- @http.use_ssl = true
27
- end
29
+ @http.use_ssl = true
30
+ end
28
31
 
29
- def get(path, params = nil)
30
- request(Net::HTTP::Get.new(Params.join(path, params)))
31
- end
32
+ def get(path, params = nil)
33
+ request(Net::HTTP::Get.new(Noko::Params.join(path, params)))
34
+ end
32
35
 
33
- private
36
+ private
34
37
 
35
- def post(path, attributes)
36
- request(Net::HTTP::Post.new(path), attributes)
37
- end
38
+ def post(path, attributes)
39
+ request(Net::HTTP::Post.new(path), attributes)
40
+ end
38
41
 
39
- def put(path, attributes = nil)
40
- request(Net::HTTP::Put.new(path), attributes)
41
- end
42
+ def put(path, attributes = nil)
43
+ request(Net::HTTP::Put.new(path), attributes)
44
+ end
42
45
 
43
- def delete(path)
44
- request(Net::HTTP::Delete.new(path))
45
- end
46
+ def delete(path)
47
+ request(Net::HTTP::Delete.new(path))
48
+ end
46
49
 
47
- def request(http_request, body_object = nil)
48
- http_request['User-Agent'] = @user_agent
49
- http_request[@auth_header] = @auth_value
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
- if body_object
52
- http_request['Content-Type'] = 'application/json'
53
- http_request.body = JSON.generate(body_object)
54
- end
54
+ if body_object
55
+ http_request['Content-Type'] = 'application/json'
56
+ http_request.body = JSON.generate(body_object)
57
+ end
55
58
 
56
- response = @http.request(http_request)
59
+ response = @http.request(http_request)
57
60
 
58
- if response.is_a?(Net::HTTPSuccess)
59
- Response.parse(response)
60
- else
61
- raise Response.error(response)
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
@@ -1,18 +1,14 @@
1
1
  require 'noko/record'
2
2
  require 'uri'
3
3
 
4
- module Noko
5
- module LinkHeader
6
- extend self
4
+ module Noko::LinkHeader
5
+ extend self
7
6
 
8
- REGEXP = /<([^>]+)>; rel="(\w+)"/
7
+ REGEXP = /<([^>]+)>; rel="(\w+)"/
9
8
 
10
- def parse(string)
11
- string.scan(REGEXP).each_with_object(Record.new) do |(uri, rel), record|
12
- record[rel.to_sym] = URI.parse(uri).request_uri
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 'cgi'
2
+ require 'uri'
3
3
 
4
- module Noko
5
- module Params
6
- extend self
4
+ module Noko::Params
5
+ extend self
7
6
 
8
- def join(path, params = nil)
9
- return path if params.nil? || params.empty?
7
+ def join(path, params = nil)
8
+ return path if params.nil? || params.empty?
10
9
 
11
- path + '?' + encode(params)
12
- end
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
- def escape(component)
25
- CGI.escape(component.to_s)
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
- private_constant :Params
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
- module Noko
2
- class Record
3
- def initialize(attributes = {})
4
- @attributes = attributes
5
- end
1
+ # frozen_string_literal: true
6
2
 
7
- def [](name)
8
- @attributes[name]
9
- end
3
+ class Noko::Record
4
+ def initialize(attributes = {})
5
+ @attributes = attributes
6
+ end
10
7
 
11
- def []=(name, value)
12
- @attributes[name] = value
13
- end
8
+ def [](name)
9
+ @attributes[name]
10
+ end
14
11
 
15
- def method_missing(name, *args, &block)
16
- if @attributes.has_key?(name) && args.empty? && block.nil?
17
- return @attributes[name]
18
- else
19
- super name, *args, &block
20
- end
21
- end
12
+ def []=(name, value)
13
+ @attributes[name] = value
14
+ end
22
15
 
23
- def respond_to_missing?(name, include_private = false)
24
- @attributes.has_key?(name)
25
- end
16
+ def inspect
17
+ '#<' + self.class.name + ' ' + @attributes.map { "#{_1}=#{_2.inspect}" }.join(', ') + '>'
18
+ end
26
19
 
27
- def to_h
28
- @attributes
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
- module Response
7
- extend self
5
+ module Noko::Response
6
+ extend self
8
7
 
9
- def parse(response)
10
- if response.is_a?(Net::HTTPNoContent)
11
- return :no_content
12
- end
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
- if response['Link']
18
- object.singleton_class.module_eval { attr_accessor :link }
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
- return object
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
- response.body
21
+ return object
26
22
  end
27
23
 
28
- def error(response)
29
- if response.content_type == 'application/json'
30
- body = JSON.parse(response.body)
24
+ response.body
25
+ end
31
26
 
32
- error_class(response).new(body['message'])
33
- else
34
- error_class(response)
35
- end
36
- end
27
+ def error(response)
28
+ if response.content_type == 'application/json'
29
+ body = JSON.parse(response.body)
37
30
 
38
- def error_class(object)
39
- case object
40
- when Net::HTTPBadRequest then Noko::ClientError
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
- private_constant :Response
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/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Noko
2
- VERSION = '1.6.0'
2
+ VERSION = '1.7.0'
3
3
  end
data/lib/noko.rb CHANGED
@@ -7,5 +7,7 @@ require 'noko/client/invoices'
7
7
  require 'noko/client/project_groups'
8
8
  require 'noko/client/projects'
9
9
  require 'noko/client/tags'
10
+ require 'noko/client/teams'
10
11
  require 'noko/client/timers'
11
12
  require 'noko/client/users'
13
+ require 'noko/client/webhooks'
data/noko.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'noko'
3
- s.version = '1.6.0'
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,12 +9,15 @@ 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.9.3'
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',
16
16
  'source_code_uri' => 'https://github.com/timcraft/noko',
17
17
  'bug_tracker_uri' => 'https://github.com/timcraft/noko/issues',
18
- 'changelog_uri' => 'https://github.com/timcraft/noko/blob/master/CHANGES.md'
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: 1.6.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Craft
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-08 00:00:00.000000000 Z
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,8 +72,10 @@ 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
78
+ - lib/noko/client/webhooks.rb
35
79
  - lib/noko/errors.rb
36
80
  - lib/noko/link_header.rb
37
81
  - lib/noko/params.rb
@@ -46,8 +90,8 @@ metadata:
46
90
  homepage: https://github.com/timcraft/noko
47
91
  source_code_uri: https://github.com/timcraft/noko
48
92
  bug_tracker_uri: https://github.com/timcraft/noko/issues
49
- changelog_uri: https://github.com/timcraft/noko/blob/master/CHANGES.md
50
- post_install_message:
93
+ changelog_uri: https://github.com/timcraft/noko/blob/main/CHANGES.md
94
+ post_install_message:
51
95
  rdoc_options: []
52
96
  require_paths:
53
97
  - lib
@@ -55,15 +99,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
55
99
  requirements:
56
100
  - - ">="
57
101
  - !ruby/object:Gem::Version
58
- version: 1.9.3
102
+ version: 3.1.0
59
103
  required_rubygems_version: !ruby/object:Gem::Requirement
60
104
  requirements:
61
105
  - - ">="
62
106
  - !ruby/object:Gem::Version
63
107
  version: '0'
64
108
  requirements: []
65
- rubygems_version: 3.1.2
66
- signing_key:
109
+ rubygems_version: 3.5.22
110
+ signing_key:
67
111
  specification_version: 4
68
112
  summary: See description
69
113
  test_files: []