cronofy 0.41.1 → 0.43.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8c111d0cca6145ea7c22e1b5d59cbd374ebbb383465fa6bb6866282a5e3d17cf
4
- data.tar.gz: e71b275482d1114f9c034245b88272d33e79d144145a1432f962bc2e83f04584
3
+ metadata.gz: d54cc6508a1fbe83ed82a347dd2c0eca157106c8a8677ae666206248a7c88eaf
4
+ data.tar.gz: 5d83b697e030bfdc8c289d6e8cc52b53a66aa8a925c322cf98eae095835c6c7b
5
5
  SHA512:
6
- metadata.gz: 850f322c3b3da531046a21a913f01f3c26cd8c5f0942162980c6efb0261b5c2aac4d75a15936782fe1feb48e8f66be6d1775760e7cc91b14c41aebd569fe895b
7
- data.tar.gz: 88646380b347532093de32d2c37630406a72e4ccdfbbbbf8492968a05a6550f14073d1783feb39e6590ac09729a8d2a2da98767c517418129918bcf6b001b004
6
+ metadata.gz: 85de2f742b637d0f6914a2f2903fdfe65aae917d3ab542d318a2d00e7b1e306d8b2c1a20443d6fb80097d619f4b351cec383dc4a137289ccf35a85a8f812ca88
7
+ data.tar.gz: 4d23e7e1ac03282a809ca48d824491581652a48194b38b00d0dd2707c0add315490febebb2b8f2a1ad152b0d1e4bbbc2ffda84c83a380c65a35ba30afa31aefc
data/CHANGELOG.md CHANGED
@@ -1,3 +1,21 @@
1
+ ## [0.43.0]
2
+
3
+ * Allow Faraday connection options, such as request timeouts, to be passed to the client [#119]
4
+
5
+ ## [0.42.0]
6
+
7
+ * Add `authorize_with_service_account_inline` to receive service account authorization credentials in the response [#121]
8
+ * Remove Rack pin from the downgraded-hashie test Gemfile [#122]
9
+ * Upgrade Rake development dependency to 13.0 [#123]
10
+
11
+ ## [0.41.3]
12
+
13
+ * Bump Rack to version 2.2.25 [#120]
14
+
15
+ ## [0.41.2]
16
+
17
+ * Bump Rack to version 2.1.4 [#113]
18
+
1
19
  ## [0.41.1]
2
20
 
3
21
  * Loosen the version requirement on Hashie to allow 5.X [#114]
@@ -237,6 +255,8 @@
237
255
  [0.40.0]: https://github.com/cronofy/cronofy-ruby/releases/tag/v0.40.0
238
256
  [0.41.0]: https://github.com/cronofy/cronofy-ruby/releases/tag/v0.41.0
239
257
  [0.41.1]: https://github.com/cronofy/cronofy-ruby/releases/tag/v0.41.1
258
+ [0.42.0]: https://github.com/cronofy/cronofy-ruby/releases/tag/v0.42.0
259
+ [0.43.0]: https://github.com/cronofy/cronofy-ruby/releases/tag/v0.43.0
240
260
 
241
261
  [#13]: https://github.com/cronofy/cronofy-ruby/pull/13
242
262
  [#16]: https://github.com/cronofy/cronofy-ruby/pull/16
@@ -289,4 +309,10 @@
289
309
  [#104]: https://github.com/cronofy/cronofy-ruby/pull/104
290
310
  [#108]: https://github.com/cronofy/cronofy-ruby/pull/108
291
311
  [#111]: https://github.com/cronofy/cronofy-ruby/pull/111
312
+ [#113]: https://github.com/cronofy/cronofy-ruby/pull/113
292
313
  [#114]: https://github.com/cronofy/cronofy-ruby/pull/114
314
+ [#119]: https://github.com/cronofy/cronofy-ruby/pull/119
315
+ [#120]: https://github.com/cronofy/cronofy-ruby/pull/120
316
+ [#121]: https://github.com/cronofy/cronofy-ruby/pull/121
317
+ [#122]: https://github.com/cronofy/cronofy-ruby/pull/122
318
+ [#123]: https://github.com/cronofy/cronofy-ruby/pull/123
data/Gemfile CHANGED
@@ -2,4 +2,4 @@ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
4
 
5
- gem "rack", "~> 1.0"
5
+ gem "rack", "~> 2.2.25"
data/README.md CHANGED
@@ -29,15 +29,16 @@ to obtain an OAuth `client_id` and `client_secret` to be able to use the full AP
29
29
  ## Creating a client
30
30
 
31
31
  To make calls to the Cronofy API you must create a `Cronofy::Client`. This takes
32
- five keyword arguments, all of which are optional:
32
+ six keyword arguments, all of which are optional:
33
33
 
34
34
  ```ruby
35
35
  cronofy = Cronofy::Client.new(
36
- client_id: 'CLIENT_ID',
37
- client_secret: 'CLIENT_SECRET',
38
- access_token: 'ACCESS_TOKEN',
39
- refresh_token: 'REFRESH_TOKEN',
40
- data_center: :de
36
+ client_id: 'CLIENT_ID',
37
+ client_secret: 'CLIENT_SECRET',
38
+ access_token: 'ACCESS_TOKEN',
39
+ refresh_token: 'REFRESH_TOKEN',
40
+ data_center: :de,
41
+ connection_options: { request: { timeout: 10 } }
41
42
  )
42
43
  ```
43
44
 
@@ -54,6 +55,16 @@ be used if present.
54
55
 
55
56
  `data_center` is the two-letter designation for the data center you want to operate against - for example `:de` for Germany, or `:au` for Australia. When omitted, this defaults to the US data center.
56
57
 
58
+ `connection_options` is an optional Hash of [Faraday connection options](https://lostisland.github.io/faraday/#/customization/connection-options)
59
+ used for every request the client makes, for example to set request timeouts:
60
+
61
+ ```ruby
62
+ cronofy = Cronofy::Client.new(
63
+ access_token: 'ACCESS_TOKEN',
64
+ connection_options: { request: { open_timeout: 5, timeout: 10 } }
65
+ )
66
+ ```
67
+
57
68
  ## Authorization
58
69
 
59
70
  [API documentation](https://docs.cronofy.com/developers/api/authorization/request-authorization/)
data/cronofy.gemspec CHANGED
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
21
21
  spec.add_runtime_dependency "oauth2", ">= 2.0.4"
22
22
 
23
23
  spec.add_development_dependency "bundler", ">= 1.6", "< 3"
24
- spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "rake", "~> 13.0"
25
25
  spec.add_development_dependency "rspec", "~> 3.2"
26
26
  spec.add_development_dependency "webmock", "~> 3.9.1"
27
27
  end
data/lib/cronofy/auth.rb CHANGED
@@ -13,11 +13,12 @@ module Cronofy
13
13
  client_secret = options[:client_secret]
14
14
  data_center = options[:data_center]
15
15
  refresh_token = options[:refresh_token]
16
+ connection_options = options[:connection_options] || {}
16
17
 
17
18
  @client_credentials_missing = blank?(client_id) || blank?(client_secret)
18
19
 
19
- @auth_client = OAuth2::Client.new(client_id, client_secret, site: ::Cronofy.app_url(data_center), auth_scheme: :request_body, connection_opts: { headers: { "User-Agent" => "Cronofy Ruby #{::Cronofy::VERSION}" } })
20
- @api_client = OAuth2::Client.new(client_id, client_secret, site: ::Cronofy.api_url(data_center), auth_scheme: :request_body, connection_opts: { headers: { "User-Agent" => "Cronofy Ruby #{::Cronofy::VERSION}" } })
20
+ @auth_client = OAuth2::Client.new(client_id, client_secret, site: ::Cronofy.app_url(data_center), auth_scheme: :request_body, connection_opts: connection_opts(connection_options))
21
+ @api_client = OAuth2::Client.new(client_id, client_secret, site: ::Cronofy.api_url(data_center), auth_scheme: :request_body, connection_opts: connection_opts(connection_options))
21
22
 
22
23
  set_access_token(access_token, refresh_token) if access_token || refresh_token
23
24
  set_api_key(client_secret) if client_secret
@@ -174,5 +175,11 @@ module Cronofy
174
175
  def blank?(value)
175
176
  value.nil? || value.strip.empty?
176
177
  end
178
+
179
+ def connection_opts(connection_options)
180
+ headers = (connection_options[:headers] || {}).merge("User-Agent" => "Cronofy Ruby #{::Cronofy::VERSION}")
181
+
182
+ connection_options.merge(headers: headers)
183
+ end
177
184
  end
178
185
  end
@@ -29,6 +29,9 @@ module Cronofy
29
29
  # account (optional).
30
30
  # :data_center - An identifier to override the default data
31
31
  # center (optional).
32
+ # :connection_options - A Hash of Faraday connection options,
33
+ # such as request timeouts, used for every
34
+ # request made by the client (optional).
32
35
  def initialize(options = {})
33
36
  access_token = options[:access_token]
34
37
  refresh_token = options[:refresh_token]
@@ -42,7 +45,8 @@ module Cronofy
42
45
  client_secret: @client_secret,
43
46
  access_token: access_token,
44
47
  refresh_token: refresh_token,
45
- data_center: @data_center
48
+ data_center: @data_center,
49
+ connection_options: options[:connection_options]
46
50
  )
47
51
  end
48
52
 
@@ -674,6 +678,36 @@ module Cronofy
674
678
  nil
675
679
  end
676
680
 
681
+ # Public: Attempts to authorize the email with impersonation from a service
682
+ # account, receiving the credentials in the response rather than via a
683
+ # callback.
684
+ #
685
+ # email - the email address to impersonate
686
+ # scope - Array or String of scopes describing the access to
687
+ # request from the user to the users calendars (required).
688
+ #
689
+ # Returns Cronofy::Credentials for the impersonated user
690
+ #
691
+ # Raises Cronofy::CredentialsMissingError if no credentials available.
692
+ # Raises Cronofy::AuthenticationFailureError if the access token is no
693
+ # longer valid.
694
+ # Raises Cronofy::TooManyRequestsError if the request exceeds the rate
695
+ # limits for the application.
696
+ def authorize_with_service_account_inline(email, scope)
697
+ if scope.respond_to?(:join)
698
+ scope = scope.join(' ')
699
+ end
700
+
701
+ params = {
702
+ email: email,
703
+ scope: scope,
704
+ response_type: "inline",
705
+ }
706
+
707
+ response = post("/v1/service_account_authorizations", params)
708
+ Credentials.new(OAuth2::AccessToken.from_hash(@auth.api_client, response.parsed))
709
+ end
710
+
677
711
  # Public: Generates a URL to send the user to in order to perform the OAuth
678
712
  # 2.0 authorization process.
679
713
  #
@@ -1995,7 +2029,7 @@ module Cronofy
1995
2029
  end
1996
2030
 
1997
2031
  def http_get(url, params = {})
1998
- response = Faraday.get(url, params, oauth_headers)
2032
+ response = access_token.client.connection.get(url, params, oauth_headers)
1999
2033
  Errors.raise_if_error(response)
2000
2034
  response
2001
2035
  end
@@ -2003,7 +2037,6 @@ module Cronofy
2003
2037
  def oauth_headers
2004
2038
  {
2005
2039
  "Authorization" => "Bearer #{access_token.token}",
2006
- "User-Agent" => "Cronofy Ruby #{::Cronofy::VERSION}",
2007
2040
  }
2008
2041
  end
2009
2042
 
@@ -1,3 +1,3 @@
1
1
  module Cronofy
2
- VERSION = "0.41.1".freeze
2
+ VERSION = "0.43.0".freeze
3
3
  end
@@ -205,15 +205,39 @@ describe Cronofy::Auth do
205
205
 
206
206
  describe '#get_token_from_code' do
207
207
  let(:data_center_override) { nil }
208
+ let(:connection_options) { nil }
208
209
 
209
210
  subject do
210
211
  Cronofy::Auth.new(
211
212
  client_id: client_id,
212
213
  client_secret: client_secret,
213
214
  data_center: data_center_override,
215
+ connection_options: connection_options,
214
216
  ).get_token_from_code(code, redirect_uri)
215
217
  end
216
218
 
219
+ context "with connection options" do
220
+ let(:connection_options) { { headers: { "X-Custom" => "custom" } } }
221
+
222
+ it "applies them to the token request" do
223
+ subject
224
+
225
+ expect(WebMock).to have_requested(:post, app_token_url)
226
+ .with(headers: { "User-Agent" => "Cronofy Ruby #{Cronofy::VERSION}", "X-Custom" => "custom" })
227
+ end
228
+
229
+ context "that set the User-Agent" do
230
+ let(:connection_options) { { headers: { "User-Agent" => "Custom Agent" } } }
231
+
232
+ it "keeps the Cronofy User-Agent" do
233
+ subject
234
+
235
+ expect(WebMock).to have_requested(:post, app_token_url)
236
+ .with(headers: { "User-Agent" => "Cronofy Ruby #{Cronofy::VERSION}" })
237
+ end
238
+ end
239
+ end
240
+
217
241
  context "with account_id" do
218
242
  let(:account_id) { "acc_0123456789abc" }
219
243
 
@@ -388,6 +412,40 @@ describe Cronofy::Auth do
388
412
 
389
413
  it_behaves_like 'an authorization request'
390
414
  end
415
+
416
+ context "with connection options" do
417
+ subject do
418
+ Cronofy::Auth.new(
419
+ client_id: client_id,
420
+ client_secret: client_secret,
421
+ access_token: access_token,
422
+ refresh_token: refresh_token,
423
+ connection_options: { headers: { "X-Custom" => "custom" } },
424
+ ).refresh!
425
+ end
426
+
427
+ it "applies them to the refresh request" do
428
+ subject
429
+
430
+ expect(WebMock).to have_requested(:post, api_token_url)
431
+ .with(headers: { "User-Agent" => "Cronofy Ruby #{Cronofy::VERSION}", "X-Custom" => "custom" })
432
+ end
433
+ end
434
+ end
435
+
436
+ describe "connection options" do
437
+ subject do
438
+ Cronofy::Auth.new(
439
+ client_id: client_id,
440
+ client_secret: client_secret,
441
+ connection_options: { request: { open_timeout: 5, timeout: 10 } },
442
+ )
443
+ end
444
+
445
+ it "sets the request timeouts" do
446
+ expect(subject.api_client.connection.options.open_timeout).to eq 5
447
+ expect(subject.api_client.connection.options.timeout).to eq 10
448
+ end
391
449
  end
392
450
 
393
451
  describe "#revoke!" do
@@ -455,6 +455,25 @@ describe Cronofy::Client do
455
455
  client.read_events(params).to_a
456
456
  end
457
457
 
458
+ context 'when connection options are given' do
459
+ let(:client) do
460
+ Cronofy::Client.new(
461
+ client_id: 'client_id_123',
462
+ client_secret: 'client_secret_456',
463
+ access_token: token,
464
+ refresh_token: 'refresh_token_456',
465
+ connection_options: { headers: { "X-Custom" => "custom" } },
466
+ )
467
+ end
468
+
469
+ it 'applies them to every page request' do
470
+ subject
471
+
472
+ expect(WebMock).to have_requested(:get, request_url).with(headers: { "X-Custom" => "custom" })
473
+ expect(WebMock).to have_requested(:get, next_page_url).with(headers: { "X-Custom" => "custom" })
474
+ end
475
+ end
476
+
458
477
  context 'when all params are passed' do
459
478
  let(:params) do
460
479
  {
@@ -671,6 +690,47 @@ describe Cronofy::Client do
671
690
  it_behaves_like 'a Cronofy request'
672
691
  end
673
692
 
693
+ describe 'Service Account impersonation with an inline response' do
694
+ let(:request_url) { "https://api.cronofy.com/v1/service_account_authorizations" }
695
+ let(:method) { :post }
696
+ let(:request_headers) { json_request_headers }
697
+ let(:request_body) { { email: email, scope: scope.join(' '), response_type: "inline" } }
698
+ let(:email) { "foo@example.com" }
699
+ let(:scope) { ['foo', 'bar'] }
700
+ let(:correct_response_code) { 200 }
701
+ let(:correct_response_body) do
702
+ {
703
+ token_type: "bearer",
704
+ access_token: "fffff",
705
+ expires_in: 3600,
706
+ refresh_token: "2222",
707
+ scope: scope.join(' '),
708
+ account_id: "acc_456",
709
+ sub: "acc_567",
710
+ }
711
+ end
712
+
713
+ subject { client.authorize_with_service_account_inline(email, scope) }
714
+
715
+ it_behaves_like 'a Cronofy request'
716
+
717
+ it "returns the credentials" do
718
+ stub_request(method, request_url)
719
+ .with(headers: request_headers, body: request_body)
720
+ .to_return(status: correct_response_code,
721
+ headers: correct_response_headers,
722
+ body: correct_response_body.to_json)
723
+
724
+ expect(subject).to be_a(Cronofy::Credentials)
725
+ expect(subject.access_token).to eq "fffff"
726
+ expect(subject.refresh_token).to eq "2222"
727
+ expect(subject.expires_in).to eq 3600
728
+ expect(subject.scope).to eq "foo bar"
729
+ expect(subject.account_id).to eq "acc_456"
730
+ expect(subject.sub).to eq "acc_567"
731
+ end
732
+ end
733
+
674
734
  describe 'Channels' do
675
735
  let(:request_url) { 'https://api.cronofy.com/v1/channels' }
676
736
 
@@ -52,7 +52,10 @@ describe Cronofy::Errors do
52
52
  end
53
53
 
54
54
  it "includes the errors in the message" do
55
- expect(subject.message).to eq('message - {"event_id"=>[{"key"=>"errors.required", "description"=>"required"}]}')
55
+ deserialized_errors = JSON.parse(body)["errors"]
56
+
57
+ # Hash#inspect output differs between Ruby versions
58
+ expect(subject.message).to eq("message - #{deserialized_errors.inspect}")
56
59
  end
57
60
  end
58
61
 
metadata CHANGED
@@ -1,15 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cronofy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.41.1
4
+ version: 0.43.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergii Paryzhskyi
8
8
  - Garry Shutler
9
- autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2024-03-01 00:00:00.000000000 Z
11
+ date: 1980-01-02 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: hashie
@@ -71,14 +70,14 @@ dependencies:
71
70
  requirements:
72
71
  - - "~>"
73
72
  - !ruby/object:Gem::Version
74
- version: '10.0'
73
+ version: '13.0'
75
74
  type: :development
76
75
  prerelease: false
77
76
  version_requirements: !ruby/object:Gem::Requirement
78
77
  requirements:
79
78
  - - "~>"
80
79
  - !ruby/object:Gem::Version
81
- version: '10.0'
80
+ version: '13.0'
82
81
  - !ruby/object:Gem::Dependency
83
82
  name: rspec
84
83
  requirement: !ruby/object:Gem::Requirement
@@ -141,7 +140,6 @@ homepage: https://github.com/cronofy/cronofy-ruby
141
140
  licenses:
142
141
  - MIT
143
142
  metadata: {}
144
- post_install_message:
145
143
  rdoc_options: []
146
144
  require_paths:
147
145
  - lib
@@ -156,8 +154,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
156
154
  - !ruby/object:Gem::Version
157
155
  version: '0'
158
156
  requirements: []
159
- rubygems_version: 3.4.10
160
- signing_key:
157
+ rubygems_version: 3.6.9
161
158
  specification_version: 4
162
159
  summary: Cronofy - the scheduling platform for business
163
160
  test_files: