noko 0.0.0 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2e20acde5d6a8996729182c545b3f02493b6c6d4456c57e7f802a4afbbb23d10
4
- data.tar.gz: 015f207bc374bf4711717bf8c7633bcba0dc469737083541e2886705230d0afb
3
+ metadata.gz: afa40cf652f7da2b1c9feb0424800d941d997991c6c4b910c46975c5c22c5fae
4
+ data.tar.gz: 56adb6ca37608d673058f13b9349d200ea376d217ea2b15ad4170baf124a2404
5
5
  SHA512:
6
- metadata.gz: a2f31aa33be6bf23e2391b9697723cd87075ed525a7a0051512f56e6e3dc5dadfabca1f4cdcf880d43ec08179e9eb712e5a21754bc3a6e1949b5c7303f32dc5f
7
- data.tar.gz: 0fa8b0ceafc2eddb3b8456b4bf4f2877cd408ea8aac3d7eb9fe841a792bbf63b229bcd95b91778d5983c489b06d7f5ce619abacfe5984c0855eb031fb9151dfe
6
+ metadata.gz: 16d9ec8b0b3ae50cc931e2326691dd4ac8c3a3865c46ef996f61ecb915db88038209daf8f17da9e28d61912ff8f7abbed22c9520fb1001347f4c709372a20a77
7
+ data.tar.gz: 022b303e0a7b4f61410b7a4a9c2ef467e9e8173b971140d3bb8df764c31f88e60e5fe68a45b2f50e3a66a8d9c36e95db6a1de67775d8fb659b015b380cd61560
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015-2019 TIMCRAFT
2
+
3
+ Permission is hereby granted, free of charge, to any person
4
+ obtaining a copy of this software and associated documentation
5
+ files (the "Software"), to deal in the Software without
6
+ restriction, including without limitation the rights to use,
7
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the
9
+ Software is furnished to do so, subject to the following
10
+ conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,40 @@
1
+ # noko
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/noko.svg)](https://badge.fury.io/rb/noko) [![Build Status](https://api.travis-ci.org/timcraft/noko.svg?branch=master)](https://travis-ci.org/timcraft/noko)
4
+
5
+
6
+ Ruby client for [Version 2 of the Noko/Freckle API](https://developer.nokotime.com/v2/).
7
+
8
+
9
+ ## Install
10
+
11
+ Install using RubyGems:
12
+
13
+ ```
14
+ $ gem install noko
15
+ ```
16
+
17
+ Add it to your Gemfile and install using Bundler:
18
+
19
+ ```ruby
20
+ gem 'noko'
21
+ ```
22
+
23
+ Clone the repository:
24
+
25
+ ```
26
+ git clone git@github.com:timcraft/noko.git
27
+ ```
28
+
29
+
30
+ ## Quick start
31
+
32
+ ```ruby
33
+ require 'noko'
34
+
35
+ noko = Noko::Client.new(token: 'YOUR PERSONAL ACCESS TOKEN')
36
+
37
+ noko.get_projects.each do |project|
38
+ puts project.name
39
+ end
40
+ ```
@@ -0,0 +1,11 @@
1
+ require 'noko/client'
2
+ require 'noko/client/account'
3
+ require 'noko/client/current_user'
4
+ require 'noko/client/entries'
5
+ require 'noko/client/expenses'
6
+ require 'noko/client/invoices'
7
+ require 'noko/client/project_groups'
8
+ require 'noko/client/projects'
9
+ require 'noko/client/tags'
10
+ require 'noko/client/timers'
11
+ require 'noko/client/users'
@@ -0,0 +1,83 @@
1
+ require 'noko/version'
2
+ require 'noko/errors'
3
+ require 'noko/link_header'
4
+ require 'noko/params'
5
+ require 'noko/record'
6
+ require 'net/http'
7
+ require 'json'
8
+
9
+ module Noko
10
+ class Client
11
+ def initialize(options = {})
12
+ if options.key?(:access_token)
13
+ @auth_header, @auth_value = 'Authorization', "token #{options[:access_token]}"
14
+ else
15
+ @auth_header, @auth_value = 'X-NokoToken', options.fetch(:token)
16
+ end
17
+
18
+ @user_agent = options.fetch(:user_agent) { "noko/#{VERSION} ruby/#{RUBY_VERSION}" }
19
+
20
+ @host = 'api.nokotime.com'
21
+
22
+ @http = Net::HTTP.new(@host, Net::HTTP.https_default_port)
23
+
24
+ @http.use_ssl = true
25
+ end
26
+
27
+ def get(path, params = nil)
28
+ request(Net::HTTP::Get.new(Params.join(path, params)))
29
+ end
30
+
31
+ private
32
+
33
+ def post(path, attributes)
34
+ request(Net::HTTP::Post.new(path), attributes)
35
+ end
36
+
37
+ def put(path, attributes = nil)
38
+ request(Net::HTTP::Put.new(path), attributes)
39
+ end
40
+
41
+ def delete(path)
42
+ request(Net::HTTP::Delete.new(path))
43
+ end
44
+
45
+ def request(http_request, body_object = nil)
46
+ http_request['User-Agent'] = @user_agent
47
+ http_request[@auth_header] = @auth_value
48
+
49
+ if body_object
50
+ http_request['Content-Type'] = 'application/json'
51
+ http_request.body = JSON.generate(body_object)
52
+ end
53
+
54
+ parse(@http.request(http_request))
55
+ end
56
+
57
+ def parse(http_response)
58
+ case http_response
59
+ when Net::HTTPNoContent
60
+ :no_content
61
+ when Net::HTTPSuccess
62
+ if http_response['Content-Type'] && http_response['Content-Type'].split(';').first == 'application/json'
63
+ JSON.parse(http_response.body, symbolize_names: true, object_class: Record).tap do |object|
64
+ if http_response['Link']
65
+ object.singleton_class.module_eval { attr_accessor :link }
66
+ object.link = LinkHeader.parse(http_response['Link'])
67
+ end
68
+ end
69
+ else
70
+ http_response.body
71
+ end
72
+ when Net::HTTPBadRequest
73
+ object = JSON.parse(http_response.body, symbolize_names: true)
74
+
75
+ raise Error, object.fetch(:message)
76
+ when Net::HTTPUnauthorized
77
+ raise AuthenticationError
78
+ else
79
+ raise Error, "unexpected #{http_response.code} response from #{@host}"
80
+ end
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,7 @@
1
+ module Noko
2
+ class Client
3
+ def get_account
4
+ get('/v2/account')
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,19 @@
1
+ module Noko
2
+ class Client
3
+ def get_current_user
4
+ get('/v2/current_user')
5
+ end
6
+
7
+ def get_current_user_entries(params = nil)
8
+ get('/v2/current_user/entries', params)
9
+ end
10
+
11
+ def get_current_user_expenses(params = nil)
12
+ get('/v2/current_user/expenses', params)
13
+ end
14
+
15
+ def update_current_user(attributes)
16
+ put('/v2/current_user', attributes)
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,23 @@
1
+ module Noko
2
+ class Client
3
+ def get_entries(params = nil)
4
+ get('/v2/entries', params)
5
+ end
6
+
7
+ def get_entry(id)
8
+ get("/v2/entries/#{id}")
9
+ end
10
+
11
+ def create_entry(attributes)
12
+ post('/v2/entries', attributes)
13
+ end
14
+
15
+ def update_entry(id, attributes)
16
+ put("/v2/entries/#{id}", attributes)
17
+ end
18
+
19
+ def delete_entry(id)
20
+ delete("/v2/entries/#{id}")
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,23 @@
1
+ module Noko
2
+ class Client
3
+ def get_expenses(params = nil)
4
+ get('/v2/expenses', params)
5
+ end
6
+
7
+ def get_expense(id)
8
+ get("/v2/expenses/#{id}")
9
+ end
10
+
11
+ def create_expense(attributes)
12
+ post('/v2/expenses', attributes)
13
+ end
14
+
15
+ def update_expense(id, attributes)
16
+ put("/v2/expenses/#{id}", attributes)
17
+ end
18
+
19
+ def delete_expense(id)
20
+ delete("/v2/expenses/#{id}")
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,39 @@
1
+ module Noko
2
+ class Client
3
+ def get_invoices(params = nil)
4
+ get('/v2/invoices', params)
5
+ end
6
+
7
+ def get_invoice(id)
8
+ get("/v2/invoices/#{id}")
9
+ end
10
+
11
+ def create_invoice(attributes)
12
+ post('/v2/invoices', attributes)
13
+ end
14
+
15
+ def update_invoice(id, attributes)
16
+ put("/v2/invoices/#{id}", attributes)
17
+ end
18
+
19
+ def mark_invoice_paid(id)
20
+ put("/v2/invoices/#{id}/paid")
21
+ end
22
+
23
+ def mark_invoice_unpaid(id)
24
+ put("/v2/invoices/#{id}/unpaid")
25
+ end
26
+
27
+ def get_invoice_entries(id, params = nil)
28
+ get("/v2/invoices/#{id}/entries", params)
29
+ end
30
+
31
+ def get_invoice_expenses(id, params = nil)
32
+ get("/v2/invoices/#{id}/expenses", params)
33
+ end
34
+
35
+ def delete_invoice(id)
36
+ delete("/v2/invoices/#{id}")
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,31 @@
1
+ module Noko
2
+ class Client
3
+ def get_project_groups(params = nil)
4
+ get('/v2/project_groups', params)
5
+ end
6
+
7
+ def get_project_group(id)
8
+ get("/v2/project_groups/#{id}")
9
+ end
10
+
11
+ def create_project_group(attributes)
12
+ post('/v2/project_groups', attributes)
13
+ end
14
+
15
+ def get_project_group_entries(id, params = nil)
16
+ get("/v2/project_groups/#{id}/entries", params)
17
+ end
18
+
19
+ def get_project_group_projects(id, params = nil)
20
+ get("/v2/project_groups/#{id}/projects", params)
21
+ end
22
+
23
+ def update_project_group(id, attributes)
24
+ put("/v2/project_groups/#{id}", attributes)
25
+ end
26
+
27
+ def delete_project_group(id)
28
+ delete("/v2/project_groups/#{id}")
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,55 @@
1
+ module Noko
2
+ class Client
3
+ def get_projects(params = nil)
4
+ get('/v2/projects', params)
5
+ end
6
+
7
+ def get_project(id)
8
+ get("/v2/projects/#{id}")
9
+ end
10
+
11
+ def create_project(attributes)
12
+ post('/v2/projects', attributes)
13
+ end
14
+
15
+ def get_project_entries(id, params = nil)
16
+ get("/v2/projects/#{id}/entries", params)
17
+ end
18
+
19
+ def get_project_expenses(id, params = nil)
20
+ get("/v2/projects/#{id}/expenses", params)
21
+ end
22
+
23
+ def update_project(id, attributes)
24
+ put("/v2/projects/#{id}", attributes)
25
+ end
26
+
27
+ def merge_projects(id, project_id)
28
+ put("/v2/projects/#{id}/merge", project_id: project_id)
29
+ end
30
+
31
+ def delete_project(id)
32
+ delete("/v2/projects/#{id}")
33
+ end
34
+
35
+ def archive_project(id)
36
+ put("/v2/projects/#{id}/archive")
37
+ end
38
+
39
+ def unarchive_project(id)
40
+ put("/v2/projects/#{id}/unarchive")
41
+ end
42
+
43
+ def archive_projects(project_ids)
44
+ put('/v2/projects/archive', project_ids: project_ids)
45
+ end
46
+
47
+ def unarchive_projects(project_ids)
48
+ put('/v2/projects/unarchive', project_ids: project_ids)
49
+ end
50
+
51
+ def delete_projects(project_ids)
52
+ put('/v2/projects/delete', project_ids: project_ids)
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,35 @@
1
+ module Noko
2
+ class Client
3
+ def get_tags(params = nil)
4
+ get('/v2/tags', params)
5
+ end
6
+
7
+ def create_tags(names)
8
+ post('/v2/tags', names: names)
9
+ end
10
+
11
+ def get_tag(id)
12
+ get("/v2/tags/#{id}")
13
+ end
14
+
15
+ def get_tag_entries(id, params = nil)
16
+ get("/v2/tags/#{id}/entries", params)
17
+ end
18
+
19
+ def update_tag(id, attributes)
20
+ put("/v2/tags/#{id}", attributes)
21
+ end
22
+
23
+ def merge_tags(id, tag_id)
24
+ put("/v2/tags/#{id}/merge", tag_id: tag_id)
25
+ end
26
+
27
+ def delete_tag(id)
28
+ delete("/v2/tags/#{id}")
29
+ end
30
+
31
+ def delete_tags(tag_ids)
32
+ put('/v2/tags/delete', tag_ids: tag_ids)
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,31 @@
1
+ module Noko
2
+ class Client
3
+ def get_timers(params = nil)
4
+ get('/v2/timers', params)
5
+ end
6
+
7
+ def get_timer(project_id)
8
+ get("/v2/projects/#{project_id}/timer")
9
+ end
10
+
11
+ def update_timer(project_id, attributes)
12
+ put("/v2/projects/#{project_id}/timer", attributes)
13
+ end
14
+
15
+ def start_timer(project_id)
16
+ put("/v2/projects/#{project_id}/timer/start")
17
+ end
18
+
19
+ def pause_timer(project_id)
20
+ put("/v2/projects/#{project_id}/timer/pause")
21
+ end
22
+
23
+ def log_timer(project_id, attributes = {})
24
+ put("/v2/projects/#{project_id}/timer/log", attributes)
25
+ end
26
+
27
+ def discard_timer(project_id)
28
+ delete("/v2/projects/#{project_id}/timer")
29
+ end
30
+ end
31
+ end