timetree 0.1.2 → 0.1.3

This diff has not been reviewed by any users.
Log in in order to be able to vote.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: de434a07fd2b0d7024c41f1bc6a555a053fe07da002a60b91479a3f239a5bac6
4
- data.tar.gz: a6ab608d7d5bceb77e05d97b2243bc804171602d538f29494b3c6796737f7fc1
3
+ metadata.gz: 1a43c7c885e6f0f2e55fdcf9b6c145e13e981fea4fee23dc468f5f16923826c0
4
+ data.tar.gz: b1dffa32b6a9d80ebca9e6de06a030e43e9d2bfe895bf9ac5ad4fa687d8f3b4a
5
5
  SHA512:
6
- metadata.gz: 67ba773c6beef87fb6e23c9e386b6d685ac4317b99516690ca321f3c216df695fa9a5b7a33c979dd142e37cd95d9ab0f400ffb3c421f77ac20339b2ed344495c
7
- data.tar.gz: 85957d72ca8df7f9be67cfaa7b962d892add2a3d2c5745efd41d89a0120553628e36c828de5b6b482e57e0cce7a67ce9959df2542222e4217f339a495283997c
6
+ metadata.gz: be24215ef1f52ccb2b0c8a8ce87f29dc2132e5987ba99533c73017cbc6a669d45dd5d565c1ff3fa1824d66cadeeddaf91f36ccaf6abd1150c755e0f836383e18
7
+ data.tar.gz: 1eb41d1864cabaf26293102c7a1b288da4e36930bce4599270e9e57e3b00e85a03e1d0bf2296f1d52ba0d26fcc4418ce287fc45a382da63c99c66209840890c3
data/.gitignore CHANGED
@@ -7,4 +7,5 @@
7
7
  /spec/reports/
8
8
  /tmp/
9
9
 
10
+ coverage
10
11
  Gemfile.lock
@@ -1,3 +1,7 @@
1
+ # 0.1.3
2
+
3
+ - refs #7 #9 make the code coverage 100%.
4
+
1
5
  # 0.1.2
2
6
 
3
7
  - refs #1 fix typo Event#recurrences to recurrence
data/README.md CHANGED
@@ -94,8 +94,6 @@ TimeTree.configuration.logger.level = :debug
94
94
  >> client.event 'cal_id_001', 'event_id_001_not_found'
95
95
  I, [2020-06-24T10:05:07.294807] INFO -- : GET https://timetreeapis.com/calendars/cal_id_001/events/event_id_001_not_found?include=creator%2Clabel%2Cattendees
96
96
  D, [2020-06-24T10:05:07.562038] DEBUG -- : Response status:404, body:{:type=>"https://developers.timetreeapp.com/en/docs/api#client-failure", :title=>"Not Found", :status=>404, :errors=>"Event not found"}
