noko 0.0.0 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,99 @@
1
+ require_relative '../client_test'
2
+
3
+ class ClientProjectsTest < ClientTest
4
+ def test_get_projects
5
+ expect_request(:get, "#{base_url}/projects").with(auth_header).to_return(json_array_response)
6
+
7
+ assert_equal [], client.get_projects
8
+ end
9
+
10
+ def test_get_projects_encodes_params
11
+ expect_request(:get, "#{base_url}/projects?billable=true")
12
+
13
+ client.get_projects(billable: true)
14
+ end
15
+
16
+ def test_get_project
17
+ expect_request(:get, "#{base_url}/projects/#{id}").with(auth_header).to_return(json_response)
18
+
19
+ assert_instance_of Noko::Record, client.get_project(id)
20
+ end
21
+
22
+ def test_create_project
23
+ expect_request(:post, "#{base_url}/projects").with(json_request).to_return(json_response.merge(status: 201))
24
+
25
+ assert_instance_of Noko::Record, client.create_project(name: 'Gear GmbH')
26
+ end
27
+
28
+ def test_get_project_entries
29
+ expect_request(:get, "#{base_url}/projects/#{id}/entries").with(auth_header).to_return(json_array_response)
30
+
31
+ assert_equal [], client.get_project_entries(id)
32
+ end
33
+
34
+ def test_get_project_entries_encodes_params
35
+ expect_request(:get, "#{base_url}/projects/#{id}/entries?billable=true")
36
+
37
+ client.get_project_entries(id, billable: true)
38
+ end
39
+
40
+ def test_get_project_expenses
41
+ expect_request(:get, "#{base_url}/projects/#{id}/expenses").with(auth_header).to_return(json_array_response)
42
+
43
+ assert_equal [], client.get_project_expenses(id)
44
+ end
45
+
46
+ def test_get_project_expenses_encodes_params
47
+ expect_request(:get, "#{base_url}/projects/#{id}/expenses?invoiced=true")
48
+
49
+ client.get_project_expenses(id, invoiced: true)
50
+ end
51
+
52
+ def test_update_project
53
+ expect_request(:put, "#{base_url}/projects/#{id}").with(json_request).to_return(json_response)
54
+
55
+ assert_instance_of Noko::Record, client.update_project(id, color: '#ff9898')
56
+ end
57
+
58
+ def test_merge_projects
59
+ expect_request(:put, "#{base_url}/projects/#{id}/merge").with(json_request.merge(body: '{"project_id":5678}')).to_return(status: 204)
60
+
61
+ assert_equal :no_content, client.merge_projects(id, 5678)
62
+ end
63
+
64
+ def test_delete_project
65
+ expect_request(:delete, "#{base_url}/projects/#{id}").with(auth_header).to_return(status: 204)
66
+
67
+ assert_equal :no_content, client.delete_project(id)
68
+ end
69
+
70
+ def test_archive_project
71
+ expect_request(:put, "#{base_url}/projects/#{id}/archive").with(auth_header).to_return(status: 204)
72
+
73
+ assert_equal :no_content, client.archive_project(id)
74
+ end
75
+
76
+ def test_unarchive_project
77
+ expect_request(:put, "#{base_url}/projects/#{id}/unarchive").with(auth_header).to_return(status: 204)
78
+
79
+ assert_equal :no_content, client.unarchive_project(id)
80
+ end
81
+
82
+ def test_archive_projects
83
+ expect_request(:put, "#{base_url}/projects/archive").with(json_request.merge(body: '{"project_ids":[123]}')).to_return(status: 204)
84
+
85
+ assert_equal :no_content, client.archive_projects([id])
86
+ end
87
+
88
+ def test_unarchive_projects
89
+ expect_request(:put, "#{base_url}/projects/unarchive").with(json_request.merge(body: '{"project_ids":[123]}')).to_return(status: 204)
90
+
91
+ assert_equal :no_content, client.unarchive_projects([id])
92
+ end
93
+
94
+ def test_delete_projects
95
+ expect_request(:put, "#{base_url}/projects/delete").with(json_request.merge(body: '{"project_ids":[123]}')).to_return(status: 204)
96
+
97
+ assert_equal :no_content, client.delete_projects([id])
98
+ end
99
+ end
@@ -0,0 +1,39 @@
1
+ require_relative '../client_test'
2
+
3
+ class ClientResponseTest < ClientTest
4
+ def response(headers)
5
+ {headers: json_response_headers.merge(headers), body: '[]'}
6
+ end
7
+
8
+ def test_rel_next_link
9
+ link = '<https://api.nokotime.com/v2/entries?page=3>; rel="next"'
10
+
11
+ expect_request(:get, "#{base_url}/entries").to_return(response('Link' => link))
12
+
13
+ assert_equal '/v2/entries?page=3', client.get_entries.link.next
14
+ end
15
+
16
+ def test_rel_prev_link
17
+ link = '<https://api.nokotime.com/v2/entries?page=2>; rel="prev"'
18
+
19
+ expect_request(:get, "#{base_url}/entries").to_return(response('Link' => link))
20
+
21
+ assert_equal '/v2/entries?page=2', client.get_entries.link.prev
22
+ end
23
+
24
+ def test_rel_last_link
25
+ link = '<https://api.nokotime.com/v2/entries?page=50>; rel="last"'
26
+
27
+ expect_request(:get, "#{base_url}/entries").to_return(response('Link' => link))
28
+
29
+ assert_equal '/v2/entries?page=50', client.get_entries.link.last
30
+ end
31
+
32
+ def test_rel_first_link
33
+ link = '<https://api.nokotime.com/v2/entries?page=1>; rel="first"'
34
+
35
+ expect_request(:get, "#{base_url}/entries").to_return(response('Link' => link))
36
+
37
+ assert_equal '/v2/entries?page=1', client.get_entries.link.first
38
+ end
39
+ end
@@ -0,0 +1,63 @@
1
+ require_relative '../client_test'
2
+
3
+ class ClientTagsTest < ClientTest
4
+ def test_get_tags
5
+ expect_request(:get, "#{base_url}/tags").with(auth_header).to_return(json_array_response)
6
+
7
+ assert_equal [], client.get_tags
8
+ end
9
+
10
+ def test_get_tags_encodes_params
11
+ expect_request(:get, "#{base_url}/tags?billable=true")
12
+
13
+ client.get_tags(billable: true)
14
+ end
15
+
16
+ def test_create_tags
17
+ expect_request(:post, "#{base_url}/tags").with(json_request).to_return(json_array_response.merge(status: 201))
18
+
19
+ assert_equal [], client.create_tags(%w[freckle])
20
+ end
21
+
22
+ def test_get_tag
23
+ expect_request(:get, "#{base_url}/tags/#{id}").with(auth_header).to_return(json_response)
24
+
25
+ assert_instance_of Noko::Record, client.get_tag(id)
26
+ end
27
+
28
+ def test_get_tag_entries
29
+ expect_request(:get, "#{base_url}/tags/#{id}/entries").with(auth_header).to_return(json_array_response)
30
+
31
+ assert_equal [], client.get_tag_entries(id)
32
+ end
33
+
34
+ def test_get_tag_entries_encodes_params
35
+ expect_request(:get, "#{base_url}/tags/#{id}/entries?billable=true")
36
+
37
+ client.get_tag_entries(id, billable: true)
38
+ end
39
+
40
+ def test_update_tag
41
+ expect_request(:put, "#{base_url}/tags/#{id}").with(json_request).to_return(json_response)
42
+
43
+ assert_instance_of Noko::Record, client.update_tag(id, name: 'freckle')
44
+ end
45
+
46
+ def test_merge_tags
47
+ expect_request(:put, "#{base_url}/tags/#{id}/merge").with(json_request.merge(body: '{"tag_id":5678}')).to_return(status: 204)
48
+
49
+ assert_equal :no_content, client.merge_tags(id, 5678)
50
+ end
51
+
52
+ def test_delete_tag
53
+ expect_request(:delete, "#{base_url}/tags/#{id}").with(auth_header).to_return(status: 204)
54
+
55
+ assert_equal :no_content, client.delete_tag(id)
56
+ end
57
+
58
+ def test_delete_tags
59
+ expect_request(:put, "#{base_url}/tags/delete").with(json_request.merge(body: '{"tag_ids":[123]}')).to_return(status: 204)
60
+
61
+ assert_equal :no_content, client.delete_tags([id])
62
+ end
63
+ end
@@ -0,0 +1,57 @@
1
+ require_relative '../client_test'
2
+
3
+ class ClientTimersTest < ClientTest
4
+ def test_get_timers
5
+ expect_request(:get, "#{base_url}/timers").with(auth_header).to_return(json_array_response)
6
+
7
+ assert_equal [], client.get_timers
8
+ end
9
+
10
+ def test_get_timers_encodes_params
11
+ expect_request(:get, "#{base_url}/timers?billable=true")
12
+
13
+ client.get_timers(billable: true)
14
+ end
15
+
16
+ def test_get_timers_encodes_ids
17
+ expect_request(:get, "#{base_url}/timers?projects=123,456,789")
18
+
19
+ client.get_timers(projects: ids)
20
+ end
21
+
22
+ def test_get_timer
23
+ expect_request(:get, "#{base_url}/projects/#{id}/timer").with(auth_header).to_return(json_response)
24
+
25
+ assert_instance_of Noko::Record, client.get_timer(id)
26
+ end
27
+
28
+ def test_update_timer
29
+ expect_request(:put, "#{base_url}/projects/#{id}/timer").with(json_request).to_return(json_response)
30
+
31
+ assert_instance_of Noko::Record, client.update_timer(id, description: 'Notes go here')
32
+ end
33
+
34
+ def test_start_timer
35
+ expect_request(:put, "#{base_url}/projects/#{id}/timer/start").with(auth_header).to_return(json_response)
36
+
37
+ assert_instance_of Noko::Record, client.start_timer(id)
38
+ end
39
+
40
+ def test_pause_timer
41
+ expect_request(:put, "#{base_url}/projects/#{id}/timer/pause").with(auth_header).to_return(json_response)
42
+
43
+ assert_instance_of Noko::Record, client.pause_timer(id)
44
+ end
45
+
46
+ def test_log_timer
47
+ expect_request(:put, "#{base_url}/projects/#{id}/timer/log").with(auth_header).to_return(status: 204)
48
+
49
+ assert_equal :no_content, client.log_timer(id, description: 'Serious #development work')
50
+ end
51
+
52
+ def test_discard_timer
53
+ expect_request(:delete, "#{base_url}/projects/#{id}/timer").with(auth_header).to_return(status: 204)
54
+
55
+ assert_equal :no_content, client.discard_timer(id)
56
+ end
57
+ end
@@ -0,0 +1,75 @@
1
+ require_relative '../client_test'
2
+
3
+ class ClientUsersTest < ClientTest
4
+ def test_get_users
5
+ expect_request(:get, "#{base_url}/users").with(auth_header).to_return(json_array_response)
6
+
7
+ assert_equal [], client.get_users
8
+ end
9
+
10
+ def test_get_users_encodes_params
11
+ expect_request(:get, "#{base_url}/users?name=John")
12
+
13
+ client.get_users(name: 'John')
14
+ end
15
+
16
+ def test_get_user
17
+ expect_request(:get, "#{base_url}/users/#{id}").with(auth_header).to_return(json_response)
18
+
19
+ assert_instance_of Noko::Record, client.get_user(id)
20
+ end
21
+
22
+ def test_get_user_entries
23
+ expect_request(:get, "#{base_url}/users/#{id}/entries").with(auth_header).to_return(json_array_response)
24
+
25
+ assert_equal [], client.get_user_entries(id)
26
+ end
27
+
28
+ def test_get_user_entries_encodes_params
29
+ expect_request(:get, "#{base_url}/users/#{id}/entries?billable=true")
30
+
31
+ client.get_user_entries(id, billable: true)
32
+ end
33
+
34
+ def test_get_user_expenses
35
+ expect_request(:get, "#{base_url}/users/#{id}/expenses").with(auth_header).to_return(json_array_response)
36
+
37
+ assert_equal [], client.get_user_expenses(id)
38
+ end
39
+
40
+ def test_get_user_expenses_encodes_params
41
+ expect_request(:get, "#{base_url}/users/#{id}/expenses?invoiced=true")
42
+
43
+ client.get_user_expenses(id, invoiced: true)
44
+ end
45
+
46
+ def test_create_user
47
+ expect_request(:post, "#{base_url}/users").with(json_request).to_return(json_response.merge(status: 201))
48
+
49
+ assert_instance_of Noko::Record, client.create_user(email: 'alice@example.com')
50
+ end
51
+
52
+ def test_update_user
53
+ expect_request(:put, "#{base_url}/users/#{id}").with(json_request).to_return(json_response)
54
+
55
+ assert_instance_of Noko::Record, client.update_user(id, role: 'leader')
56
+ end
57
+
58
+ def test_delete_user
59
+ expect_request(:delete, "#{base_url}/users/#{id}").with(auth_header).to_return(status: 204)
60
+
61
+ assert_equal :no_content, client.delete_user(id)
62
+ end
63
+
64
+ def test_reactivate_user
65
+ expect_request(:put, "#{base_url}/users/#{id}/activate").with(auth_header).to_return(status: 204)
66
+
67
+ assert_equal :no_content, client.reactivate_user(id)
68
+ end
69
+
70
+ def test_deactivate_user
71
+ expect_request(:put, "#{base_url}/users/#{id}/deactivate").with(auth_header).to_return(status: 204)
72
+
73
+ assert_equal :no_content, client.deactivate_user(id)
74
+ end
75
+ end
@@ -0,0 +1,59 @@
1
+ require 'minitest/autorun'
2
+ require 'webmock/minitest'
3
+ require 'noko'
4
+
5
+ class ClientTest < Minitest::Test
6
+ def token
7
+ 'token-xxx'
8
+ end
9
+
10
+ def id
11
+ 123
12
+ end
13
+
14
+ def ids
15
+ %w[123 456 789]
16
+ end
17
+
18
+ def base_url
19
+ 'https://api.nokotime.com/v2'
20
+ end
21
+
22
+ def auth_header
23
+ {headers: {'X-NokoToken' => token}}
24
+ end
25
+
26
+ def json_request
27
+ {headers: {'X-NokoToken' => token, 'Content-Type' => 'application/json'}, body: /\A{.+}\z/}
28
+ end
29
+
30
+ def json_response_headers
31
+ {'Content-Type' => 'application/json;charset=utf-8'}
32
+ end
33
+
34
+ def json_response
35
+ {headers: json_response_headers, body: '{}'}
36
+ end
37
+
38
+ def json_array_response
39
+ {headers: json_response_headers, body: '[]'}
40
+ end
41
+
42
+ attr_accessor :client
43
+ attr_accessor :request
44
+
45
+ def setup
46
+ WebMock.reset!
47
+
48
+ self.client = Noko::Client.new(token: token)
49
+ self.request = nil
50
+ end
51
+
52
+ def teardown
53
+ assert_requested(request) if request
54
+ end
55
+
56
+ def expect_request(*args)
57
+ self.request = stub_request(*args)
58
+ end
59
+ end
@@ -0,0 +1,28 @@
1
+ require 'minitest/autorun'
2
+ require 'noko'
3
+
4
+ class RecordTest < Minitest::Test
5
+ def id
6
+ 123
7
+ end
8
+
9
+ attr_accessor :record
10
+
11
+ def setup
12
+ self.record = Noko::Record.new(project_id: id)
13
+ end
14
+
15
+ def test_square_brackets_returns_attribute_values
16
+ assert_equal id, record[:project_id]
17
+ end
18
+
19
+ def test_method_missing_returns_attribute_values
20
+ assert_equal id, record.project_id
21
+ end
22
+
23
+ def test_to_h_returns_attributes_hash
24
+ attributes = {project_id: id}
25
+
26
+ assert_equal attributes, record.to_h
27
+ end
28
+ end
metadata CHANGED
@@ -1,23 +1,100 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: noko
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 1.4.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: 2019-03-21 00:00:00.000000000 Z
12
- dependencies: []
13
- description: Ruby client library for the Noko API
11
+ date: 2019-04-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '12'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '12'
27
+ - !ruby/object:Gem::Dependency
28
+ name: webmock
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ description: Ruby client for Version 2 of the Noko/Freckle API
14
56
  email:
