cronofy 0.8.3 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/cronofy/client.rb +42 -2
- data/lib/cronofy/errors.rb +8 -0
- data/lib/cronofy/version.rb +1 -1
- data/spec/lib/cronofy/client_spec.rb +116 -13
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 326fa8f77f51139784236c0a9e2f73cdc53edecc
|
4
|
+
data.tar.gz: 3b314897d498fcf530953ac9bd44bcfd7b21f533
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b36221de26d3abf310b4be4ce4ea29a7c02bf0858ea36f9924488559fd9db24dea773b07c0a8d47863f940bb0484b4349a1b6796538c437c25b6d9dd1325591c
|
7
|
+
data.tar.gz: d78d17162887646dbfc909290ceabc2fb2bd080253597a54c0aa3be452504d01112dd1b1b91c323734b023bdae071b211a419a2994e0a5b7d7c60194544209c9
|
data/lib/cronofy/client.rb
CHANGED
@@ -32,6 +32,32 @@ module Cronofy
|
|
32
32
|
@auth = Auth.new(client_id, client_secret, access_token, refresh_token)
|
33
33
|
end
|
34
34
|
|
35
|
+
# Public: Creates a new calendar for the account.
|
36
|
+
#
|
37
|
+
# profile_id - The String ID of the profile to create the calendar within.
|
38
|
+
# name - A String to use as the name of the calendar.
|
39
|
+
#
|
40
|
+
# See http://www.cronofy.com/developers/api/alpah#create-calendar for
|
41
|
+
# reference.
|
42
|
+
#
|
43
|
+
# Returns the created Calendar
|
44
|
+
#
|
45
|
+
# Raises Cronofy::CredentialsMissingError if no credentials available.
|
46
|
+
# Raises Cronofy::AuthenticationFailureError if the access token is no
|
47
|
+
# longer valid.
|
48
|
+
# Raises Cronofy::AuthorizationFailureError if the access token does not
|
49
|
+
# include the required scope.
|
50
|
+
# Raises Cronofy::InvalidRequestError if the request contains invalid
|
51
|
+
# parameters.
|
52
|
+
# Raises Cronofy::AccountLockedError if the profile is not in a writable
|
53
|
+
# state and so a calendar cannot be created.
|
54
|
+
# Raises Cronofy::TooManyRequestsError if the request exceeds the rate
|
55
|
+
# limits for the application.
|
56
|
+
def create_calendar(profile_id, name)
|
57
|
+
response = post("/v1/calendars", profile_id: profile_id, name: name)
|
58
|
+
parse_json(Calendar, "calendar", response)
|
59
|
+
end
|
60
|
+
|
35
61
|
# Public: Lists all the calendars for the account.
|
36
62
|
#
|
37
63
|
# See http://www.cronofy.com/developers/api#calendars for reference.
|
@@ -269,6 +295,18 @@ module Cronofy
|
|
269
295
|
# Public: Creates a notification channel with a callback URL
|
270
296
|
#
|
271
297
|
# callback_url - A String specifing the callback URL for the channel.
|
298
|
+
# options - The Hash options used to refine the notifications of the
|
299
|
+
# channel (default: {}):
|
300
|
+
# :filters - A Hash of filters to use for the notification
|
301
|
+
# channel (optional):
|
302
|
+
# :calendar_ids - An Array of calendar ID strings
|
303
|
+
# to restrict the returned events
|
304
|
+
# to (optional).
|
305
|
+
# :only_managed - A Boolean specifying whether
|
306
|
+
# only events that you are
|
307
|
+
# managing for the account should
|
308
|
+
# trigger notifications
|
309
|
+
# (optional).
|
272
310
|
#
|
273
311
|
# See http://www.cronofy.com/developers/api#create-channel for reference.
|
274
312
|
#
|
@@ -283,8 +321,10 @@ module Cronofy
|
|
283
321
|
# parameters.
|
284
322
|
# Raises Cronofy::TooManyRequestsError if the request exceeds the rate
|
285
323
|
# limits for the application.
|
286
|
-
def create_channel(callback_url)
|
287
|
-
|
324
|
+
def create_channel(callback_url, options = {})
|
325
|
+
params = options.merge(callback_url: callback_url)
|
326
|
+
|
327
|
+
response = post("/v1/channels", params)
|
288
328
|
parse_json(Channel, "channel", response)
|
289
329
|
end
|
290
330
|
|
data/lib/cronofy/errors.rb
CHANGED
@@ -52,9 +52,15 @@ module Cronofy
|
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
55
|
+
class AccountLockedError < APIError
|
56
|
+
end
|
57
|
+
|
55
58
|
class TooManyRequestsError < APIError
|
56
59
|
end
|
57
60
|
|
61
|
+
class ServerError < APIError
|
62
|
+
end
|
63
|
+
|
58
64
|
class UnknownError < APIError
|
59
65
|
end
|
60
66
|
|
@@ -66,7 +72,9 @@ module Cronofy
|
|
66
72
|
403 => AuthorizationFailureError,
|
67
73
|
404 => NotFoundError,
|
68
74
|
422 => InvalidRequestError,
|
75
|
+
423 => AccountLockedError,
|
69
76
|
429 => TooManyRequestsError,
|
77
|
+
500 => ServerError,
|
70
78
|
}.freeze
|
71
79
|
|
72
80
|
def self.map_error(error)
|
data/lib/cronofy/version.rb
CHANGED
@@ -102,7 +102,17 @@ describe Cronofy::Client do
|
|
102
102
|
expect{ subject }.to raise_error(::Cronofy::InvalidRequestError)
|
103
103
|
end
|
104
104
|
|
105
|
-
it 'raises
|
105
|
+
it 'raises AccountLockedError on 423s' do
|
106
|
+
stub_request(method, request_url)
|
107
|
+
.with(headers: request_headers,
|
108
|
+
body: request_body)
|
109
|
+
.to_return(status: 423,
|
110
|
+
headers: correct_response_headers,
|
111
|
+
body: correct_response_body.to_json)
|
112
|
+
expect{ subject }.to raise_error(::Cronofy::AccountLockedError)
|
113
|
+
end
|
114
|
+
|
115
|
+
it 'raises TooManyRequestsError on 429s' do
|
106
116
|
stub_request(method, request_url)
|
107
117
|
.with(headers: request_headers,
|
108
118
|
body: request_body)
|
@@ -111,6 +121,50 @@ describe Cronofy::Client do
|
|
111
121
|
body: correct_response_body.to_json)
|
112
122
|
expect{ subject }.to raise_error(::Cronofy::TooManyRequestsError)
|
113
123
|
end
|
124
|
+
|
125
|
+
it 'raises ServerError on 500s' do
|
126
|
+
stub_request(method, request_url)
|
127
|
+
.with(headers: request_headers,
|
128
|
+
body: request_body)
|
129
|
+
.to_return(status: 500,
|
130
|
+
headers: correct_response_headers,
|
131
|
+
body: correct_response_body.to_json)
|
132
|
+
expect{ subject }.to raise_error(::Cronofy::ServerError)
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
describe '#create_calendar' do
|
137
|
+
let(:request_url) { 'https://api.cronofy.com/v1/calendars' }
|
138
|
+
let(:method) { :post }
|
139
|
+
let(:request_body) do
|
140
|
+
{
|
141
|
+
:profile_id => "pro_1234",
|
142
|
+
:name => "Home",
|
143
|
+
}
|
144
|
+
end
|
145
|
+
|
146
|
+
let(:correct_response_code) { 200 }
|
147
|
+
let(:correct_response_body) do
|
148
|
+
{
|
149
|
+
"calendar" => {
|
150
|
+
"provider_name" => "google",
|
151
|
+
"profile_name" => "example@cronofy.com",
|
152
|
+
"calendar_id" => "cal_n23kjnwrw2_jsdfjksn234",
|
153
|
+
"calendar_name" => "Home",
|
154
|
+
"calendar_readonly" => false,
|
155
|
+
"calendar_deleted" => false
|
156
|
+
}
|
157
|
+
}
|
158
|
+
end
|
159
|
+
|
160
|
+
let(:correct_mapped_result) do
|
161
|
+
Cronofy::Calendar.new(correct_response_body["calendar"])
|
162
|
+
end
|
163
|
+
|
164
|
+
subject { client.create_calendar("pro_1234", "Home") }
|
165
|
+
|
166
|
+
it_behaves_like 'a Cronofy request'
|
167
|
+
it_behaves_like 'a Cronofy request with mapped return value'
|
114
168
|
end
|
115
169
|
|
116
170
|
describe '#list_calendars' do
|
@@ -177,14 +231,16 @@ describe Cronofy::Client do
|
|
177
231
|
}
|
178
232
|
end
|
179
233
|
let(:request_body) do
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
234
|
+
{
|
235
|
+
:event_id => "qTtZdczOccgaPncGJaCiLg",
|
236
|
+
:summary => "Board meeting",
|
237
|
+
:description => "Discuss plans for the next quarter.",
|
238
|
+
:start => encoded_start_datetime,
|
239
|
+
:end => encoded_end_datetime,
|
240
|
+
:location => {
|
241
|
+
:description => "Board room"
|
242
|
+
}
|
243
|
+
}
|
188
244
|
end
|
189
245
|
let(:correct_response_code) { 202 }
|
190
246
|
let(:correct_response_body) { nil }
|
@@ -391,6 +447,24 @@ describe Cronofy::Client do
|
|
391
447
|
it_behaves_like 'a Cronofy request with mapped return value'
|
392
448
|
end
|
393
449
|
|
450
|
+
context "when calendar_ids are passed" do
|
451
|
+
let(:params) do
|
452
|
+
{
|
453
|
+
calendar_ids: ["cal_1234_abcd", "cal_1234_efgh", "cal_5678_ijkl"],
|
454
|
+
}
|
455
|
+
end
|
456
|
+
|
457
|
+
let(:request_url) do
|
458
|
+
"#{request_url_prefix}?tzid=Etc/UTC" \
|
459
|
+
"&calendar_ids[]=cal_1234_abcd" \
|
460
|
+
"&calendar_ids[]=cal_1234_efgh" \
|
461
|
+
"&calendar_ids[]=cal_5678_ijkl"
|
462
|
+
end
|
463
|
+
|
464
|
+
it_behaves_like 'a Cronofy request'
|
465
|
+
it_behaves_like 'a Cronofy request with mapped return value'
|
466
|
+
end
|
467
|
+
|
394
468
|
context "next page not found" do
|
395
469
|
before do
|
396
470
|
stub_request(:get, next_page_url)
|
@@ -474,7 +548,6 @@ describe Cronofy::Client do
|
|
474
548
|
let(:method) { :post }
|
475
549
|
let(:callback_url) { 'http://call.back/url' }
|
476
550
|
let(:request_headers) { json_request_headers }
|
477
|
-
let(:request_body) { hash_including(:callback_url => callback_url) }
|
478
551
|
|
479
552
|
let(:correct_response_code) { 200 }
|
480
553
|
let(:correct_response_body) do
|
@@ -491,10 +564,40 @@ describe Cronofy::Client do
|
|
491
564
|
Cronofy::Channel.new(correct_response_body["channel"])
|
492
565
|
end
|
493
566
|
|
494
|
-
|
567
|
+
context "with filters" do
|
568
|
+
let(:request_body) do
|
569
|
+
{
|
570
|
+
callback_url: callback_url,
|
571
|
+
filters: filters,
|
572
|
+
}
|
573
|
+
end
|
495
574
|
|
496
|
-
|
497
|
-
|
575
|
+
let(:filters) do
|
576
|
+
{
|
577
|
+
calendar_ids: ["cal_1234_abcd", "cal_1234_efgh", "cal_5678_ijkl"],
|
578
|
+
only_managed: true,
|
579
|
+
future_parameter: "for flexibility",
|
580
|
+
}
|
581
|
+
end
|
582
|
+
|
583
|
+
subject { client.create_channel(callback_url, filters: filters) }
|
584
|
+
|
585
|
+
it_behaves_like 'a Cronofy request'
|
586
|
+
it_behaves_like 'a Cronofy request with mapped return value'
|
587
|
+
end
|
588
|
+
|
589
|
+
context "without filters" do
|
590
|
+
let(:request_body) do
|
591
|
+
{
|
592
|
+
callback_url: callback_url,
|
593
|
+
}
|
594
|
+
end
|
595
|
+
|
596
|
+
subject { client.create_channel(callback_url) }
|
597
|
+
|
598
|
+
it_behaves_like 'a Cronofy request'
|
599
|
+
it_behaves_like 'a Cronofy request with mapped return value'
|
600
|
+
end
|
498
601
|
end
|
499
602
|
|
500
603
|
describe '#list_channels' do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cronofy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sergii Paryzhskyi
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-
|
12
|
+
date: 2016-05-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: oauth2
|