cronofy 0.10.0 → 0.11.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/lib/cronofy/client.rb +82 -0
- data/lib/cronofy/types.rb +6 -0
- data/lib/cronofy/version.rb +1 -1
- data/spec/lib/cronofy/client_spec.rb +108 -0
- metadata +19 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e0de9ce12744013f0db7eb1dccbe156fc28451b1
|
4
|
+
data.tar.gz: 63f12bd7138884230847c5fb9797f135ca01232d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4f0e9d054650efa325932f5986cff49bd00b91b56edcd38bb2428675b097ce1278e53e4d7ed8f91848a59677ae1e459a2f146b40561f8cb341ae31abe87cda37
|
7
|
+
data.tar.gz: 870cf96a3fca25d8da9d73d3da16363e1f52d1a9b09a84c4bdc490557abe8bf60277f0fb3b74ffe568abc09595db87d63231af208cde2bb06849712ed1f24f6f
|
data/lib/cronofy/client.rb
CHANGED
@@ -401,6 +401,54 @@ module Cronofy
|
|
401
401
|
parse_collection(Profile, "profiles", response)
|
402
402
|
end
|
403
403
|
|
404
|
+
# Public: Retrieves the userinfo for the account
|
405
|
+
#
|
406
|
+
# See http://openid.net/specs/openid-connect-core-1_0.html#UserInfo for
|
407
|
+
# reference.
|
408
|
+
#
|
409
|
+
# Returns an UserInfo.
|
410
|
+
#
|
411
|
+
# Raises Cronofy::CredentialsMissingError if no credentials available.
|
412
|
+
# Raises Cronofy::AuthenticationFailureError if the access token is no
|
413
|
+
# longer valid.
|
414
|
+
# Raises Cronofy::AuthorizationFailureError if the access token does not
|
415
|
+
# include the required scope.
|
416
|
+
# Raises Cronofy::TooManyRequestsError if the request exceeds the rate
|
417
|
+
# limits for the application.
|
418
|
+
def userinfo
|
419
|
+
response = get("/v1/userinfo")
|
420
|
+
parse_json(UserInfo, nil, response)
|
421
|
+
end
|
422
|
+
|
423
|
+
# Public: Attempts to authorize the email with impersonation from a service
|
424
|
+
# account
|
425
|
+
#
|
426
|
+
# email - the email address to impersonate
|
427
|
+
# scope - Array or String of scopes describing the access to
|
428
|
+
# request from the user to the users calendars (required).
|
429
|
+
# callback_url - the url to callback to
|
430
|
+
#
|
431
|
+
# Returns nothing
|
432
|
+
#
|
433
|
+
# Raises Cronofy::CredentialsMissingError if no credentials available.
|
434
|
+
# Raises Cronofy::AuthenticationFailureError if the access token is no
|
435
|
+
# longer valid.
|
436
|
+
# Raises Cronofy::TooManyRequestsError if the request exceeds the rate
|
437
|
+
# limits for the application.
|
438
|
+
def authorize_with_service_account(email, scope, callback_url)
|
439
|
+
if scope.respond_to?(:join)
|
440
|
+
scope = scope.join(' ')
|
441
|
+
end
|
442
|
+
|
443
|
+
params = {
|
444
|
+
email: email,
|
445
|
+
scope: scope,
|
446
|
+
callback_url: callback_url
|
447
|
+
}
|
448
|
+
post("/v1/service_account_authorizations", params)
|
449
|
+
nil
|
450
|
+
end
|
451
|
+
|
404
452
|
# Public: Generates a URL to send the user to in order to perform the OAuth
|
405
453
|
# 2.0 authorization process.
|
406
454
|
#
|
@@ -477,6 +525,40 @@ module Cronofy
|
|
477
525
|
@auth.revoke!
|
478
526
|
end
|
479
527
|
|
528
|
+
# Public: Requests elevated permissions for a set of calendars.
|
529
|
+
#
|
530
|
+
# args - A Hash of options used to initialize the request (default: {}):
|
531
|
+
# :permissions - An Array of calendar permission hashes to set on
|
532
|
+
# the each hash must contain symbols for both
|
533
|
+
# `calendar_id` and `permission_level`
|
534
|
+
# :redirect_uri - A uri to redirect the end user back to after they
|
535
|
+
# have either granted or rejected the request for
|
536
|
+
# elevated permission.
|
537
|
+
#
|
538
|
+
# In the case of normal accounts:
|
539
|
+
# After making this call the end user will have to grant the extended
|
540
|
+
# permissions to their calendar via rhe url returned from the response.
|
541
|
+
#
|
542
|
+
# In the case of service accounts:
|
543
|
+
# After making this call the exteneded permissions will be granted provided
|
544
|
+
# the relevant scope has been granted to the account
|
545
|
+
#
|
546
|
+
# Returns a extended permissions response.
|
547
|
+
#
|
548
|
+
# Raises Cronofy::AuthenticationFailureError if the client ID and secret are
|
549
|
+
# not valid.
|
550
|
+
def elevated_permissions(args = {})
|
551
|
+
filtered_permissions = args[:permissions].map do |permission|
|
552
|
+
{ calendar_id: permission[:calendar_id], permission_level: permission[:permission_level] }
|
553
|
+
end
|
554
|
+
|
555
|
+
body = { permissions: filtered_permissions }
|
556
|
+
body[:redirect_uri] = args[:redirect_uri] if args[:redirect_uri]
|
557
|
+
|
558
|
+
response = post("/v1/permissions", body)
|
559
|
+
parse_json(PermissionsResponse, "permissions_request", response)
|
560
|
+
end
|
561
|
+
|
480
562
|
private
|
481
563
|
|
482
564
|
FREE_BUSY_DEFAULT_PARAMS = { tzid: "Etc/UTC" }.freeze
|
data/lib/cronofy/types.rb
CHANGED
@@ -187,6 +187,9 @@ module Cronofy
|
|
187
187
|
class Account < Hashie::Mash
|
188
188
|
end
|
189
189
|
|
190
|
+
class UserInfo < Hashie::Mash
|
191
|
+
end
|
192
|
+
|
190
193
|
class Calendar < Hashie::Mash
|
191
194
|
end
|
192
195
|
|
@@ -269,4 +272,7 @@ module Cronofy
|
|
269
272
|
|
270
273
|
class Profile < Hashie::Mash
|
271
274
|
end
|
275
|
+
|
276
|
+
class PermissionsResponse < Hashie::Mash
|
277
|
+
end
|
272
278
|
end
|
data/lib/cronofy/version.rb
CHANGED
@@ -541,6 +541,23 @@ describe Cronofy::Client do
|
|
541
541
|
end
|
542
542
|
end
|
543
543
|
|
544
|
+
describe 'Service Account impersonation' do
|
545
|
+
let(:calendar_id) { 'calendar_id_123'}
|
546
|
+
let(:request_url) { "https://api.cronofy.com/v1/service_account_authorizations" }
|
547
|
+
let(:method) { :post }
|
548
|
+
let(:request_headers) { json_request_headers }
|
549
|
+
let(:request_body) { { email: email, scope: scope.join(' '), callback_url: callback_url } }
|
550
|
+
let(:correct_response_code) { 202 }
|
551
|
+
let(:correct_response_body) { nil }
|
552
|
+
let(:email) { "foo@example.com" }
|
553
|
+
let(:scope) { ['foo', 'bar'] }
|
554
|
+
let(:callback_url) { "http://example.com/not_found" }
|
555
|
+
|
556
|
+
subject { client.authorize_with_service_account(email, scope, callback_url) }
|
557
|
+
|
558
|
+
it_behaves_like 'a Cronofy request'
|
559
|
+
end
|
560
|
+
|
544
561
|
describe 'Channels' do
|
545
562
|
let(:request_url) { 'https://api.cronofy.com/v1/channels' }
|
546
563
|
|
@@ -645,6 +662,71 @@ describe Cronofy::Client do
|
|
645
662
|
end
|
646
663
|
end
|
647
664
|
|
665
|
+
describe "ElevatedPermissions" do
|
666
|
+
|
667
|
+
describe '#elevated_permissions' do
|
668
|
+
let(:method) { :post }
|
669
|
+
let(:request_url) { "https://api.cronofy.com/v1/permissions" }
|
670
|
+
|
671
|
+
let(:correct_response_code) { 202 }
|
672
|
+
|
673
|
+
let(:redirect_uri) { "http://www.example.com/redirect" }
|
674
|
+
let(:permissions) do
|
675
|
+
[
|
676
|
+
{
|
677
|
+
calendar_id: "cal_1234567",
|
678
|
+
permission_level: "unrestricted"
|
679
|
+
},
|
680
|
+
{
|
681
|
+
calendar_id: "cal_1234453",
|
682
|
+
permission_level: "sandbox"
|
683
|
+
}
|
684
|
+
]
|
685
|
+
end
|
686
|
+
|
687
|
+
let(:request_body) do
|
688
|
+
{
|
689
|
+
permissions: permissions,
|
690
|
+
redirect_uri: redirect_uri,
|
691
|
+
}
|
692
|
+
end
|
693
|
+
|
694
|
+
let(:correct_mapped_result) do
|
695
|
+
Cronofy::PermissionsResponse.new(correct_response_body[:permissions_request])
|
696
|
+
end
|
697
|
+
|
698
|
+
describe "with uri supplied" do
|
699
|
+
let(:correct_response_body) do
|
700
|
+
{
|
701
|
+
permissions_request: {
|
702
|
+
url: "http://app.cronofy.com/permissions/"
|
703
|
+
}
|
704
|
+
}
|
705
|
+
end
|
706
|
+
|
707
|
+
subject { client.elevated_permissions(permissions: permissions, redirect_uri: redirect_uri) }
|
708
|
+
|
709
|
+
it_behaves_like 'a Cronofy request'
|
710
|
+
it_behaves_like 'a Cronofy request with mapped return value'
|
711
|
+
end
|
712
|
+
|
713
|
+
describe "without uri supplied" do
|
714
|
+
let(:correct_response_body) do
|
715
|
+
{
|
716
|
+
permissions_request: {
|
717
|
+
accepted: true
|
718
|
+
}
|
719
|
+
}
|
720
|
+
end
|
721
|
+
|
722
|
+
subject { client.elevated_permissions(permissions: permissions, redirect_uri: redirect_uri) }
|
723
|
+
|
724
|
+
it_behaves_like 'a Cronofy request'
|
725
|
+
it_behaves_like 'a Cronofy request with mapped return value'
|
726
|
+
end
|
727
|
+
end
|
728
|
+
end
|
729
|
+
|
648
730
|
describe "Account" do
|
649
731
|
let(:request_url) { "https://api.cronofy.com/v1/account" }
|
650
732
|
|
@@ -672,6 +754,32 @@ describe Cronofy::Client do
|
|
672
754
|
end
|
673
755
|
end
|
674
756
|
|
757
|
+
describe "Userinfo" do
|
758
|
+
let(:request_url) { "https://api.cronofy.com/v1/userinfo" }
|
759
|
+
|
760
|
+
describe "#userinfo" do
|
761
|
+
let(:method) { :get }
|
762
|
+
|
763
|
+
let(:correct_response_code) { 200 }
|
764
|
+
let(:correct_response_body) do
|
765
|
+
{
|
766
|
+
"sub" => "ser_5700a00eb0ccd07000000000",
|
767
|
+
"cronofy.type" => "service_account",
|
768
|
+
"cronofy.service_account.domain" => "example.com"
|
769
|
+
}
|
770
|
+
end
|
771
|
+
|
772
|
+
let(:correct_mapped_result) do
|
773
|
+
Cronofy::UserInfo.new(correct_response_body)
|
774
|
+
end
|
775
|
+
|
776
|
+
subject { client.userinfo }
|
777
|
+
|
778
|
+
it_behaves_like "a Cronofy request"
|
779
|
+
it_behaves_like "a Cronofy request with mapped return value"
|
780
|
+
end
|
781
|
+
end
|
782
|
+
|
675
783
|
describe 'Profiles' do
|
676
784
|
let(:request_url) { 'https://api.cronofy.com/v1/profiles' }
|
677
785
|
|
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.11.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sergii Paryzhskyi
|
@@ -15,90 +15,90 @@ dependencies:
|
|
15
15
|
name: oauth2
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
requirements:
|
18
|
-
- - ~>
|
18
|
+
- - "~>"
|
19
19
|
- !ruby/object:Gem::Version
|
20
20
|
version: '1.0'
|
21
21
|
type: :runtime
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
|
-
- - ~>
|
25
|
+
- - "~>"
|
26
26
|
- !ruby/object:Gem::Version
|
27
27
|
version: '1.0'
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: hashie
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
31
31
|
requirements:
|
32
|
-
- -
|
32
|
+
- - ">="
|
33
33
|
- !ruby/object:Gem::Version
|
34
34
|
version: '2.1'
|
35
|
-
- - <
|
35
|
+
- - "<"
|
36
36
|
- !ruby/object:Gem::Version
|
37
37
|
version: '4'
|
38
38
|
type: :runtime
|
39
39
|
prerelease: false
|
40
40
|
version_requirements: !ruby/object:Gem::Requirement
|
41
41
|
requirements:
|
42
|
-
- -
|
42
|
+
- - ">="
|
43
43
|
- !ruby/object:Gem::Version
|
44
44
|
version: '2.1'
|
45
|
-
- - <
|
45
|
+
- - "<"
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '4'
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
49
|
name: bundler
|
50
50
|
requirement: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - ~>
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '1.6'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
57
|
version_requirements: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - ~>
|
59
|
+
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '1.6'
|
62
62
|
- !ruby/object:Gem::Dependency
|
63
63
|
name: rake
|
64
64
|
requirement: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - ~>
|
66
|
+
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '10.0'
|
69
69
|
type: :development
|
70
70
|
prerelease: false
|
71
71
|
version_requirements: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - ~>
|
73
|
+
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '10.0'
|
76
76
|
- !ruby/object:Gem::Dependency
|
77
77
|
name: rspec
|
78
78
|
requirement: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- - ~>
|
80
|
+
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '3.2'
|
83
83
|
type: :development
|
84
84
|
prerelease: false
|
85
85
|
version_requirements: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- - ~>
|
87
|
+
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
89
|
version: '3.2'
|
90
90
|
- !ruby/object:Gem::Dependency
|
91
91
|
name: webmock
|
92
92
|
requirement: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- - ~>
|
94
|
+
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '1.21'
|
97
97
|
type: :development
|
98
98
|
prerelease: false
|
99
99
|
version_requirements: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
|
-
- - ~>
|
101
|
+
- - "~>"
|
102
102
|
- !ruby/object:Gem::Version
|
103
103
|
version: '1.21'
|
104
104
|
description: Ruby wrapper for Cronofy's unified calendar API
|
@@ -138,17 +138,17 @@ require_paths:
|
|
138
138
|
- lib
|
139
139
|
required_ruby_version: !ruby/object:Gem::Requirement
|
140
140
|
requirements:
|
141
|
-
- -
|
141
|
+
- - ">="
|
142
142
|
- !ruby/object:Gem::Version
|
143
143
|
version: '0'
|
144
144
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
145
145
|
requirements:
|
146
|
-
- -
|
146
|
+
- - ">="
|
147
147
|
- !ruby/object:Gem::Version
|
148
148
|
version: '0'
|
149
149
|
requirements: []
|
150
150
|
rubyforge_project:
|
151
|
-
rubygems_version: 2.
|
151
|
+
rubygems_version: 2.6.1
|
152
152
|
signing_key:
|
153
153
|
specification_version: 4
|
154
154
|
summary: Cronofy - one API for all the calendars
|
@@ -160,3 +160,4 @@ test_files:
|
|
160
160
|
- spec/lib/cronofy/event_spec.rb
|
161
161
|
- spec/response_parser_spec.rb
|
162
162
|
- spec/spec_helper.rb
|
163
|
+
has_rdoc:
|