15
57
  - mail@timcraft.com
16
58
  executables: []
17
59
  extensions: []
18
60
  extra_rdoc_files: []
19
- files: []
20
- homepage: https://nokotime.com
61
+ files:
62
+ - LICENSE.txt
63
+ - README.md
64
+ - lib/noko.rb
65
+ - lib/noko/client.rb
66
+ - lib/noko/client/account.rb
67
+ - lib/noko/client/current_user.rb
68
+ - lib/noko/client/entries.rb
69
+ - lib/noko/client/expenses.rb
70
+ - lib/noko/client/invoices.rb
71
+ - lib/noko/client/project_groups.rb
72
+ - lib/noko/client/projects.rb
73
+ - lib/noko/client/tags.rb
74
+ - lib/noko/client/timers.rb
75
+ - lib/noko/client/users.rb
76
+ - lib/noko/errors.rb
77
+ - lib/noko/link_header.rb
78
+ - lib/noko/params.rb
79
+ - lib/noko/record.rb
80
+ - lib/noko/version.rb
81
+ - noko.gemspec
82
+ - test/noko/client/account_test.rb
83
+ - test/noko/client/current_user_test.rb
84
+ - test/noko/client/entries_test.rb
85
+ - test/noko/client/errors_test.rb
86
+ - test/noko/client/expenses_test.rb
87
+ - test/noko/client/invoices_test.rb
88
+ - test/noko/client/options_test.rb
89
+ - test/noko/client/project_groups_test.rb
90
+ - test/noko/client/projects_test.rb
91
+ - test/noko/client/response_test.rb
92
+ - test/noko/client/tags_test.rb
93
+ - test/noko/client/timers_test.rb
94
+ - test/noko/client/users_test.rb
95
+ - test/noko/client_test.rb
96
+ - test/noko/record_test.rb
97
+ homepage: https://github.com/timcraft/noko
21
98
  licenses:
22
99
  - MIT
23
100
  metadata: {}
@@ -29,7 +106,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
29
106
  requirements:
30
107
  - - ">="
31
108
  - !ruby/object:Gem::Version
32
- version: '0'
109
+ version: 1.9.3
33
110
  required_rubygems_version: !ruby/object:Gem::Requirement
34
111
  requirements:
35
112
  - - ">="
@@ -39,5 +116,5 @@ requirements: []
39
116
  rubygems_version: 3.0.3
40
117
  signing_key:
41
118
  specification_version: 4
42
- summary: Ruby client library for the Noko (née Freckle) v2 API
119
+ summary: Ruby client for Version 2 of the Noko/Freckle API
43
120
  test_files: []