cronofy 0.18.0 → 0.19.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/lib/cronofy/client.rb +138 -32
- data/lib/cronofy/types.rb +3 -0
- data/lib/cronofy/version.rb +1 -1
- data/spec/lib/cronofy/client_spec.rb +170 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4f999ccb12faff1b50ff5f6069670c5edaeecdba
|
4
|
+
data.tar.gz: a5eb234959601811c9518e60ee7f614b4e9a658c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3317567d3489c8d7621f99e3deb35a40dd08854ff19d14a5919bb89a6d21d59fc2a55f14e602f3bb1d39c7f1d8d559d9044708f4bf475f7bf1c69687f9422386
|
7
|
+
data.tar.gz: ef28b30f3a07e251ba34a785e87e849cb0b3deae030438a2ecaac9d4a1d3091b4187c5077c94ae22df40de47fb22e5021e1da4cf24caa4bbec15d7620256f74e
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
## [0.19.0]
|
2
|
+
|
3
|
+
* Support add to calendar #31]
|
4
|
+
|
1
5
|
## [0.18.0]
|
2
6
|
|
3
7
|
* Support multiple data centres [#30]
|
@@ -40,6 +44,7 @@
|
|
40
44
|
[0.16.0]: https://github.com/cronofy/cronofy-ruby/releases/tag/v0.16.0
|
41
45
|
[0.17.0]: https://github.com/cronofy/cronofy-ruby/releases/tag/v0.17.0
|
42
46
|
[0.18.0]: https://github.com/cronofy/cronofy-ruby/releases/tag/v0.18.0
|
47
|
+
[0.19.0]: https://github.com/cronofy/cronofy-ruby/releases/tag/v0.19.0
|
43
48
|
|
44
49
|
[#13]: https://github.com/cronofy/cronofy-ruby/pull/13
|
45
50
|
[#16]: https://github.com/cronofy/cronofy-ruby/pull/16
|
@@ -50,3 +55,4 @@
|
|
50
55
|
[#26]: https://github.com/cronofy/cronofy-ruby/pull/26
|
51
56
|
[#27]: https://github.com/cronofy/cronofy-ruby/pull/27
|
52
57
|
[#30]: https://github.com/cronofy/cronofy-ruby/pull/30
|
58
|
+
[#31]: https://github.com/cronofy/cronofy-ruby/pull/31
|
data/lib/cronofy/client.rb
CHANGED
@@ -27,15 +27,15 @@ module Cronofy
|
|
27
27
|
# centre (optional).
|
28
28
|
def initialize(options = {})
|
29
29
|
access_token = options[:access_token]
|
30
|
-
client_id = options.fetch(:client_id, ENV["CRONOFY_CLIENT_ID"])
|
31
|
-
client_secret = options.fetch(:client_secret, ENV["CRONOFY_CLIENT_SECRET"])
|
32
30
|
refresh_token = options[:refresh_token]
|
33
31
|
|
32
|
+
@client_id = options.fetch(:client_id, ENV["CRONOFY_CLIENT_ID"])
|
33
|
+
@client_secret = options.fetch(:client_secret, ENV["CRONOFY_CLIENT_SECRET"])
|
34
34
|
@data_centre = options[:data_centre]
|
35
35
|
|
36
36
|
@auth = Auth.new(
|
37
|
-
client_id: client_id,
|
38
|
-
client_secret: client_secret,
|
37
|
+
client_id: @client_id,
|
38
|
+
client_secret: @client_secret,
|
39
39
|
access_token: access_token,
|
40
40
|
refresh_token: refresh_token,
|
41
41
|
data_centre: @data_centre,
|
@@ -90,34 +90,40 @@ module Cronofy
|
|
90
90
|
# calendar_id - The String Cronofy ID for the calendar to upsert the event
|
91
91
|
# to.
|
92
92
|
# event - A Hash describing the event with symbolized keys:
|
93
|
-
# :event_id
|
94
|
-
#
|
95
|
-
#
|
96
|
-
# :summary
|
97
|
-
#
|
98
|
-
#
|
99
|
-
# :description
|
100
|
-
#
|
101
|
-
#
|
102
|
-
# :start
|
103
|
-
# :end
|
104
|
-
# :url
|
105
|
-
# :location
|
106
|
-
#
|
107
|
-
#
|
108
|
-
#
|
109
|
-
#
|
110
|
-
#
|
111
|
-
# :reminders
|
112
|
-
#
|
113
|
-
#
|
114
|
-
#
|
115
|
-
#
|
116
|
-
#
|
117
|
-
#
|
118
|
-
#
|
119
|
-
#
|
120
|
-
#
|
93
|
+
# :event_id - A String uniquely identifying the event for
|
94
|
+
# your application (note: this is NOT an ID
|
95
|
+
# generated by Cronofy).
|
96
|
+
# :summary - A String to use as the summary, sometimes
|
97
|
+
# referred to as the name or title, of the
|
98
|
+
# event.
|
99
|
+
# :description - A String to use as the description, sometimes
|
100
|
+
# referred to as the notes or body, of the
|
101
|
+
# event.
|
102
|
+
# :start - The Time or Date the event starts.
|
103
|
+
# :end - The Time or Date the event ends.
|
104
|
+
# :url - The URL associated with the event.
|
105
|
+
# :location - A Hash describing the location of the event
|
106
|
+
# with symbolized keys (optional):
|
107
|
+
# :description - A String describing the
|
108
|
+
# location.
|
109
|
+
# :lat - A String of the location's latitude.
|
110
|
+
# :long - A String of the location's longitude.
|
111
|
+
# :reminders - An Array of Hashes describing the desired
|
112
|
+
# reminders for the event. Reminders should be
|
113
|
+
# specified in priority order as, for example,
|
114
|
+
# when the underlying provider only supports a
|
115
|
+
# single reminder then the first reminder will
|
116
|
+
# be used.
|
117
|
+
# :minutes - An Integer specifying the number
|
118
|
+
# of minutes before the start of the
|
119
|
+
# event that the reminder should
|
120
|
+
# occur.
|
121
|
+
# :transparency - The transparency state for the event (optional).
|
122
|
+
# Accepted values are "transparent" and "opaque".
|
123
|
+
# :attendees - A Hash of :invite and :reject, each of which is
|
124
|
+
# an array of invitees to invite to or reject from
|
125
|
+
# the event. Invitees are represented by a hash of
|
126
|
+
# :email and :display_name (optional).
|
121
127
|
#
|
122
128
|
# Examples
|
123
129
|
#
|
@@ -193,6 +199,9 @@ module Cronofy
|
|
193
199
|
# after in order to be returned (optional).
|
194
200
|
# :calendar_ids - An Array of calendar ids for restricting the
|
195
201
|
# returned events (optional).
|
202
|
+
# :include_geo - A Boolean specifying whether the events should
|
203
|
+
# have their location.lat and location.long
|
204
|
+
# returned where available (optional).
|
196
205
|
#
|
197
206
|
# The first page will be retrieved eagerly so that common errors will happen
|
198
207
|
# inline. However, subsequent pages (if any) will be requested lazily.
|
@@ -690,6 +699,103 @@ module Cronofy
|
|
690
699
|
parse_collection(AvailablePeriod, "available_periods", response)
|
691
700
|
end
|
692
701
|
|
702
|
+
|
703
|
+
# Public: Generates an add to calendar link to start the OAuth process with
|
704
|
+
# an event to be automatically upserted
|
705
|
+
#
|
706
|
+
# oauth - A Hash describing the OAuth flow required:
|
707
|
+
# :scope - A String representing the scopes to ask for
|
708
|
+
# within the OAuth flow
|
709
|
+
# :redirect_uri - A String containing a url to redirect the
|
710
|
+
# user to after completing the OAuth flow.
|
711
|
+
# :scope - A String representing additional state to
|
712
|
+
# be passed within the OAuth flow.
|
713
|
+
#
|
714
|
+
# event - A Hash describing the event with symbolized keys:
|
715
|
+
# :event_id - A String uniquely identifying the event for
|
716
|
+
# your application (note: this is NOT an ID
|
717
|
+
# generated by Cronofy).
|
718
|
+
# :summary - A String to use as the summary, sometimes
|
719
|
+
# referred to as the name or title, of the
|
720
|
+
# event.
|
721
|
+
# :description - A String to use as the description, sometimes
|
722
|
+
# referred to as the notes or body, of the
|
723
|
+
# event.
|
724
|
+
# :start - The Time or Date the event starts.
|
725
|
+
# :end - The Time or Date the event ends.
|
726
|
+
# :url - The URL associated with the event.
|
727
|
+
# :location - A Hash describing the location of the event
|
728
|
+
# with symbolized keys (optional):
|
729
|
+
# :description - A String describing the
|
730
|
+
# location.
|
731
|
+
# :lat - A String of the location's latitude.
|
732
|
+
# :long - A String of the location's longitude.
|
733
|
+
# :reminders - An Array of Hashes describing the desired
|
734
|
+
# reminders for the event. Reminders should be
|
735
|
+
# specified in priority order as, for example,
|
736
|
+
# when the underlying provider only supports a
|
737
|
+
# single reminder then the first reminder will
|
738
|
+
# be used.
|
739
|
+
# :minutes - An Integer specifying the number
|
740
|
+
# of minutes before the start of the
|
741
|
+
# event that the reminder should
|
742
|
+
# occur.
|
743
|
+
# :transparency - The transparency state for the event (optional).
|
744
|
+
# Accepted values are "transparent" and "opaque".
|
745
|
+
# :attendees - A Hash of :invite and :reject, each of which is
|
746
|
+
# an array of invitees to invite to or reject from
|
747
|
+
# the event. Invitees are represented by a hash of
|
748
|
+
# :email and :display_name (optional).
|
749
|
+
#
|
750
|
+
# Examples
|
751
|
+
#
|
752
|
+
# client.add_to_calendar(
|
753
|
+
# oauth: {
|
754
|
+
# scopes: 'read_events delete_events',
|
755
|
+
# redirect_uri: 'http://www.example.com',
|
756
|
+
# state: 'example_state'
|
757
|
+
# }
|
758
|
+
# event: {
|
759
|
+
# event_id: "qTtZdczOccgaPncGJaCiLg",
|
760
|
+
# summary: "Board meeting",
|
761
|
+
# description: "Discuss plans for the next quarter.",
|
762
|
+
# start: Time.utc(2014, 8, 5, 15, 30),
|
763
|
+
# end: Time.utc(2014, 8, 5, 17, 30),
|
764
|
+
# location: {
|
765
|
+
# description: "Board room",
|
766
|
+
# lat: "1.2345",
|
767
|
+
# long: "0.1234"
|
768
|
+
# })
|
769
|
+
#
|
770
|
+
# See http://www.cronofy.com/developers/api#upsert-event for reference.
|
771
|
+
#
|
772
|
+
# Returns a AddToCalendarResponse.
|
773
|
+
#
|
774
|
+
# Raises Cronofy::CredentialsMissingError if no credentials available.
|
775
|
+
# Raises Cronofy::AuthenticationFailureError if the access token is no
|
776
|
+
# longer valid.
|
777
|
+
# Raises Cronofy::AuthorizationFailureError if the access token does not
|
778
|
+
# include the required scope.
|
779
|
+
# Raises Cronofy::NotFoundError if the calendar does not exist.
|
780
|
+
# Raises Cronofy::InvalidRequestError if the request contains invalid
|
781
|
+
# parameters.
|
782
|
+
# Raises Cronofy::TooManyRequestsError if the request exceeds the rate
|
783
|
+
# limits for the application.
|
784
|
+
def add_to_calendar(args = {})
|
785
|
+
body = {
|
786
|
+
client_id: @client_id,
|
787
|
+
client_secret: @client_secret,
|
788
|
+
oauth: args[:oauth],
|
789
|
+
event: args[:event],
|
790
|
+
}
|
791
|
+
|
792
|
+
body[:event][:start] = encode_event_time(body[:event][:start]) if body[:event][:start]
|
793
|
+
body[:event][:end] = encode_event_time(body[:event][:end]) if body[:event][:end]
|
794
|
+
|
795
|
+
response = post("/v1/add_to_calendar", body)
|
796
|
+
parse_json(AddToCalendarResponse, nil , response)
|
797
|
+
end
|
798
|
+
|
693
799
|
private
|
694
800
|
|
695
801
|
def translate_available_periods(periods)
|
data/lib/cronofy/types.rb
CHANGED
data/lib/cronofy/version.rb
CHANGED
@@ -225,6 +225,7 @@ describe Cronofy::Client do
|
|
225
225
|
let(:encoded_start_datetime) { "2014-08-05T15:30:00Z" }
|
226
226
|
let(:encoded_end_datetime) { "2014-08-05T17:00:00Z" }
|
227
227
|
let(:location) { { :description => "Board room" } }
|
228
|
+
let(:transparency) { nil }
|
228
229
|
|
229
230
|
let(:event) do
|
230
231
|
{
|
@@ -235,6 +236,7 @@ describe Cronofy::Client do
|
|
235
236
|
:end => end_datetime,
|
236
237
|
:url => url,
|
237
238
|
:location => location,
|
239
|
+
:transparency => transparency,
|
238
240
|
:reminders => [
|
239
241
|
{ :minutes => 60 },
|
240
242
|
{ :minutes => 0 },
|
@@ -251,6 +253,7 @@ describe Cronofy::Client do
|
|
251
253
|
:end => encoded_end_datetime,
|
252
254
|
:url => url.to_s,
|
253
255
|
:location => location,
|
256
|
+
:transparency => transparency,
|
254
257
|
:reminders => [
|
255
258
|
{ :minutes => 60 },
|
256
259
|
{ :minutes => 0 },
|
@@ -310,6 +313,12 @@ describe Cronofy::Client do
|
|
310
313
|
|
311
314
|
it_behaves_like 'a Cronofy request'
|
312
315
|
end
|
316
|
+
|
317
|
+
context 'when transparency present' do
|
318
|
+
let(:transparency) { "transparent" }
|
319
|
+
|
320
|
+
it_behaves_like 'a Cronofy request'
|
321
|
+
end
|
313
322
|
end
|
314
323
|
|
315
324
|
describe '#read_events' do
|
@@ -1264,6 +1273,71 @@ describe Cronofy::Client do
|
|
1264
1273
|
it_behaves_like 'a Cronofy request with mapped return value'
|
1265
1274
|
end
|
1266
1275
|
|
1276
|
+
context "member-specific calendars" do
|
1277
|
+
let(:request_body) do
|
1278
|
+
{
|
1279
|
+
"participants" => [
|
1280
|
+
{
|
1281
|
+
"members" => [
|
1282
|
+
{ "sub" => "acc_567236000909002" },
|
1283
|
+
{
|
1284
|
+
"sub" => "acc_678347111010113",
|
1285
|
+
"calendar_ids" => [
|
1286
|
+
"cal_1234_5678",
|
1287
|
+
"cal_9876_5432",
|
1288
|
+
]
|
1289
|
+
}
|
1290
|
+
],
|
1291
|
+
"required" => "all"
|
1292
|
+
}
|
1293
|
+
],
|
1294
|
+
"required_duration" => { "minutes" => 60 },
|
1295
|
+
"available_periods" => [
|
1296
|
+
{
|
1297
|
+
"start" => "2017-01-03T09:00:00Z",
|
1298
|
+
"end" => "2017-01-03T18:00:00Z"
|
1299
|
+
},
|
1300
|
+
{
|
1301
|
+
"start" => "2017-01-04T09:00:00Z",
|
1302
|
+
"end" => "2017-01-04T18:00:00Z"
|
1303
|
+
}
|
1304
|
+
]
|
1305
|
+
}
|
1306
|
+
end
|
1307
|
+
|
1308
|
+
let(:participants) do
|
1309
|
+
[
|
1310
|
+
{
|
1311
|
+
members: [
|
1312
|
+
{ sub: "acc_567236000909002" },
|
1313
|
+
{
|
1314
|
+
sub: "acc_678347111010113",
|
1315
|
+
calendar_ids: [
|
1316
|
+
"cal_1234_5678",
|
1317
|
+
"cal_9876_5432",
|
1318
|
+
],
|
1319
|
+
},
|
1320
|
+
],
|
1321
|
+
required: :all,
|
1322
|
+
}
|
1323
|
+
]
|
1324
|
+
end
|
1325
|
+
|
1326
|
+
let(:required_duration) do
|
1327
|
+
{ minutes: 60 }
|
1328
|
+
end
|
1329
|
+
|
1330
|
+
let(:available_periods) do
|
1331
|
+
[
|
1332
|
+
{ start: Time.parse("2017-01-03T09:00:00Z"), end: Time.parse("2017-01-03T18:00:00Z") },
|
1333
|
+
{ start: Time.parse("2017-01-04T09:00:00Z"), end: Time.parse("2017-01-04T18:00:00Z") },
|
1334
|
+
]
|
1335
|
+
end
|
1336
|
+
|
1337
|
+
it_behaves_like 'a Cronofy request'
|
1338
|
+
it_behaves_like 'a Cronofy request with mapped return value'
|
1339
|
+
end
|
1340
|
+
|
1267
1341
|
context "simple values to defaults" do
|
1268
1342
|
let(:participants) do
|
1269
1343
|
{ members: %w{acc_567236000909002 acc_678347111010113} }
|
@@ -1284,6 +1358,102 @@ describe Cronofy::Client do
|
|
1284
1358
|
end
|
1285
1359
|
end
|
1286
1360
|
|
1361
|
+
describe "Add to calendar" do
|
1362
|
+
let(:request_url) { "https://api.cronofy.com/v1/add_to_calendar" }
|
1363
|
+
let(:url) { URI("https://example.com") }
|
1364
|
+
let(:method) { :post }
|
1365
|
+
let(:request_headers) { json_request_headers }
|
1366
|
+
|
1367
|
+
let(:start_datetime) { Time.utc(2014, 8, 5, 15, 30, 0) }
|
1368
|
+
let(:end_datetime) { Time.utc(2014, 8, 5, 17, 0, 0) }
|
1369
|
+
let(:encoded_start_datetime) { "2014-08-05T15:30:00Z" }
|
1370
|
+
let(:encoded_end_datetime) { "2014-08-05T17:00:00Z" }
|
1371
|
+
let(:location) { { :description => "Board room" } }
|
1372
|
+
let(:transparency) { nil }
|
1373
|
+
let(:client_id) { 'example_id' }
|
1374
|
+
let(:client_secret) { 'example_secret' }
|
1375
|
+
let(:scope) { 'read_events delete_events' }
|
1376
|
+
let(:state) { 'example_state' }
|
1377
|
+
let(:redirect_uri) { 'http://example.com/redirect' }
|
1378
|
+
|
1379
|
+
let(:client) do
|
1380
|
+
Cronofy::Client.new(
|
1381
|
+
client_id: client_id,
|
1382
|
+
client_secret: client_secret,
|
1383
|
+
access_token: token,
|
1384
|
+
)
|
1385
|
+
end
|
1386
|
+
|
1387
|
+
let(:event) do
|
1388
|
+
{
|
1389
|
+
:event_id => "qTtZdczOccgaPncGJaCiLg",
|
1390
|
+
:summary => "Board meeting",
|
1391
|
+
:description => "Discuss plans for the next quarter.",
|
1392
|
+
:start => start_datetime,
|
1393
|
+
:end => end_datetime,
|
1394
|
+
:url => url,
|
1395
|
+
:location => location,
|
1396
|
+
:transparency => transparency,
|
1397
|
+
:reminders => [
|
1398
|
+
{ :minutes => 60 },
|
1399
|
+
{ :minutes => 0 },
|
1400
|
+
{ :minutes => 10 },
|
1401
|
+
],
|
1402
|
+
}
|
1403
|
+
end
|
1404
|
+
|
1405
|
+
let(:oauth_body) do
|
1406
|
+
{
|
1407
|
+
scope: scope,
|
1408
|
+
redirect_uri: redirect_uri,
|
1409
|
+
state: state,
|
1410
|
+
}
|
1411
|
+
end
|
1412
|
+
|
1413
|
+
let(:args) do
|
1414
|
+
{
|
1415
|
+
oauth: oauth_body,
|
1416
|
+
event: event,
|
1417
|
+
}
|
1418
|
+
end
|
1419
|
+
|
1420
|
+
let(:request_body) do
|
1421
|
+
{
|
1422
|
+
client_id: client_id,
|
1423
|
+
client_secret: client_secret,
|
1424
|
+
oauth: oauth_body,
|
1425
|
+
event: {
|
1426
|
+
:event_id => "qTtZdczOccgaPncGJaCiLg",
|
1427
|
+
:summary => "Board meeting",
|
1428
|
+
:description => "Discuss plans for the next quarter.",
|
1429
|
+
:start => encoded_start_datetime,
|
1430
|
+
:end => encoded_end_datetime,
|
1431
|
+
:url => url.to_s,
|
1432
|
+
:location => location,
|
1433
|
+
:transparency => transparency,
|
1434
|
+
:reminders => [
|
1435
|
+
{ :minutes => 60 },
|
1436
|
+
{ :minutes => 0 },
|
1437
|
+
{ :minutes => 10 },
|
1438
|
+
],
|
1439
|
+
}
|
1440
|
+
}
|
1441
|
+
end
|
1442
|
+
let(:correct_response_code) { 202 }
|
1443
|
+
let(:correct_response_body) do
|
1444
|
+
{
|
1445
|
+
oauth_url: "http://www.example.com/oauth?token=example"
|
1446
|
+
}
|
1447
|
+
end
|
1448
|
+
|
1449
|
+
subject { client.add_to_calendar(args) }
|
1450
|
+
|
1451
|
+
context 'when start/end are Times' do
|
1452
|
+
it_behaves_like 'a Cronofy request'
|
1453
|
+
end
|
1454
|
+
|
1455
|
+
end
|
1456
|
+
|
1287
1457
|
describe "Specified data centre" do
|
1288
1458
|
let(:data_centre) { :de }
|
1289
1459
|
|
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.19.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: 2017-
|
12
|
+
date: 2017-04-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: oauth2
|
@@ -149,7 +149,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
149
149
|
version: '0'
|
150
150
|
requirements: []
|
151
151
|
rubyforge_project:
|
152
|
-
rubygems_version: 2.6.
|
152
|
+
rubygems_version: 2.6.8
|
153
153
|
signing_key:
|
154
154
|
specification_version: 4
|
155
155
|
summary: Cronofy - one API for all the calendars
|