97
- Traceback (most recent call last):
98
- TimeTree::ApiError (TimeTree::ApiError)
99
97
  ```
100
98
 
101
99
  ## Contributing
@@ -28,10 +28,7 @@ module TimeTree
28
28
  # @raise [TimeTree::ApiError] if the http response status will not success.
29
29
  # @since 0.0.1
30
30
  def create
31
- raise Error, '@client is nil.' if @client.nil?
32
- raise Error, 'calendar_id is required.' if calendar_id.nil?
33
- raise Error, 'event_id is required.' if event_id.nil?
34
-
31
+ check_client
35
32
  @client.create_activity calendar_id, event_id, data_params
36
33
  end
37
34
 
@@ -50,9 +50,9 @@ module TimeTree
50
50
  end
51
51
  end
52
52
 
53
- def initialize(id:, type:, client: nil, attributes: nil, relationships: nil, included: nil)
54
- @id = id
53
+ def initialize(type:, id: nil, client: nil, attributes: nil, relationships: nil, included: nil)
55
54
  @type = type
55
+ @id = id
56
56
  @client = client
57
57
  set_attributes attributes
58
58
  set_relationships relationships, included
@@ -64,6 +64,10 @@ module TimeTree
64
64
 
65
65
  private
66
66
 
67
+ def check_client
68
+ raise Error, '@client is nil.' if @client.nil?
69
+ end
70
+
67
71
  def to_model(data)
68
72
  self.class.to_model data, client: @client
69
73
  end
@@ -29,8 +29,7 @@ module TimeTree
29
29
  # @raise [TimeTree::ApiError] if the http response status will not success.
30
30
  # @since 0.0.1
31
31
  def event(event_id)
32
- raise Error, '@client is nil.' if @client.nil?
33
-
32
+ check_client
34
33
  @client.event id, event_id
35
34
  end
36
35
 
@@ -46,37 +45,36 @@ module TimeTree
46
45
  # @raise [TimeTree::ApiError] if the http response status will not success.
47
46
  # @since 0.0.1
48
47
  def upcoming_events(days: 7, timezone: 'UTC')
49
- raise Error, '@client is nil.' if @client.nil?
50
-
48
+ check_client
51
49
  @client.upcoming_events id, days: days, timezone: timezone
52
50
  end
53
51
 
54
52
  #
55
- # Get a calendar's label information used in event.
53
+ # Get a calendar's member information.
56
54
  #
57
- # @return [Array<TimeTree::Label>]
55
+ # @return [Array<TimeTree::User>]
58
56
  # @raise [TimeTree::Error] if @client is not set.
59
57
  # @raise [TimeTree::ApiError] if the http response status will not success.
60
58
  # @since 0.0.1
61
- def labels
62
- return @labels if defined? @labels
63
- raise Error, '@client is nil.' if @client.nil?
59
+ def members
60
+ return @members if defined? @members
64
61
 
65
- @labels = @client.calendar_labels id
62
+ check_client
63
+ @members = @client.calendar_members id
66
64
  end
67
65
 
68
66
  #
69
- # Get a calendar's member information.
67
+ # Get a calendar's label information used in event.
70
68
  #
71
- # @return [Array<TimeTree::User>]
69
+ # @return [Array<TimeTree::Label>]
72
70
  # @raise [TimeTree::Error] if @client is not set.
73
71
  # @raise [TimeTree::ApiError] if the http response status will not success.
74
72
  # @since 0.0.1
75
- def members
76
- return @members if defined? @members
77
- raise Error, '@client is nil.' if @client.nil?
73
+ def labels
74
+ return @labels if defined? @labels
78
75
 
79
- @members = @client.calendar_members id
76
+ check_client
77
+ @labels = @client.calendar_labels id
80
78
  end
81
79
  end
82
80
  end
@@ -16,8 +16,7 @@ module TimeTree
16
16
  # @param token [String] a TimeTree's access token.
17
17
  def initialize(token = nil)
18
18
  @token = token || TimeTree.configuration.token
19
- raise Error, 'token is required.' unless ready_token?
20
-
19
+ check_token
21
20
  @http_cmd = HttpCommand.new(API_HOST, self)
22
21
  end
23
22
 
@@ -44,6 +43,7 @@ module TimeTree
44
43
  # @raise [TimeTree::ApiError] if the http response status will not success.
45
44
  # @since 0.0.1
46
45
  def calendar(cal_id, include_relationships: nil)
46
+ check_calendar_id cal_id
47
47
  params = relationships_params(include_relationships, Calendar::RELATIONSHIPS)
48
48
  res = @http_cmd.get "/calendars/#{cal_id}", params
49
49
  raise ApiError, res if res.status != 200
@@ -76,6 +76,7 @@ module TimeTree
76
76
  # @raise [TimeTree::ApiError] if the http response status will not success.
77
77
  # @since 0.0.1
78
78
  def calendar_labels(cal_id)
79
+ check_calendar_id cal_id
79
80
  res = @http_cmd.get "/calendars/#{cal_id}/labels"
80
81
  raise ApiError, res if res.status != 200
81
82
 
@@ -90,6 +91,7 @@ module TimeTree
90
91
  # @raise [TimeTree::ApiError] if the http response status will not success.
91
92
  # @since 0.0.1
92
93
  def calendar_members(cal_id)
94
+ check_calendar_id cal_id
93
95
  res = @http_cmd.get "/calendars/#{cal_id}/members"
94
96
  raise ApiError, res if res.status != 200
95
97
 
@@ -107,6 +109,8 @@ module TimeTree
107
109
  # @raise [TimeTree::ApiError] if the http response status will not success.
108
110
  # @since 0.0.1
109
111
  def event(cal_id, event_id, include_relationships: nil)
112
+ check_calendar_id cal_id
113
+ check_event_id event_id
110
114
  params = relationships_params(include_relationships, Event::RELATIONSHIPS)
111
115
  res = @http_cmd.get "/calendars/#{cal_id}/events/#{event_id}", params
112
116
  raise ApiError, res if res.status != 200
@@ -128,6 +132,7 @@ module TimeTree
128
132
  # @raise [TimeTree::ApiError] if the http response status will not success.
129
133
  # @since 0.0.1
130
134
  def upcoming_events(cal_id, days: 7, timezone: 'UTC', include_relationships: nil)
135
+ check_calendar_id cal_id
131
136
  params = relationships_params(include_relationships, Event::RELATIONSHIPS)
132
137
  params.merge!(days: days, timezone: timezone)
133
138
  res = @http_cmd.get "/calendars/#{cal_id}/upcoming_events", params
@@ -150,6 +155,7 @@ module TimeTree
150
155
  # @raise [TimeTree::ApiError] if the http response status will not success.
151
156
  # @since 0.0.1
152
157
  def create_event(cal_id, params)
158
+ check_calendar_id cal_id
153
159
  res = @http_cmd.post "/calendars/#{cal_id}/events", params
154
160
  raise ApiError, res if res.status != 201
155
161
 
@@ -169,6 +175,8 @@ module TimeTree
169
175
  # @raise [TimeTree::ApiError] if the http response status will not success.
170
176
  # @since 0.0.1
171
177
  def update_event(cal_id, event_id, params)
178
+ check_calendar_id cal_id
179
+ check_event_id event_id
172
180
  res = @http_cmd.put "/calendars/#{cal_id}/events/#{event_id}", params
173
181
  raise ApiError, res if res.status != 200
174
182
 
@@ -186,6 +194,8 @@ module TimeTree
186
194
  # @raise [TimeTree::ApiError] if the http response status will not success.
187
195
  # @since 0.0.1
188
196
  def delete_event(cal_id, event_id)
197
+ check_calendar_id cal_id
198
+ check_event_id event_id
189
199
  res = @http_cmd.delete "/calendars/#{cal_id}/events/#{event_id}"
190
200
  raise ApiError, res if res.status != 204
191
201
 
@@ -203,6 +213,8 @@ module TimeTree
203
213
  # @raise [TimeTree::ApiError] if the nhttp response status is not success.
204
214
  # @since 0.0.1
205
215
  def create_activity(cal_id, event_id, params)
216
+ check_calendar_id cal_id
217
+ check_event_id event_id
206
218
  res = @http_cmd.post "/calendars/#{cal_id}/events/#{event_id}/activities", params
207
219
  raise ApiError, res if res.status != 201
208
220
 
@@ -214,10 +226,10 @@ module TimeTree
214
226
 
215
227
  def inspect
216
228
  limit_info = nil
217
- if @ratelimit_limit
229
+ if defined?(@ratelimit_limit) && @ratelimit_limit
218
230
  limit_info = " ratelimit:#{@ratelimit_remaining}/#{@ratelimit_limit}"
219
231
  end
220
- if @ratelimit_reset_at
232
+ if defined?(@ratelimit_reset_at) && @ratelimit_reset_at
221
233
  limit_info = "#{limit_info}, reset_at:#{@ratelimit_reset_at.strftime('%m/%d %R')}"
222
234
  end
223
235
  "\#<#{self.class}:#{object_id}#{limit_info}>"
@@ -239,12 +251,28 @@ module TimeTree
239
251
 
240
252
  private
241
253
 
242
- def to_model(data, included: nil)
243
- TimeTree::BaseModel.to_model data, client: self, included: included
254
+ def check_token
255
+ check_required_property(@token, 'token')
256
+ end
257
+
258
+ def check_calendar_id(value)
259
+ check_required_property(value, 'calendar_id')
260
+ end
261
+
262
+ def check_event_id(value)
263
+ check_required_property(value, 'event_id')
244
264
  end
245
265
 
246
- def ready_token?
247
- @token.is_a?(String) && !@token.empty?
266
+ def check_required_property(value, name)
267
+ err = Error.new "#{name} is required."
268
+ raise err if value.nil?
269
+ raise err if value.to_s.empty?
270
+
271
+ true
272
+ end
273
+
274
+ def to_model(data, included: nil)
275
+ TimeTree::BaseModel.to_model data, client: self, included: included
248
276
  end
249
277
 
250
278
  def relationships_params(relationships, default)
@@ -38,9 +38,9 @@ module TimeTree
38
38
  # @return [TimeTree::User]
39
39
  attr_reader :creator
40
40
  # @return [TimeTree::Label]
41
- attr_reader :label
41
+ attr_accessor :label
42
42
  # @return [Array<TimeTree::User>]
43
- attr_reader :attendees
43
+ attr_accessor :attendees
44
44
 
45
45
  TIME_FIELDS = %i[start_at end_at updated_at created_at].freeze
46
46
  RELATIONSHIPS = %i[creator label attendees].freeze
@@ -53,28 +53,10 @@ module TimeTree
53
53
  # @raise [TimeTree::ApiError] if the http response status will not success.
54
54
  # @since 0.0.1
55
55
  def create
56
- raise Error, 'client is required.' if @client.nil?
57
-
56
+ check_client
58
57
  @client.create_event calendar_id, data_params
59
58
  end
60
59
 
61
- #
62
- # Creates comment to the event.
63
- #
64
- # @return [TimeTree::Activity]
65
- # @raise [TimeTree::Error] if @client is not set.
66
- # @raise [TimeTree::ApiError] if the http response status will not success.
67
- # @since 0.0.1
68
- def create_comment(message)
69
- raise Error, '@client is nil.' if @client.nil?
70
-
71
- params = { type: 'activity', attributes: { calendar_id: calendar_id, event_id: id, content: message } }
72
- activity = to_model params
73
- return if activity.nil?
74
-
75
- activity.create
76
- end
77
-
78
60
  #
79
61
  # Updates the event.
80
62
  #
@@ -84,9 +66,7 @@ module TimeTree
84
66
  # @raise [TimeTree::ApiError] if the http response status will not success.
85
67
  # @since 0.0.1
86
68
  def update
87
- raise Error, '@client is nil.' if @client.nil?
88
- raise Error, 'id is required.' if id.nil?
89
-
69
+ check_client
90
70
  @client.update_event calendar_id, id, data_params
91
71
  end
92
72
 
@@ -99,12 +79,26 @@ module TimeTree
99
79
  # @raise [TimeTree::ApiError] if the http response status will not success.
100
80
  # @since 0.0.1
101
81
  def delete
102
- raise Error, '@client is nil.' if @client.nil?
103
- raise Error, 'id is required.' if id.nil?
104
-
82
+ check_client
105
83
  @client.delete_event calendar_id, id
106
84
  end
107
85
 
86
+ #
87
+ # Creates comment to the event.
88
+ #
89
+ # @return [TimeTree::Activity]
90
+ # @raise [TimeTree::Error] if @client is not set.
91
+ # @raise [TimeTree::ApiError] if the http response status will not success.
92
+ # @since 0.0.1
93
+ def create_comment(message)
94
+ check_client
95
+ params = { type: 'activity', attributes: { calendar_id: calendar_id, event_id: id, content: message } }
96
+ activity = to_model params
97
+ return if activity.nil?
98
+
99
+ activity.create
100
+ end
101
+
108
102
  #
109
103
  # convert to a TimeTree request body format.
110
104
  #
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TimeTree
4
- VERSION = '0.1.2'
4
+ VERSION = '0.1.3'
5
5
  end
@@ -37,4 +37,5 @@ Gem::Specification.new do |spec|
37
37
  spec.add_development_dependency 'minitest-reporters', '~> 1.4.2'
38
38
  spec.add_development_dependency 'rake', '~> 12.0'
39
39
  spec.add_development_dependency 'webmock', '~> 3.7.6'
40
+ spec.add_development_dependency 'simplecov', '~> 0.18.5'
40
41
  end
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.1.2
4
+ version: 0.1.3
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-06-24 00:00:00.000000000 Z
11
+ date: 2020-06-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -122,6 +122,20 @@ dependencies:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
124
  version: 3.7.6
125
+ - !ruby/object:Gem::Dependency
126
+ name: simplecov
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: 0.18.5
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: 0.18.5
125
139
  description: Client for accessing TimeTree APIs
126
140
  email:
127
141
  - koshikawa2009@gmail.com
@@ -160,7 +174,7 @@ metadata:
160
174
  homepage_uri: https://github.com/koshilife/timetree-api-ruby-client
161
175
  source_code_uri: https://github.com/koshilife/timetree-api-ruby-client
162
176
  changelog_uri: https://github.com/koshilife/timetree-api-ruby-client/blob/master/CHANGELOG.md
163
- documentation_uri: https://www.rubydoc.info/gems/timetree/0.1.2
177
+ documentation_uri: https://www.rubydoc.info/gems/timetree/0.1.3
164
178
  post_install_message:
165
179
  rdoc_options: []
166
180
  require_paths: