timetree 0.3.0 → 0.3.1
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/{.rubocom.yml → .rubocop.yml} +11 -9
- data/CHANGELOG.md +18 -12
- data/Rakefile +8 -6
- data/lib/timetree/client.rb +12 -12
- data/lib/timetree/http_command.rb +4 -4
- data/lib/timetree/models/activity.rb +1 -1
- data/lib/timetree/models/base_model.rb +11 -13
- data/lib/timetree/models/event.rb +6 -6
- data/lib/timetree/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: df0d2bfb7eba71f46fe26e60f22fffae4b0da14fbb4e08b65554c2196618d92f
|
4
|
+
data.tar.gz: 2d9da4a76ece71b6a9c4515655ef17f0f27d72f0ab540c53c118492076881a03
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 860f43f818d2eb354d57c6a657301b2c33104fd6e372f1769a5509b37aee9033fcc8d9ac0058364562128a2a00edd19bd42bdc2ec7614e506c59b66f4c2c7701
|
7
|
+
data.tar.gz: 6cdae75ad99e57b6ec9d86781fb402cfea2424c85644898e0991e2745c9fcd30872d8ca8febf0f896147ca49a98e67fcb6f911ae494e193eef82b64654d3e0b9
|
@@ -23,12 +23,11 @@ Metrics/BlockNesting:
|
|
23
23
|
Max: 2
|
24
24
|
|
25
25
|
Layout/LineLength:
|
26
|
-
|
27
|
-
Enabled: false
|
26
|
+
Max: 120
|
28
27
|
|
29
28
|
Metrics/MethodLength:
|
30
29
|
CountComments: false
|
31
|
-
Max:
|
30
|
+
Max: 20
|
32
31
|
|
33
32
|
Metrics/ParameterLists:
|
34
33
|
Max: 4
|
@@ -39,10 +38,10 @@ Metrics/AbcSize:
|
|
39
38
|
|
40
39
|
Style/CollectionMethods:
|
41
40
|
PreferredMethods:
|
42
|
-
map:
|
43
|
-
reduce:
|
44
|
-
find:
|
45
|
-
find_all:
|
41
|
+
map: "collect"
|
42
|
+
reduce: "inject"
|
43
|
+
find: "detect"
|
44
|
+
find_all: "select"
|
46
45
|
|
47
46
|
Style/Documentation:
|
48
47
|
Enabled: false
|
@@ -60,10 +59,13 @@ Style/ExpandPathArguments:
|
|
60
59
|
Enabled: false
|
61
60
|
|
62
61
|
Style/HashSyntax:
|
63
|
-
EnforcedStyle:
|
62
|
+
EnforcedStyle: ruby19
|
64
63
|
|
65
64
|
Style/Lambda:
|
66
65
|
Enabled: false
|
67
66
|
|
68
67
|
Style/RaiseArgs:
|
69
|
-
EnforcedStyle: compact
|
68
|
+
EnforcedStyle: compact
|
69
|
+
|
70
|
+
Style/AsciiComments:
|
71
|
+
Enabled: false
|
data/CHANGELOG.md
CHANGED
@@ -1,55 +1,61 @@
|
|
1
|
-
#
|
1
|
+
# CHANGELOG
|
2
|
+
|
3
|
+
## 0.3.1
|
4
|
+
|
5
|
+
- fix rubocop warnings.
|
6
|
+
|
7
|
+
## 0.3.0
|
2
8
|
|
3
9
|
- refs #25 fix dependencies.
|
4
10
|
- remove minitest-reporter.
|
5
11
|
|
6
|
-
|
12
|
+
## 0.2.1
|
7
13
|
|
8
14
|
- do refactor
|
9
15
|
- use `respond_to?(setter)` instead of `instance_methods.include?(setter)`.
|
10
16
|
- use getter method instead of instant variables if defined it.
|
11
17
|
|
12
|
-
|
18
|
+
## 0.2.0
|
13
19
|
|
14
20
|
- organize model classes.
|
15
21
|
|
16
|
-
|
22
|
+
## 0.1.7
|
17
23
|
|
18
24
|
- refs #16 correct a mistake codecov badge url on README
|
19
25
|
|
20
|
-
|
26
|
+
## 0.1.6
|
21
27
|
|
22
28
|
- refs #16 add code coverage to readme.
|
23
29
|
- refs #17 update deprecated `version` for `ruby-version` on gem-push.yml.
|
24
30
|
|
25
|
-
|
31
|
+
## 0.1.5
|
26
32
|
|
27
33
|
- refs #6 setup GitHub Actions.
|
28
34
|
|
29
|
-
|
35
|
+
## 0.1.4
|
30
36
|
|
31
37
|
- updates comments.
|
32
38
|
|
33
|
-
|
39
|
+
## 0.1.3
|
34
40
|
|
35
41
|
- refs #7 #9 make the code coverage 100%.
|
36
42
|
|
37
|
-
|
43
|
+
## 0.1.2
|
38
44
|
|
39
45
|
- refs #1 fix typo Event#recurrences to recurrence
|
40
46
|
- refs #2 add a note for debugging guide on README
|
41
47
|
|
42
|
-
|
48
|
+
## 0.1.1
|
43
49
|
|
44
50
|
- set current version on this gem's documentation_uri.
|
45
51
|
- fixed typo on README.
|
46
52
|
|
47
|
-
|
53
|
+
## 0.1.0
|
48
54
|
|
49
55
|
- did refactor and wrote comments.
|
50
56
|
- started to use zeitwerk.
|
51
57
|
- wrote README.
|
52
58
|
|
53
|
-
|
59
|
+
## 0.0.1
|
54
60
|
|
55
61
|
- Initial release
|
data/Rakefile
CHANGED
@@ -1,10 +1,12 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'bundler/gem_tasks'
|
4
|
+
require 'rake/testtask'
|
3
5
|
|
4
6
|
Rake::TestTask.new(:test) do |t|
|
5
|
-
t.libs <<
|
6
|
-
t.libs <<
|
7
|
-
t.test_files = FileList[
|
7
|
+
t.libs << 'test'
|
8
|
+
t.libs << 'lib'
|
9
|
+
t.test_files = FileList['test/**/*_test.rb']
|
8
10
|
end
|
9
11
|
|
10
|
-
task :
|
12
|
+
task default: :test
|
data/lib/timetree/client.rb
CHANGED
@@ -28,7 +28,7 @@ module TimeTree
|
|
28
28
|
# @since 0.0.1
|
29
29
|
def current_user
|
30
30
|
res = @http_cmd.get '/user'
|
31
|
-
raise ApiError
|
31
|
+
raise ApiError.new(res) if res.status != 200
|
32
32
|
|
33
33
|
to_model res.body[:data]
|
34
34
|
end
|
@@ -47,7 +47,7 @@ module TimeTree
|
|
47
47
|
check_calendar_id cal_id
|
48
48
|
params = relationships_params(include_relationships, Calendar::RELATIONSHIPS)
|
49
49
|
res = @http_cmd.get "/calendars/#{cal_id}", params
|
50
|
-
raise ApiError
|
50
|
+
raise ApiError.new(res) if res.status != 200
|
51
51
|
|
52
52
|
to_model(res.body[:data], included: res.body[:included])
|
53
53
|
end
|
@@ -63,7 +63,7 @@ module TimeTree
|
|
63
63
|
def calendars(include_relationships: nil)
|
64
64
|
params = relationships_params(include_relationships, Calendar::RELATIONSHIPS)
|
65
65
|
res = @http_cmd.get '/calendars', params
|
66
|
-
raise ApiError
|
66
|
+
raise ApiError.new(res) if res.status != 200
|
67
67
|
|
68
68
|
included = res.body[:included]
|
69
69
|
res.body[:data].map { |item| to_model(item, included: included) }
|
@@ -80,7 +80,7 @@ module TimeTree
|
|
80
80
|
def calendar_labels(cal_id)
|
81
81
|
check_calendar_id cal_id
|
82
82
|
res = @http_cmd.get "/calendars/#{cal_id}/labels"
|
83
|
-
raise ApiError
|
83
|
+
raise ApiError.new(res) if res.status != 200
|
84
84
|
|
85
85
|
res.body[:data].map { |item| to_model(item) }
|
86
86
|
end
|
@@ -96,7 +96,7 @@ module TimeTree
|
|
96
96
|
def calendar_members(cal_id)
|
97
97
|
check_calendar_id cal_id
|
98
98
|
res = @http_cmd.get "/calendars/#{cal_id}/members"
|
99
|
-
raise ApiError
|
99
|
+
raise ApiError.new(res) if res.status != 200
|
100
100
|
|
101
101
|
res.body[:data].map { |item| to_model item }
|
102
102
|
end
|
@@ -118,7 +118,7 @@ module TimeTree
|
|
118
118
|
check_event_id event_id
|
119
119
|
params = relationships_params(include_relationships, Event::RELATIONSHIPS)
|
120
120
|
res = @http_cmd.get "/calendars/#{cal_id}/events/#{event_id}", params
|
121
|
-
raise ApiError
|
121
|
+
raise ApiError.new(res) if res.status != 200
|
122
122
|
|
123
123
|
ev = to_model(res.body[:data], included: res.body[:included])
|
124
124
|
ev.calendar_id = cal_id
|
@@ -142,7 +142,7 @@ module TimeTree
|
|
142
142
|
params = relationships_params(include_relationships, Event::RELATIONSHIPS)
|
143
143
|
params.merge!(days: days, timezone: timezone)
|
144
144
|
res = @http_cmd.get "/calendars/#{cal_id}/upcoming_events", params
|
145
|
-
raise ApiError
|
145
|
+
raise ApiError.new(res) if res.status != 200
|
146
146
|
|
147
147
|
included = res.body[:included]
|
148
148
|
res.body[:data].map do |item|
|
@@ -164,7 +164,7 @@ module TimeTree
|
|
164
164
|
def create_event(cal_id, params)
|
165
165
|
check_calendar_id cal_id
|
166
166
|
res = @http_cmd.post "/calendars/#{cal_id}/events", params
|
167
|
-
raise ApiError
|
167
|
+
raise ApiError.new(res) if res.status != 201
|
168
168
|
|
169
169
|
ev = to_model res.body[:data]
|
170
170
|
ev.calendar_id = cal_id
|
@@ -187,7 +187,7 @@ module TimeTree
|
|
187
187
|
check_calendar_id cal_id
|
188
188
|
check_event_id event_id
|
189
189
|
res = @http_cmd.put "/calendars/#{cal_id}/events/#{event_id}", params
|
190
|
-
raise ApiError
|
190
|
+
raise ApiError.new(res) if res.status != 200
|
191
191
|
|
192
192
|
ev = to_model res.body[:data]
|
193
193
|
ev.calendar_id = cal_id
|
@@ -208,7 +208,7 @@ module TimeTree
|
|
208
208
|
check_calendar_id cal_id
|
209
209
|
check_event_id event_id
|
210
210
|
res = @http_cmd.delete "/calendars/#{cal_id}/events/#{event_id}"
|
211
|
-
raise ApiError
|
211
|
+
raise ApiError.new(res) if res.status != 204
|
212
212
|
|
213
213
|
true
|
214
214
|
end
|
@@ -229,7 +229,7 @@ module TimeTree
|
|
229
229
|
check_calendar_id cal_id
|
230
230
|
check_event_id event_id
|
231
231
|
res = @http_cmd.post "/calendars/#{cal_id}/events/#{event_id}/activities", params
|
232
|
-
raise ApiError
|
232
|
+
raise ApiError.new(res) if res.status != 201
|
233
233
|
|
234
234
|
activity = to_model res.body[:data]
|
235
235
|
activity.calendar_id = cal_id
|
@@ -262,7 +262,7 @@ module TimeTree
|
|
262
262
|
@ratelimit_reset_at = Time.at reset.to_i if reset
|
263
263
|
end
|
264
264
|
|
265
|
-
|
265
|
+
private
|
266
266
|
|
267
267
|
def check_token
|
268
268
|
check_required_property(@token, 'token')
|
@@ -27,7 +27,7 @@ module TimeTree
|
|
27
27
|
# The request bodythat will eventually be converted to JSON.
|
28
28
|
def post(path, body_params = {})
|
29
29
|
@logger.debug "POST #{@host}#{path} body:#{body_params}"
|
30
|
-
headers = {
|
30
|
+
headers = {'Content-Type' => 'application/json'}
|
31
31
|
res = connection.run_request :post, path, body_params.to_json, headers
|
32
32
|
@client.update_ratelimit(res)
|
33
33
|
@logger.debug "Response status:#{res.status}, body:#{res.body}"
|
@@ -39,7 +39,7 @@ module TimeTree
|
|
39
39
|
# The request bodythat will eventually be converted to JSON.
|
40
40
|
def put(path, body_params = {})
|
41
41
|
@logger.debug "PUT #{@host}#{path} body:#{body_params}"
|
42
|
-
headers = {
|
42
|
+
headers = {'Content-Type' => 'application/json'}
|
43
43
|
res = connection.run_request :put, path, body_params.to_json, headers
|
44
44
|
@client.update_ratelimit(res)
|
45
45
|
@logger.debug "Response status:#{res.status}, body:#{res.body}"
|
@@ -56,14 +56,14 @@ module TimeTree
|
|
56
56
|
res
|
57
57
|
end
|
58
58
|
|
59
|
-
|
59
|
+
private
|
60
60
|
|
61
61
|
def connection
|
62
62
|
Faraday.new(
|
63
63
|
url: @host,
|
64
64
|
headers: base_request_headers
|
65
65
|
) do |builder|
|
66
|
-
builder.response :json, parser_options: {
|
66
|
+
builder.response :json, parser_options: {symbolize_names: true}, content_type: /\bjson$/
|
67
67
|
end
|
68
68
|
end
|
69
69
|
|
@@ -4,7 +4,7 @@ require 'time'
|
|
4
4
|
|
5
5
|
module TimeTree
|
6
6
|
# TimeTree base model object.
|
7
|
-
class BaseModel
|
7
|
+
class BaseModel # rubocop:disable Metrics/ClassLength
|
8
8
|
# @return [Array<Hash<String,String>>]
|
9
9
|
attr_accessor :relationships
|
10
10
|
# @return [String]
|
@@ -20,10 +20,10 @@ module TimeTree
|
|
20
20
|
# A TimeTree model object that be based on the type.
|
21
21
|
# @raise [TimeTree::Error] if the type property is not set or unknown.
|
22
22
|
# @since 0.0.1
|
23
|
-
def self.to_model(data, included: nil, client: nil)
|
23
|
+
def self.to_model(data, included: nil, client: nil) # rubocop:disable all
|
24
24
|
id = data[:id]
|
25
25
|
type = data[:type]
|
26
|
-
raise Error
|
26
|
+
raise Error.new('type is required.') if type.nil?
|
27
27
|
|
28
28
|
attributes = data[:attributes] || {}
|
29
29
|
relationships = data[:relationships] || {}
|
@@ -48,11 +48,11 @@ module TimeTree
|
|
48
48
|
when 'activity'
|
49
49
|
Activity.new(**params)
|
50
50
|
else
|
51
|
-
raise Error
|
51
|
+
raise Error.new("type '#{type}' is unknown.")
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
55
|
-
def initialize(type:, id: nil, client: nil, attributes: nil, relationships: nil, included: nil)
|
55
|
+
def initialize(type:, id: nil, client: nil, attributes: nil, relationships: nil, included: nil) # rubocop:disable Metrics/ParameterLists
|
56
56
|
@type = type
|
57
57
|
@id = id
|
58
58
|
@client = client
|
@@ -64,31 +64,29 @@ module TimeTree
|
|
64
64
|
"\#<#{self.class}:#{object_id} id:#{id}>"
|
65
65
|
end
|
66
66
|
|
67
|
-
|
67
|
+
private
|
68
68
|
|
69
69
|
def check_client
|
70
|
-
raise Error
|
70
|
+
raise Error.new('@client is nil.') if @client.nil?
|
71
71
|
end
|
72
72
|
|
73
73
|
def to_model(data)
|
74
74
|
self.class.to_model data, client: @client
|
75
75
|
end
|
76
76
|
|
77
|
-
def set_attributes(attributes)
|
77
|
+
def set_attributes(attributes) # rubocop:disable Naming/AccessorMethodName
|
78
78
|
return unless attributes.is_a? Hash
|
79
79
|
return if attributes.empty?
|
80
80
|
|
81
81
|
attributes.each do |key, value|
|
82
82
|
next unless respond_to?("#{key}=".to_sym)
|
83
83
|
|
84
|
-
if defined?(self.class::TIME_FIELDS) && self.class::TIME_FIELDS.include?(key)
|
85
|
-
value = Time.parse value
|
86
|
-
end
|
84
|
+
value = Time.parse value if defined?(self.class::TIME_FIELDS) && self.class::TIME_FIELDS.include?(key)
|
87
85
|
instance_variable_set "@#{key}", value
|
88
86
|
end
|
89
87
|
end
|
90
88
|
|
91
|
-
def set_relationships(relationships, included)
|
89
|
+
def set_relationships(relationships, included) # rubocop:disable all
|
92
90
|
return unless relationships.is_a? Hash
|
93
91
|
return if relationships.empty?
|
94
92
|
return unless defined? self.class::RELATIONSHIPS
|
@@ -110,7 +108,7 @@ module TimeTree
|
|
110
108
|
set_relationship_data_if_included(included)
|
111
109
|
end
|
112
110
|
|
113
|
-
def set_relationship_data_if_included(included)
|
111
|
+
def set_relationship_data_if_included(included) # rubocop:disable all
|
114
112
|
@_relation_data_dic = {}
|
115
113
|
included.each do |data|
|
116
114
|
item = to_model(data)
|
@@ -90,7 +90,7 @@ module TimeTree
|
|
90
90
|
# @since 0.0.1
|
91
91
|
def create_comment(message)
|
92
92
|
check_client
|
93
|
-
params = {
|
93
|
+
params = {type: 'activity', attributes: {calendar_id: calendar_id, event_id: id, content: message}}
|
94
94
|
activity = to_model params
|
95
95
|
activity.create
|
96
96
|
end
|
@@ -120,14 +120,14 @@ module TimeTree
|
|
120
120
|
}
|
121
121
|
end
|
122
122
|
|
123
|
-
|
123
|
+
private
|
124
124
|
|
125
125
|
def relationships_params
|
126
|
-
current_label = label ? {
|
127
|
-
current_attendees = attendees ? attendees.map { |u| {
|
126
|
+
current_label = label ? {type: 'label', id: label.id} : relationships[:label]
|
127
|
+
current_attendees = attendees ? attendees.map { |u| {type: 'user', id: u.id} } : relationships[:attendees]
|
128
128
|
{
|
129
|
-
label: {
|
130
|
-
attendees: {
|
129
|
+
label: {data: current_label},
|
130
|
+
attendees: {data: current_attendees}
|
131
131
|
}
|
132
132
|
end
|
133
133
|
end
|
data/lib/timetree/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: timetree
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kenji Koshikawa
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-09-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -146,7 +146,7 @@ files:
|
|
146
146
|
- ".github/workflows/gem-push.yml"
|
147
147
|
- ".github/workflows/test.yml"
|
148
148
|
- ".gitignore"
|
149
|
-
- ".
|
149
|
+
- ".rubocop.yml"
|
150
150
|
- CHANGELOG.md
|
151
151
|
- CODE_OF_CONDUCT.md
|
152
152
|
- Gemfile
|
@@ -175,7 +175,7 @@ metadata:
|
|
175
175
|
homepage_uri: https://github.com/koshilife/timetree-api-ruby-client
|
176
176
|
source_code_uri: https://github.com/koshilife/timetree-api-ruby-client
|
177
177
|
changelog_uri: https://github.com/koshilife/timetree-api-ruby-client/blob/master/CHANGELOG.md
|
178
|
-
documentation_uri: https://www.rubydoc.info/gems/timetree/0.3.
|
178
|
+
documentation_uri: https://www.rubydoc.info/gems/timetree/0.3.1
|
179
179
|
post_install_message:
|
180
180
|
rdoc_options: []
|
181
181
|
require_paths:
|