cronofy 0.17.0 → 0.18.0
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/CHANGELOG.md +6 -0
- data/lib/cronofy.rb +48 -4
- data/lib/cronofy/auth.rb +10 -4
- data/lib/cronofy/client.rb +17 -3
- data/lib/cronofy/version.rb +1 -1
- data/spec/lib/cronofy/auth_spec.rb +90 -12
- data/spec/lib/cronofy/client_spec.rb +40 -0
- 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: cf2e08298ccea5ded0fbfdda981849d4baa3afe0
|
4
|
+
data.tar.gz: 7e790d91714ec2aa9b426ae16e0348d7854878c6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1f90a02ae698495b2d3a6b904172a9cb69526a7fb729a45e3e4bf6de965dcc0de7d11d5ff1bc96d28ebe9a88b4087eee36041c4c1d6dc71c44ef291f8e660462
|
7
|
+
data.tar.gz: 9b80e6db0d04ab9687dc09dde40a5bf0ae1c076c837b3674ed19cc3e43abe41cdc3db2ce0c58eb080556e727ccc916e23d09afc40681bd1190e6897fd1917909
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
## [0.18.0]
|
2
|
+
|
3
|
+
* Support multiple data centres [#30]
|
4
|
+
|
1
5
|
## [0.17.0]
|
2
6
|
|
3
7
|
* Support member-specific available periods for Availability API [#27]
|
@@ -35,6 +39,7 @@
|
|
35
39
|
[0.15.0]: https://github.com/cronofy/cronofy-ruby/releases/tag/v0.15.0
|
36
40
|
[0.16.0]: https://github.com/cronofy/cronofy-ruby/releases/tag/v0.16.0
|
37
41
|
[0.17.0]: https://github.com/cronofy/cronofy-ruby/releases/tag/v0.17.0
|
42
|
+
[0.18.0]: https://github.com/cronofy/cronofy-ruby/releases/tag/v0.18.0
|
38
43
|
|
39
44
|
[#13]: https://github.com/cronofy/cronofy-ruby/pull/13
|
40
45
|
[#16]: https://github.com/cronofy/cronofy-ruby/pull/16
|
@@ -44,3 +49,4 @@
|
|
44
49
|
[#24]: https://github.com/cronofy/cronofy-ruby/pull/24
|
45
50
|
[#26]: https://github.com/cronofy/cronofy-ruby/pull/26
|
46
51
|
[#27]: https://github.com/cronofy/cronofy-ruby/pull/27
|
52
|
+
[#30]: https://github.com/cronofy/cronofy-ruby/pull/30
|
data/lib/cronofy.rb
CHANGED
@@ -7,19 +7,63 @@ require "cronofy/response_parser"
|
|
7
7
|
require 'json'
|
8
8
|
|
9
9
|
module Cronofy
|
10
|
-
def self.
|
11
|
-
@
|
10
|
+
def self.default_data_centre
|
11
|
+
@default_data_centre || ENV['CRONOFY_DATA_CENTRE']
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.default_data_centre=(value)
|
15
|
+
@default_data_centre = value
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.api_url(data_centre_override)
|
19
|
+
if data_centre_override
|
20
|
+
api_url_for_data_centre(data_centre_override)
|
21
|
+
else
|
22
|
+
ENV['CRONOFY_API_URL'] || api_url_for_data_centre(default_data_centre)
|
23
|
+
end
|
12
24
|
end
|
13
25
|
|
14
26
|
def self.api_url=(value)
|
15
27
|
@api_url = value
|
16
28
|
end
|
17
29
|
|
18
|
-
def self.
|
19
|
-
@
|
30
|
+
def self.api_url_for_data_centre(dc)
|
31
|
+
@api_urls ||= Hash.new do |hash, key|
|
32
|
+
if key.nil? || key.to_sym == :us
|
33
|
+
url = "https://api.cronofy.com"
|
34
|
+
else
|
35
|
+
url = "https://api-#{key}.cronofy.com"
|
36
|
+
end
|
37
|
+
|
38
|
+
hash[key] = url.freeze
|
39
|
+
end
|
40
|
+
|
41
|
+
@api_urls[dc]
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.app_url(data_centre_override)
|
45
|
+
if data_centre_override
|
46
|
+
app_url_for_data_centre(data_centre_override)
|
47
|
+
else
|
48
|
+
ENV['CRONOFY_APP_URL'] || app_url_for_data_centre(default_data_centre)
|
49
|
+
end
|
20
50
|
end
|
21
51
|
|
22
52
|
def self.app_url=(value)
|
23
53
|
@app_url = value
|
24
54
|
end
|
55
|
+
|
56
|
+
def self.app_url_for_data_centre(dc)
|
57
|
+
@app_urls ||= Hash.new do |hash, key|
|
58
|
+
if key.nil? || key.to_sym == :us
|
59
|
+
url = "https://app.cronofy.com"
|
60
|
+
else
|
61
|
+
url = "https://app-#{key}.cronofy.com"
|
62
|
+
end
|
63
|
+
|
64
|
+
hash[key] = url.freeze
|
65
|
+
end
|
66
|
+
|
67
|
+
@app_urls[dc]
|
68
|
+
end
|
25
69
|
end
|
data/lib/cronofy/auth.rb
CHANGED
@@ -5,13 +5,19 @@ module Cronofy
|
|
5
5
|
class Auth
|
6
6
|
attr_reader :access_token
|
7
7
|
|
8
|
-
def initialize(
|
8
|
+
def initialize(options = {})
|
9
|
+
access_token = options[:access_token]
|
10
|
+
client_id = options[:client_id]
|
11
|
+
client_secret = options[:client_secret]
|
12
|
+
data_centre = options[:data_centre]
|
13
|
+
refresh_token = options[:refresh_token]
|
14
|
+
|
9
15
|
@client_credentials_missing = blank?(client_id) || blank?(client_secret)
|
10
16
|
|
11
|
-
@auth_client = OAuth2::Client.new(client_id, client_secret, site: ::Cronofy.app_url, connection_opts: { headers: { "User-Agent" => "Cronofy Ruby #{::Cronofy::VERSION}" } })
|
12
|
-
@api_client = OAuth2::Client.new(client_id, client_secret, site: ::Cronofy.api_url, connection_opts: { headers: { "User-Agent" => "Cronofy Ruby #{::Cronofy::VERSION}" } })
|
17
|
+
@auth_client = OAuth2::Client.new(client_id, client_secret, site: ::Cronofy.app_url(data_centre), connection_opts: { headers: { "User-Agent" => "Cronofy Ruby #{::Cronofy::VERSION}" } })
|
18
|
+
@api_client = OAuth2::Client.new(client_id, client_secret, site: ::Cronofy.api_url(data_centre), connection_opts: { headers: { "User-Agent" => "Cronofy Ruby #{::Cronofy::VERSION}" } })
|
13
19
|
|
14
|
-
set_access_token(
|
20
|
+
set_access_token(access_token, refresh_token) if access_token || refresh_token
|
15
21
|
end
|
16
22
|
|
17
23
|
# Internal: generate a URL for authorizing the application with Cronofy
|
data/lib/cronofy/client.rb
CHANGED
@@ -23,13 +23,23 @@ module Cronofy
|
|
23
23
|
# ENV["CRONOFY_CLIENT_SECRET"]).
|
24
24
|
# :refresh_token - An existing refresh token String for the user's
|
25
25
|
# account (optional).
|
26
|
+
# :data_centre - An identifier to override the default data
|
27
|
+
# centre (optional).
|
26
28
|
def initialize(options = {})
|
27
29
|
access_token = options[:access_token]
|
28
30
|
client_id = options.fetch(:client_id, ENV["CRONOFY_CLIENT_ID"])
|
29
31
|
client_secret = options.fetch(:client_secret, ENV["CRONOFY_CLIENT_SECRET"])
|
30
32
|
refresh_token = options[:refresh_token]
|
31
33
|
|
32
|
-
@
|
34
|
+
@data_centre = options[:data_centre]
|
35
|
+
|
36
|
+
@auth = Auth.new(
|
37
|
+
client_id: client_id,
|
38
|
+
client_secret: client_secret,
|
39
|
+
access_token: access_token,
|
40
|
+
refresh_token: refresh_token,
|
41
|
+
data_centre: @data_centre,
|
42
|
+
)
|
33
43
|
end
|
34
44
|
|
35
45
|
# Public: Creates a new calendar for the account.
|
@@ -207,7 +217,7 @@ module Cronofy
|
|
207
217
|
params[tp] = to_iso8601(params[tp])
|
208
218
|
end
|
209
219
|
|
210
|
-
url =
|
220
|
+
url = api_url + "/v1/events"
|
211
221
|
PagedResultIterator.new(PagedEventsResult, :events, access_token!, url, params)
|
212
222
|
end
|
213
223
|
|
@@ -255,7 +265,7 @@ module Cronofy
|
|
255
265
|
params[tp] = to_iso8601(params[tp])
|
256
266
|
end
|
257
267
|
|
258
|
-
url =
|
268
|
+
url = api_url + "/v1/free_busy"
|
259
269
|
PagedResultIterator.new(PagedFreeBusyResult, :free_busy, access_token!, url, params)
|
260
270
|
end
|
261
271
|
|
@@ -891,6 +901,10 @@ module Cronofy
|
|
891
901
|
ResponseParser.new(response).parse_json(@page_parser)
|
892
902
|
end
|
893
903
|
end
|
904
|
+
|
905
|
+
def api_url
|
906
|
+
::Cronofy.api_url(@data_centre)
|
907
|
+
end
|
894
908
|
end
|
895
909
|
|
896
910
|
# Deprecated: Alias for Client for backwards compatibility.
|
data/lib/cronofy/version.rb
CHANGED
@@ -22,10 +22,13 @@ describe Cronofy::Auth do
|
|
22
22
|
WebMock.disable_net_connect!(allow_localhost: true)
|
23
23
|
end
|
24
24
|
|
25
|
+
let(:api_token_url) { "https://api.cronofy.com/oauth/token" }
|
26
|
+
let(:app_token_url) { "https://app.cronofy.com/oauth/token" }
|
27
|
+
|
25
28
|
let(:response_status) { 200 }
|
26
29
|
|
27
30
|
before(:each) do
|
28
|
-
stub_request(:post,
|
31
|
+
stub_request(:post, api_token_url)
|
29
32
|
.with(
|
30
33
|
body: {
|
31
34
|
client_id: client_id,
|
@@ -52,7 +55,7 @@ describe Cronofy::Auth do
|
|
52
55
|
}
|
53
56
|
)
|
54
57
|
|
55
|
-
stub_request(:post,
|
58
|
+
stub_request(:post, app_token_url)
|
56
59
|
.with(
|
57
60
|
body: {
|
58
61
|
client_id: client_id,
|
@@ -89,6 +92,7 @@ describe Cronofy::Auth do
|
|
89
92
|
let(:scheme) { 'https' }
|
90
93
|
let(:host) { 'app.cronofy.com' }
|
91
94
|
let(:path) { '/oauth/authorize' }
|
95
|
+
let(:data_centre_override) { nil }
|
92
96
|
let(:default_params) do
|
93
97
|
{
|
94
98
|
'client_id' => client_id,
|
@@ -99,7 +103,11 @@ describe Cronofy::Auth do
|
|
99
103
|
end
|
100
104
|
|
101
105
|
let(:auth) do
|
102
|
-
Cronofy::Auth.new(
|
106
|
+
Cronofy::Auth.new(
|
107
|
+
client_id: client_id,
|
108
|
+
client_secret: client_secret,
|
109
|
+
data_centre: data_centre_override,
|
110
|
+
)
|
103
111
|
end
|
104
112
|
|
105
113
|
subject do
|
@@ -147,6 +155,14 @@ describe Cronofy::Auth do
|
|
147
155
|
|
148
156
|
it_behaves_like 'a user auth link provider'
|
149
157
|
end
|
158
|
+
|
159
|
+
context 'when data centre overridden' do
|
160
|
+
let(:data_centre_override) { :de }
|
161
|
+
let(:host) { 'app-de.cronofy.com' }
|
162
|
+
let(:params) { default_params }
|
163
|
+
|
164
|
+
it_behaves_like 'a user auth link provider'
|
165
|
+
end
|
150
166
|
end
|
151
167
|
|
152
168
|
shared_examples 'an authorization request' do
|
@@ -188,7 +204,15 @@ describe Cronofy::Auth do
|
|
188
204
|
end
|
189
205
|
|
190
206
|
describe '#get_token_from_code' do
|
191
|
-
|
207
|
+
let(:data_centre_override) { nil }
|
208
|
+
|
209
|
+
subject do
|
210
|
+
Cronofy::Auth.new(
|
211
|
+
client_id: client_id,
|
212
|
+
client_secret: client_secret,
|
213
|
+
data_centre: data_centre_override,
|
214
|
+
).get_token_from_code(code, redirect_uri)
|
215
|
+
end
|
192
216
|
|
193
217
|
context "with account_id" do
|
194
218
|
let(:account_id) { "acc_0123456789abc" }
|
@@ -239,13 +263,26 @@ describe Cronofy::Auth do
|
|
239
263
|
end
|
240
264
|
end
|
241
265
|
|
266
|
+
context "with data centre overridden" do
|
267
|
+
let(:data_centre_override) { :de }
|
268
|
+
let(:api_token_url) { "https://api-de.cronofy.com/oauth/token" }
|
269
|
+
let(:app_token_url) { "https://app-de.cronofy.com/oauth/token" }
|
270
|
+
|
271
|
+
it_behaves_like 'an authorization request'
|
272
|
+
end
|
273
|
+
|
242
274
|
it_behaves_like 'an authorization request'
|
243
275
|
end
|
244
276
|
|
245
277
|
describe '#refresh!' do
|
246
278
|
context "access_token and refresh_token present" do
|
247
279
|
subject do
|
248
|
-
Cronofy::Auth.new(
|
280
|
+
Cronofy::Auth.new(
|
281
|
+
client_id: client_id,
|
282
|
+
client_secret: client_secret,
|
283
|
+
access_token: access_token,
|
284
|
+
refresh_token: refresh_token,
|
285
|
+
).refresh!
|
249
286
|
end
|
250
287
|
|
251
288
|
it_behaves_like 'an authorization request'
|
@@ -253,7 +290,11 @@ describe Cronofy::Auth do
|
|
253
290
|
|
254
291
|
context "no refresh_token" do
|
255
292
|
subject do
|
256
|
-
Cronofy::Auth.new(
|
293
|
+
Cronofy::Auth.new(
|
294
|
+
client_id: client_id,
|
295
|
+
client_secret: client_secret,
|
296
|
+
access_token: access_token,
|
297
|
+
).refresh!
|
257
298
|
end
|
258
299
|
|
259
300
|
it "raises a credentials missing error" do
|
@@ -263,7 +304,10 @@ describe Cronofy::Auth do
|
|
263
304
|
|
264
305
|
context "no access_token or refresh_token" do
|
265
306
|
subject do
|
266
|
-
Cronofy::Auth.new(
|
307
|
+
Cronofy::Auth.new(
|
308
|
+
client_id: client_id,
|
309
|
+
client_secret: client_secret,
|
310
|
+
).refresh!
|
267
311
|
end
|
268
312
|
|
269
313
|
it "raises a credentials missing error" do
|
@@ -273,11 +317,32 @@ describe Cronofy::Auth do
|
|
273
317
|
|
274
318
|
context "only refresh_token" do
|
275
319
|
subject do
|
276
|
-
Cronofy::Auth.new(
|
320
|
+
Cronofy::Auth.new(
|
321
|
+
client_id: client_id,
|
322
|
+
client_secret: client_secret,
|
323
|
+
refresh_token: refresh_token,
|
324
|
+
).refresh!
|
277
325
|
end
|
278
326
|
|
279
327
|
it_behaves_like 'an authorization request'
|
280
328
|
end
|
329
|
+
|
330
|
+
context "with data centre overridden" do
|
331
|
+
subject do
|
332
|
+
Cronofy::Auth.new(
|
333
|
+
client_id: client_id,
|
334
|
+
client_secret: client_secret,
|
335
|
+
access_token: access_token,
|
336
|
+
refresh_token: refresh_token,
|
337
|
+
data_centre: :de,
|
338
|
+
).refresh!
|
339
|
+
end
|
340
|
+
|
341
|
+
let(:api_token_url) { "https://api-de.cronofy.com/oauth/token" }
|
342
|
+
let(:app_token_url) { "https://app-de.cronofy.com/oauth/token" }
|
343
|
+
|
344
|
+
it_behaves_like 'an authorization request'
|
345
|
+
end
|
281
346
|
end
|
282
347
|
|
283
348
|
describe "#revoke!" do
|
@@ -315,7 +380,12 @@ describe Cronofy::Auth do
|
|
315
380
|
|
316
381
|
context "access_token and refresh_token present" do
|
317
382
|
let(:auth) do
|
318
|
-
Cronofy::Auth.new(
|
383
|
+
Cronofy::Auth.new(
|
384
|
+
client_id: client_id,
|
385
|
+
client_secret: client_secret,
|
386
|
+
access_token: access_token,
|
387
|
+
refresh_token: refresh_token,
|
388
|
+
)
|
319
389
|
end
|
320
390
|
|
321
391
|
let(:revoke_token) { refresh_token }
|
@@ -325,7 +395,11 @@ describe Cronofy::Auth do
|
|
325
395
|
|
326
396
|
context "only refresh_token" do
|
327
397
|
let(:auth) do
|
328
|
-
Cronofy::Auth.new(
|
398
|
+
Cronofy::Auth.new(
|
399
|
+
client_id: client_id,
|
400
|
+
client_secret: client_secret,
|
401
|
+
refresh_token: refresh_token,
|
402
|
+
)
|
329
403
|
end
|
330
404
|
|
331
405
|
let(:revoke_token) { refresh_token }
|
@@ -335,7 +409,11 @@ describe Cronofy::Auth do
|
|
335
409
|
|
336
410
|
context "only access_token" do
|
337
411
|
let(:auth) do
|
338
|
-
Cronofy::Auth.new(
|
412
|
+
Cronofy::Auth.new(
|
413
|
+
client_id: client_id,
|
414
|
+
client_secret: client_secret,
|
415
|
+
access_token: access_token,
|
416
|
+
)
|
339
417
|
end
|
340
418
|
|
341
419
|
let(:revoke_token) { access_token }
|
@@ -345,7 +423,7 @@ describe Cronofy::Auth do
|
|
345
423
|
|
346
424
|
context "no access_token or refresh_token" do
|
347
425
|
let(:auth) do
|
348
|
-
Cronofy::Auth.new(client_id, client_secret
|
426
|
+
Cronofy::Auth.new(client_id: client_id, client_secret: client_secret)
|
349
427
|
end
|
350
428
|
|
351
429
|
it "raises a credentials missing error" do
|
@@ -1283,4 +1283,44 @@ describe Cronofy::Client do
|
|
1283
1283
|
end
|
1284
1284
|
end
|
1285
1285
|
end
|
1286
|
+
|
1287
|
+
describe "Specified data centre" do
|
1288
|
+
let(:data_centre) { :de }
|
1289
|
+
|
1290
|
+
let(:client) do
|
1291
|
+
Cronofy::Client.new(
|
1292
|
+
client_id: 'client_id_123',
|
1293
|
+
client_secret: 'client_secret_456',
|
1294
|
+
access_token: token,
|
1295
|
+
refresh_token: 'refresh_token_456',
|
1296
|
+
data_centre: data_centre,
|
1297
|
+
)
|
1298
|
+
end
|
1299
|
+
|
1300
|
+
describe "Userinfo" do
|
1301
|
+
let(:request_url) { "https://api-#{data_centre}.cronofy.com/v1/userinfo" }
|
1302
|
+
|
1303
|
+
describe "#userinfo" do
|
1304
|
+
let(:method) { :get }
|
1305
|
+
|
1306
|
+
let(:correct_response_code) { 200 }
|
1307
|
+
let(:correct_response_body) do
|
1308
|
+
{
|
1309
|
+
"sub" => "ser_5700a00eb0ccd07000000000",
|
1310
|
+
"cronofy.type" => "service_account",
|
1311
|
+
"cronofy.service_account.domain" => "example.com"
|
1312
|
+
}
|
1313
|
+
end
|
1314
|
+
|
1315
|
+
let(:correct_mapped_result) do
|
1316
|
+
Cronofy::UserInfo.new(correct_response_body)
|
1317
|
+
end
|
1318
|
+
|
1319
|
+
subject { client.userinfo }
|
1320
|
+
|
1321
|
+
it_behaves_like "a Cronofy request"
|
1322
|
+
it_behaves_like "a Cronofy request with mapped return value"
|
1323
|
+
end
|
1324
|
+
end
|
1325
|
+
end
|
1286
1326
|
end
|
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.18.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-02-
|
12
|
+
date: 2017-02-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: oauth2
|