cronofy 0.34.0 → 0.37.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 78e9782a7bdba695815ed3931c13185e37fa84d20f450e922ebd906eb4ba74e0
4
- data.tar.gz: 5b43ef1fb59f670be1c8b59316b2b837d56ab9eb94f165c8b7764047d945780b
3
+ metadata.gz: a805a11bb064f04901d8cb57e9941bb71db91224c3c61f351b827c75074d1db5
4
+ data.tar.gz: ec146b1c4c31ced2d208bca1f066b15a4b162edacaac0bc0f7cf1da079f0d1d2
5
5
  SHA512:
6
- metadata.gz: 159294f3efa6c0ff5ce443e1610a532d2e4ede0758589a1b38abddd134b0e7f88ad63525f471dd0d6f002966b111503ce14b00d67ceca487f58b6bab3534d06c
7
- data.tar.gz: 040d8238dd7a35ea6810279da80453f45efcad258459bf49c68b959f5c54ee07816e8e437b82c040e1b3fa29a0a74a75e8b3919a0bee6e68a2ffa8c1733b08d1
6
+ metadata.gz: 38b1b55c2f736c9692c0e11ebd03d803709e485b7d51ce2522c0a32b2333b75faa2ca56658315f9390b44b7f6a0a1b3b2abfdeca98f22a94d8e4dddf6cada60c
7
+ data.tar.gz: 22645a8c38f429465ec6bcbacc2f8a9463a1895597d68b21f853a4c57c2630cb4db0adcbd1204d9a2187a33e598df0de9c94e20dd63794b9e807b621648df110
@@ -1,3 +1,23 @@
1
+ ## [0.37.1]
2
+
3
+ * Rename `data_centre` to `data_centre` (with aliases for backwards compatibility) [#90]
4
+
5
+ ## [0.37.0]
6
+
7
+ * Add `revoke_by_token` and `revoke_by_sub` to the Client [#86]
8
+
9
+ ## [0.36.1]
10
+
11
+ * Loosen the version requirement on Hashie to allow 4.X
12
+
13
+ ## [0.36.0]
14
+
15
+ * Add support for Available Periods [#81]
16
+
17
+ ## [0.35.0]
18
+
19
+ * Add specific errors for network issues [#77]
20
+
1
21
  ## [0.34.0]
2
22
 
3
23
  * Support removing a participant from a Smart Invite [#75]
@@ -157,6 +177,11 @@
157
177
  [0.32.0]: https://github.com/cronofy/cronofy-ruby/releases/tag/v0.32.0
158
178
  [0.33.0]: https://github.com/cronofy/cronofy-ruby/releases/tag/v0.33.0
159
179
  [0.34.0]: https://github.com/cronofy/cronofy-ruby/releases/tag/v0.34.0
180
+ [0.35.0]: https://github.com/cronofy/cronofy-ruby/releases/tag/v0.35.0
181
+ [0.36.0]: https://github.com/cronofy/cronofy-ruby/releases/tag/v0.36.0
182
+ [0.36.1]: https://github.com/cronofy/cronofy-ruby/releases/tag/v0.36.1
183
+ [0.37.0]: https://github.com/cronofy/cronofy-ruby/releases/tag/v0.37.0
184
+ [0.37.1]: https://github.com/cronofy/cronofy-ruby/releases/tag/v0.37.1
160
185
 
161
186
  [#13]: https://github.com/cronofy/cronofy-ruby/pull/13
162
187
  [#16]: https://github.com/cronofy/cronofy-ruby/pull/16
@@ -195,3 +220,8 @@
195
220
  [#73]: https://github.com/cronofy/cronofy-ruby/pull/73
196
221
  [#74]: https://github.com/cronofy/cronofy-ruby/pull/74
197
222
  [#75]: https://github.com/cronofy/cronofy-ruby/pull/75
223
+ [#77]: https://github.com/cronofy/cronofy-ruby/pull/77
224
+ [#81]: https://github.com/cronofy/cronofy-ruby/pull/81
225
+ [#85]: https://github.com/cronofy/cronofy-ruby/pull/85
226
+ [#86]: https://github.com/cronofy/cronofy-ruby/pull/86
227
+ [#90]: https://github.com/cronofy/cronofy-ruby/pull/90
data/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  [![Build Status](https://travis-ci.org/cronofy/cronofy-ruby.svg?branch=master)](https://travis-ci.org/cronofy/cronofy-ruby)
4
4
  [![Gem Version](https://badge.fury.io/rb/cronofy.svg)](http://badge.fury.io/rb/cronofy)
5
5
 
6
- [Cronofy](https://www.cronofy.com) - one API for all the calendars (Google, iCloud, Exchange, Office 365, Outlook.com)
6
+ [Cronofy](https://www.cronofy.com) - the scheduling platform for business
7
7
 
8
8
  ## Installation
9
9
 
@@ -23,22 +23,21 @@ bundle install
23
23
 
24
24
  In order to use the Cronofy API you will need to [create a developer account](https://app.cronofy.com/sign_up/new).
25
25
 
26
- From there you can [use your Calendar Sandbox](https://app.cronofy.com/oauth/sandbox)
27
- to access your own calendars, or you can [create an OAuth application](https://app.cronofy.com/oauth/applications/new)
28
- to obtain an OAuth `client_id` and `client_secret` to be able to use the full
29
- API.
26
+ From there you can [create an OAuth application](https://app.cronofy.com/oauth/applications/new)
27
+ to obtain an OAuth `client_id` and `client_secret` to be able to use the full API.
30
28
 
31
29
  ## Creating a client
32
30
 
33
31
  To make calls to the Cronofy API you must create a `Cronofy::Client`. This takes
34
- four keyword arguments, all of which are optional:
32
+ five keyword arguments, all of which are optional:
35
33
 
36
34
  ```ruby
37
35
  cronofy = Cronofy::Client.new(
38
36
  client_id: 'CLIENT_ID',
39
37
  client_secret: 'CLIENT_SECRET',
40
38
  access_token: 'ACCESS_TOKEN',
41
- refresh_token: 'REFRESH_TOKEN'
39
+ refresh_token: 'REFRESH_TOKEN',
40
+ data_center: :de
42
41
  )
43
42
  ```
44
43
 
@@ -53,6 +52,8 @@ If `client_id` and `client_secret` are not specified explicitly the values from
53
52
  the environment variables `CRONOFY_CLIENT_ID` and `CRONOFY_CLIENT_SECRET` will
54
53
  be used if present.
55
54
 
55
+ `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
+
56
57
  ## Authorization
57
58
 
58
59
  [API documentation](https://www.cronofy.com/developers/api/#authorization)
@@ -5,7 +5,7 @@ Gem::Specification.new do |spec|
5
5
  spec.version = Cronofy::VERSION
6
6
  spec.authors = ["Sergii Paryzhskyi", "Garry Shutler"]
7
7
  spec.email = ["parizhskiy@gmail.com", "garry@cronofy.com"]
8
- spec.summary = %q{Cronofy - one API for all the calendars}
8
+ spec.summary = %q{Cronofy - the scheduling platform for business}
9
9
  spec.description = %q{Ruby wrapper for Cronofy's unified calendar API}
10
10
  spec.homepage = "https://github.com/cronofy/cronofy-ruby"
11
11
  spec.license = "MIT"
@@ -17,11 +17,11 @@ Gem::Specification.new do |spec|
17
17
  spec.files += Dir['spec/**/*.rb']
18
18
  spec.test_files = Dir['spec/**/*.rb']
19
19
 
20
+ spec.add_runtime_dependency "hashie", ">= 2.1", "< 5"
20
21
  spec.add_runtime_dependency "oauth2", "~> 1.0"
21
- spec.add_runtime_dependency "hashie", ">= 2.1", "< 4"
22
22
 
23
23
  spec.add_development_dependency "bundler", ">= 1.6", "< 3"
24
24
  spec.add_development_dependency "rake", "~> 10.0"
25
25
  spec.add_development_dependency "rspec", "~> 3.2"
26
- spec.add_development_dependency "webmock", "~> 1.21"
26
+ spec.add_development_dependency "webmock", "~> 3.9.1"
27
27
  end
@@ -13,18 +13,26 @@ require 'openssl'
13
13
 
14
14
  module Cronofy
15
15
  def self.default_data_centre
16
- @default_data_centre || ENV['CRONOFY_DATA_CENTRE']
16
+ default_data_center
17
17
  end
18
18
 
19
19
  def self.default_data_centre=(value)
20
- @default_data_centre = value
20
+ default_data_center= value
21
21
  end
22
22
 
23
- def self.api_url(data_centre_override)
24
- if data_centre_override
25
- api_url_for_data_centre(data_centre_override)
23
+ def self.default_data_center
24
+ @default_data_center || ENV['CRONOFY_DATA_CENTER'] || ENV['CRONOFY_DATA_CENTRE']
25
+ end
26
+
27
+ def self.default_data_center=(value)
28
+ @default_data_center = value
29
+ end
30
+
31
+ def self.api_url(data_center_override)
32
+ if data_center_override
33
+ api_url_for_data_center(data_center_override)
26
34
  else
27
- ENV['CRONOFY_API_URL'] || api_url_for_data_centre(default_data_centre)
35
+ ENV['CRONOFY_API_URL'] || api_url_for_data_center(default_data_center)
28
36
  end
29
37
  end
30
38
 
@@ -32,7 +40,11 @@ module Cronofy
32
40
  @api_url = value
33
41
  end
34
42
 
35
- def self.api_url_for_data_centre(dc)
43
+ def self.api_url_for_data_centre
44
+ api_url_for_data_center
45
+ end
46
+
47
+ def self.api_url_for_data_center(dc)
36
48
  @api_urls ||= Hash.new do |hash, key|
37
49
  if key.nil? || key.to_sym == :us
38
50
  url = "https://api.cronofy.com"
@@ -46,11 +58,11 @@ module Cronofy
46
58
  @api_urls[dc]
47
59
  end
48
60
 
49
- def self.app_url(data_centre_override)
50
- if data_centre_override
51
- app_url_for_data_centre(data_centre_override)
61
+ def self.app_url(data_center_override)
62
+ if data_center_override
63
+ app_url_for_data_center(data_center_override)
52
64
  else
53
- ENV['CRONOFY_APP_URL'] || app_url_for_data_centre(default_data_centre)
65
+ ENV['CRONOFY_APP_URL'] || app_url_for_data_center(default_data_center)
54
66
  end
55
67
  end
56
68
 
@@ -59,6 +71,10 @@ module Cronofy
59
71
  end
60
72
 
61
73
  def self.app_url_for_data_centre(dc)
74
+ app_url_for_data_center(dc)
75
+ end
76
+
77
+ def self.app_url_for_data_center(dc)
62
78
  @app_urls ||= Hash.new do |hash, key|
63
79
  if key.nil? || key.to_sym == :us
64
80
  url = "https://app.cronofy.com"
@@ -11,13 +11,13 @@ module Cronofy
11
11
  access_token = options[:access_token]
12
12
  client_id = options[:client_id]
13
13
  client_secret = options[:client_secret]
14
- data_centre = options[:data_centre]
14
+ data_center = options[:data_center]
15
15
  refresh_token = options[:refresh_token]
16
16
 
17
17
  @client_credentials_missing = blank?(client_id) || blank?(client_secret)
18
18
 
19
- @auth_client = OAuth2::Client.new(client_id, client_secret, site: ::Cronofy.app_url(data_centre), connection_opts: { headers: { "User-Agent" => "Cronofy Ruby #{::Cronofy::VERSION}" } })
20
- @api_client = OAuth2::Client.new(client_id, client_secret, site: ::Cronofy.api_url(data_centre), connection_opts: { headers: { "User-Agent" => "Cronofy Ruby #{::Cronofy::VERSION}" } })
19
+ @auth_client = OAuth2::Client.new(client_id, client_secret, site: ::Cronofy.app_url(data_center), 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), connection_opts: { headers: { "User-Agent" => "Cronofy Ruby #{::Cronofy::VERSION}" } })
21
21
 
22
22
  set_access_token(access_token, refresh_token) if access_token || refresh_token
23
23
  set_api_key(client_secret) if client_secret
@@ -118,20 +118,50 @@ module Cronofy
118
118
  def revoke!
119
119
  raise CredentialsMissingError.new("No credentials to revoke") unless access_token
120
120
 
121
+ token = access_token.refresh_token || access_token.token
122
+ revoke_by_token(token)
123
+ @access_token = nil
124
+ end
125
+
126
+ # Internal: Revokes an authorization by the sub
127
+ #
128
+ # Returns nothing.
129
+ #
130
+ # Raises Cronofy::CredentialsMissingError if no credentials available.
131
+ def revoke_by_sub(sub)
132
+ do_revoke(sub: sub)
133
+ end
134
+
135
+ # Internal: Revokes an authorization via the token
136
+ #
137
+ # Returns nothing.
138
+ #
139
+ # Raises Cronofy::CredentialsMissingError if no credentials available.
140
+ def revoke_by_token(token)
141
+ do_revoke(token: token)
142
+ end
143
+
144
+ private
145
+
146
+ def do_revoke(token: nil, sub: nil)
147
+ raise CredentialsMissingError.new("No credentials to revoke") unless token || sub
148
+
121
149
  do_request do
122
150
  body = {
123
151
  client_id: @api_client.id,
124
152
  client_secret: @api_client.secret,
125
- token: access_token.refresh_token || access_token.token,
126
153
  }
127
154
 
155
+ if token
156
+ body.merge!(token: token)
157
+ else
158
+ body.merge!(sub: sub)
159
+ end
160
+
128
161
  @api_client.request(:post, "/oauth/token/revoke", body: body)
129
- @access_token = nil
130
162
  end
131
163
  end
132
164
 
133
- private
134
-
135
165
  def do_request(&block)
136
166
  if @client_credentials_missing
137
167
  raise CredentialsMissingError.new("OAuth client_id and client_secret must be set")
@@ -1,3 +1,5 @@
1
+ require 'uri'
2
+
1
3
  module Cronofy
2
4
  # Public: Primary class for interacting with the Cronofy API.
3
5
  class Client
@@ -25,22 +27,22 @@ module Cronofy
25
27
  # ENV["CRONOFY_CLIENT_SECRET"]).
26
28
  # :refresh_token - An existing refresh token String for the user's
27
29
  # account (optional).
28
- # :data_centre - An identifier to override the default data
29
- # centre (optional).
30
+ # :data_center - An identifier to override the default data
31
+ # center (optional).
30
32
  def initialize(options = {})
31
33
  access_token = options[:access_token]
32
34
  refresh_token = options[:refresh_token]
33
35
 
34
36
  @client_id = options.fetch(:client_id, ENV["CRONOFY_CLIENT_ID"])
35
37
  @client_secret = options.fetch(:client_secret, ENV["CRONOFY_CLIENT_SECRET"])
36
- @data_centre = options[:data_centre]
38
+ @data_center = options[:data_center] || options[:data_centre]
37
39
 
38
40
  @auth = Auth.new(
39
41
  client_id: @client_id,
40
42
  client_secret: @client_secret,
41
43
  access_token: access_token,
42
44
  refresh_token: refresh_token,
43
- data_centre: @data_centre,
45
+ data_center: @data_center
44
46
  )
45
47
  end
46
48
 
@@ -735,6 +737,14 @@ module Cronofy
735
737
  @auth.revoke!
736
738
  end
737
739
 
740
+ def revoke_by_sub(sub)
741
+ @auth.revoke_by_sub(sub)
742
+ end
743
+
744
+ def revoke_by_token(token)
745
+ @auth.revoke_by_token(token)
746
+ end
747
+
738
748
  # Public: Requests elevated permissions for a set of calendars.
739
749
  #
740
750
  # args - A Hash of options used to initialize the request (default: {}):
@@ -1492,6 +1502,84 @@ module Cronofy
1492
1502
  nil
1493
1503
  end
1494
1504
 
1505
+ # Public: Creates or updates an AvailablePeriod.
1506
+ #
1507
+ # available_period_id - A String uniquely identifying the available period
1508
+ # for the authenticated user in your application
1509
+ # (note: this is NOT an ID generated by Cronofy).
1510
+ # body - A Hash describing the available period with
1511
+ # symbolized keys:
1512
+ # :start - A String (ISO-8601 date/time)
1513
+ # :end - A String (ISO-8601 date/time)
1514
+ #
1515
+ # See https://docs.cronofy.com/developers/api/scheduling/available-periods/upsert/
1516
+ # for reference.
1517
+ #
1518
+ # Returns nothing.
1519
+ #
1520
+ # Raises Cronofy::CredentialsMissingError if no credentials available.
1521
+ # Raises Cronofy::InvalidRequestError if the request contains invalid
1522
+ # parameters.
1523
+ # Raises Cronofy::TooManyRequestsError if the request exceeds the rate
1524
+ # limits for the application.
1525
+ def upsert_available_period(available_period_id, body)
1526
+ payload = body.merge(available_period_id: available_period_id)
1527
+ wrapped_request { post("/v1/available_periods", payload) }
1528
+ nil
1529
+ end
1530
+
1531
+ # Public: Gets all AvailablePeriods for an account.
1532
+ #
1533
+ # options - The Hash options used to refine the selection (default: {}):
1534
+ # :from - The minimum Date from which to return periods
1535
+ # (optional).
1536
+ # :to - The Date to return periods up until (optional).
1537
+ # :tzid - A String representing a known time zone
1538
+ # identifier from the IANA Time Zone Database
1539
+ # (default: Etc/UTC).
1540
+ # :localized_times - A Boolean specifying whether the start and
1541
+ # end times should be returned with any
1542
+ # available localization information
1543
+ # (optional).
1544
+ #
1545
+ # Returns an array of AvailablePeriods.
1546
+ #
1547
+ # Raises Cronofy::CredentialsMissingError if no credentials available.
1548
+ # Raises Cronofy::InvalidRequestError if the request contains invalid
1549
+ # parameters.
1550
+ # Raises Cronofy::TooManyRequestsError if the request exceeds the rate
1551
+ # limits for the application.
1552
+ def get_available_periods(options={})
1553
+ query = {}
1554
+ query[:from] = to_iso8601(options[:from]) if options[:from]
1555
+ query[:to] = to_iso8601(options[:to]) if options[:to]
1556
+ query[:tzid] = options[:tzid] if options[:tzid]
1557
+ query[:localized_times] = options[:localized_times] if options[:localized_times]
1558
+ if query.any?
1559
+ query_string = "?#{URI.encode_www_form(query)}"
1560
+ end
1561
+
1562
+ response = wrapped_request { get("/v1/available_periods#{query_string}") }
1563
+ parse_collection(AvailablePeriod, 'available_periods', response)
1564
+ end
1565
+
1566
+ # Public: Deletes an AvailablePeriod.
1567
+ #
1568
+ # available_period_id - A String uniquely identifying the available period
1569
+ # for the authenticated user in your application
1570
+ #
1571
+ # Returns nothing.
1572
+ #
1573
+ # Raises Cronofy::CredentialsMissingError if no credentials available.
1574
+ # Raises Cronofy::InvalidRequestError if the request contains invalid
1575
+ # parameters.
1576
+ # Raises Cronofy::TooManyRequestsError if the request exceeds the rate
1577
+ # limits for the application.
1578
+ def delete_available_period(available_period_id)
1579
+ wrapped_request { delete("/v1/available_periods", available_period_id: available_period_id) }
1580
+ nil
1581
+ end
1582
+
1495
1583
  # Public: Creates a scheduling conversation
1496
1584
  #
1497
1585
  # pre release end-point documentation to follow
@@ -1801,7 +1889,7 @@ module Cronofy
1801
1889
  end
1802
1890
 
1803
1891
  def api_url
1804
- ::Cronofy.api_url(@data_centre)
1892
+ ::Cronofy.api_url(@data_center)
1805
1893
  end
1806
1894
  end
1807
1895
 
@@ -68,6 +68,18 @@ module Cronofy
68
68
  class PaymentRequiredError < APIError
69
69
  end
70
70
 
71
+ class ServiceUnreachableError < APIError
72
+ end
73
+
74
+ class BadGatewayError < ServiceUnreachableError
75
+ end
76
+
77
+ class ServiceUnavailableError < ServiceUnreachableError
78
+ end
79
+
80
+ class GatewayTimeoutError < ServiceUnreachableError
81
+ end
82
+
71
83
  class UnknownError < APIError
72
84
  end
73
85
 
@@ -83,6 +95,9 @@ module Cronofy
83
95
  423 => AccountLockedError,
84
96
  429 => TooManyRequestsError,
85
97
  500 => ServerError,
98
+ 502 => BadGatewayError,
99
+ 503 => ServiceUnavailableError,
100
+ 504 => GatewayTimeoutError,
86
101
  }.freeze
87
102
 
88
103
  def self.map_error(error)
@@ -1,3 +1,3 @@
1
1
  module Cronofy
2
- VERSION = "0.34.0".freeze
2
+ VERSION = "0.37.1".freeze
3
3
  end
@@ -92,7 +92,7 @@ describe Cronofy::Auth do
92
92
  let(:scheme) { 'https' }
93
93
  let(:host) { 'app.cronofy.com' }
94
94
  let(:path) { '/oauth/authorize' }
95
- let(:data_centre_override) { nil }
95
+ let(:data_center_override) { nil }
96
96
  let(:default_params) do
97
97
  {
98
98
  'client_id' => client_id,
@@ -106,7 +106,7 @@ describe Cronofy::Auth do
106
106
  Cronofy::Auth.new(
107
107
  client_id: client_id,
108
108
  client_secret: client_secret,
109
- data_centre: data_centre_override,
109
+ data_center: data_center_override,
110
110
  )
111
111
  end
112
112
 
@@ -156,8 +156,8 @@ describe Cronofy::Auth do
156
156
  it_behaves_like 'a user auth link provider'
157
157
  end
158
158
 
159
- context 'when data centre overridden' do
160
- let(:data_centre_override) { :de }
159
+ context 'when data center overridden' do
160
+ let(:data_center_override) { :de }
161
161
  let(:host) { 'app-de.cronofy.com' }
162
162
  let(:params) { default_params }
163
163
 
@@ -204,13 +204,13 @@ describe Cronofy::Auth do
204
204
  end
205
205
 
206
206
  describe '#get_token_from_code' do
207
- let(:data_centre_override) { nil }
207
+ let(:data_center_override) { nil }
208
208
 
209
209
  subject do
210
210
  Cronofy::Auth.new(
211
211
  client_id: client_id,
212
212
  client_secret: client_secret,
213
- data_centre: data_centre_override,
213
+ data_center: data_center_override,
214
214
  ).get_token_from_code(code, redirect_uri)
215
215
  end
216
216
 
@@ -236,7 +236,7 @@ describe Cronofy::Auth do
236
236
  end
237
237
 
238
238
  describe '#application_calendar' do
239
- let(:data_centre_override) { nil }
239
+ let(:data_center_override) { nil }
240
240
 
241
241
  let(:application_calendar_id) { "my-application-calendar" }
242
242
  let(:cronofy_application_calendar_id) { "apc_54475485743" }
@@ -273,7 +273,7 @@ describe Cronofy::Auth do
273
273
  Cronofy::Auth.new(
274
274
  client_id: client_id,
275
275
  client_secret: client_secret,
276
- data_centre: data_centre_override,
276
+ data_center: data_center_override,
277
277
  ).application_calendar(application_calendar_id)
278
278
  end
279
279
 
@@ -308,8 +308,8 @@ describe Cronofy::Auth do
308
308
  end
309
309
  end
310
310
 
311
- context "with data centre overridden" do
312
- let(:data_centre_override) { :de }
311
+ context "with data center overridden" do
312
+ let(:data_center_override) { :de }
313
313
  let(:api_token_url) { "https://api-de.cronofy.com/oauth/token" }
314
314
  let(:app_token_url) { "https://app-de.cronofy.com/oauth/token" }
315
315
 
@@ -372,14 +372,14 @@ describe Cronofy::Auth do
372
372
  it_behaves_like 'an authorization request'
373
373
  end
374
374
 
375
- context "with data centre overridden" do
375
+ context "with data center overridden" do
376
376
  subject do
377
377
  Cronofy::Auth.new(
378
378
  client_id: client_id,
379
379
  client_secret: client_secret,
380
380
  access_token: access_token,
381
381
  refresh_token: refresh_token,
382
- data_centre: :de,
382
+ data_center: :de,
383
383
  ).refresh!
384
384
  end
385
385
 
@@ -476,4 +476,84 @@ describe Cronofy::Auth do
476
476
  end
477
477
  end
478
478
  end
479
+
480
+ describe "#revoke_by_sub" do
481
+ let(:auth) do
482
+ Cronofy::Auth.new(
483
+ client_id: client_id,
484
+ client_secret: client_secret,
485
+ access_token: access_token,
486
+ refresh_token: refresh_token,
487
+ )
488
+ end
489
+
490
+ let!(:revocation_request) do
491
+ stub_request(:post, "https://api.cronofy.com/oauth/token/revoke")
492
+ .with(
493
+ body: {
494
+ client_id: client_id,
495
+ client_secret: client_secret,
496
+ sub: sub,
497
+ },
498
+ headers: {
499
+ 'Content-Type' => 'application/x-www-form-urlencoded',
500
+ 'User-Agent' => "Cronofy Ruby #{Cronofy::VERSION}",
501
+ }
502
+ ).to_return(status: response_status)
503
+ end
504
+
505
+ let(:sub) { "random_sub_value" }
506
+
507
+ before do
508
+ auth.revoke_by_sub(sub)
509
+ end
510
+
511
+ it "does not unset the access token for the current auth" do
512
+ expect(auth.access_token).not_to be_nil
513
+ end
514
+
515
+ it "makes the revocation request" do
516
+ expect(revocation_request).to have_been_requested
517
+ end
518
+ end
519
+
520
+ describe "#revoke_by_token" do
521
+ let(:auth) do
522
+ Cronofy::Auth.new(
523
+ client_id: client_id,
524
+ client_secret: client_secret,
525
+ access_token: access_token,
526
+ refresh_token: refresh_token,
527
+ )
528
+ end
529
+
530
+ let!(:revocation_request) do
531
+ stub_request(:post, "https://api.cronofy.com/oauth/token/revoke")
532
+ .with(
533
+ body: {
534
+ client_id: client_id,
535
+ client_secret: client_secret,
536
+ token: token,
537
+ },
538
+ headers: {
539
+ 'Content-Type' => 'application/x-www-form-urlencoded',
540
+ 'User-Agent' => "Cronofy Ruby #{Cronofy::VERSION}",
541
+ }
542
+ ).to_return(status: response_status)
543
+ end
544
+
545
+ let(:token) { "random_token_value" }
546
+
547
+ before do
548
+ auth.revoke_by_token(token)
549
+ end
550
+
551
+ it "does not unset the access token for the current auth" do
552
+ expect(auth.access_token).not_to be_nil
553
+ end
554
+
555
+ it "makes the revocation request" do
556
+ expect(revocation_request).to have_been_requested
557
+ end
558
+ end
479
559
  end
@@ -2325,8 +2325,8 @@ describe Cronofy::Client do
2325
2325
 
2326
2326
  end
2327
2327
 
2328
- describe "Specified data centre" do
2329
- let(:data_centre) { :de }
2328
+ describe "specifying data_centre" do
2329
+ let(:data_center) { :de }
2330
2330
 
2331
2331
  let(:client) do
2332
2332
  Cronofy::Client.new(
@@ -2334,12 +2334,52 @@ describe Cronofy::Client do
2334
2334
  client_secret: 'client_secret_456',
2335
2335
  access_token: token,
2336
2336
  refresh_token: 'refresh_token_456',
2337
- data_centre: data_centre,
2337
+ data_centre: data_center,
2338
2338
  )
2339
2339
  end
2340
2340
 
2341
2341
  describe "Userinfo" do
2342
- let(:request_url) { "https://api-#{data_centre}.cronofy.com/v1/userinfo" }
2342
+ let(:request_url) { "https://api-#{data_center}.cronofy.com/v1/userinfo" }
2343
+
2344
+ describe "#userinfo" do
2345
+ let(:method) { :get }
2346
+
2347
+ let(:correct_response_code) { 200 }
2348
+ let(:correct_response_body) do
2349
+ {
2350
+ "sub" => "ser_5700a00eb0ccd07000000000",
2351
+ "cronofy.type" => "service_account",
2352
+ "cronofy.service_account.domain" => "example.com"
2353
+ }
2354
+ end
2355
+
2356
+ let(:correct_mapped_result) do
2357
+ Cronofy::UserInfo.new(correct_response_body)
2358
+ end
2359
+
2360
+ subject { client.userinfo }
2361
+
2362
+ it_behaves_like "a Cronofy request"
2363
+ it_behaves_like "a Cronofy request with mapped return value"
2364
+ end
2365
+ end
2366
+ end
2367
+
2368
+ describe "specifying data_center" do
2369
+ let(:data_center) { :au }
2370
+
2371
+ let(:client) do
2372
+ Cronofy::Client.new(
2373
+ client_id: 'client_id_123',
2374
+ client_secret: 'client_secret_456',
2375
+ access_token: token,
2376
+ refresh_token: 'refresh_token_456',
2377
+ data_center: data_center,
2378
+ )
2379
+ end
2380
+
2381
+ describe "Userinfo" do
2382
+ let(:request_url) { "https://api-#{data_center}.cronofy.com/v1/userinfo" }
2343
2383
 
2344
2384
  describe "#userinfo" do
2345
2385
  let(:method) { :get }
@@ -3152,4 +3192,160 @@ describe Cronofy::Client do
3152
3192
 
3153
3193
  it_behaves_like 'a Cronofy request'
3154
3194
  end
3195
+
3196
+ describe "#upsert_available_period" do
3197
+ let(:request_url) { 'https://api.cronofy.com/v1/available_periods' }
3198
+ let(:method) { :post }
3199
+ let(:available_period_id) { "test" }
3200
+ let(:request_body) do
3201
+ {
3202
+ available_period_id: available_period_id,
3203
+ start: "2020-07-26T15:30:00Z",
3204
+ end: "2020-07-26T17:00:00Z"
3205
+ }
3206
+ end
3207
+
3208
+ let(:correct_response_code) { 202 }
3209
+ let(:correct_response_body) { "" }
3210
+ let(:correct_mapped_result) { nil }
3211
+
3212
+ subject {
3213
+ client.upsert_available_period(available_period_id,
3214
+ start: request_body[:start],
3215
+ end: request_body[:end]
3216
+ )
3217
+ }
3218
+
3219
+ it_behaves_like 'a Cronofy request'
3220
+ it_behaves_like 'a Cronofy request with mapped return value'
3221
+ end
3222
+
3223
+ describe "#get_available_periods" do
3224
+ context "unfiltered" do
3225
+ let(:request_url) { "https://api.cronofy.com/v1/available_periods" }
3226
+ let(:method) { :get }
3227
+
3228
+ let(:correct_response_code) { 200 }
3229
+ let(:correct_response_body) do
3230
+ {
3231
+ "available_periods" => [
3232
+ {
3233
+ "available_period_id" => "qTtZdczOccgaPncGJaCiLg",
3234
+ "start" => "2020-07-26T15:30:00Z",
3235
+ "end" => "2020-07-26T17:00:00Z"
3236
+ }
3237
+ ]
3238
+ }
3239
+ end
3240
+
3241
+ let(:correct_mapped_result) do
3242
+ period = correct_response_body['available_periods'][0]
3243
+
3244
+ [
3245
+ Cronofy::AvailablePeriod.new(
3246
+ available_period_id: period['available_period_id'],
3247
+ start: period['start'],
3248
+ end: period['end']
3249
+ )
3250
+ ]
3251
+ end
3252
+
3253
+ subject { client.get_available_periods }
3254
+
3255
+ it_behaves_like 'a Cronofy request'
3256
+ it_behaves_like 'a Cronofy request with mapped return value'
3257
+ end
3258
+
3259
+ context "filterd by date range" do
3260
+ let(:tzid) { "America/New_York" }
3261
+ let(:from) { "2020-07-01" }
3262
+ let(:to) { "2020-07-31" }
3263
+ let(:request_url) { "https://api.cronofy.com/v1/available_periods?from=#{from}&to=#{to}&tzid=#{tzid}" }
3264
+ let(:method) { :get }
3265
+
3266
+ let(:correct_response_code) { 200 }
3267
+ let(:correct_response_body) do
3268
+ {
3269
+ "available_periods" => [
3270
+ {
3271
+ "available_period_id" => "qTtZdczOccgaPncGJaCiLg",
3272
+ "start" => "2020-07-26T15:30:00Z",
3273
+ "end" => "2020-07-26T17:00:00Z"
3274
+ }
3275
+ ]
3276
+ }
3277
+ end
3278
+
3279
+ let(:correct_mapped_result) do
3280
+ period = correct_response_body['available_periods'][0]
3281
+
3282
+ [
3283
+ Cronofy::AvailablePeriod.new(
3284
+ available_period_id: period['available_period_id'],
3285
+ start: period['start'],
3286
+ end: period['end']
3287
+ )
3288
+ ]
3289
+ end
3290
+
3291
+ subject { client.get_available_periods(from: from, to: to, tzid: tzid) }
3292
+
3293
+ it_behaves_like 'a Cronofy request'
3294
+ it_behaves_like 'a Cronofy request with mapped return value'
3295
+ end
3296
+
3297
+ context "requesting localized times" do
3298
+ let(:tzid) { "America/New_York" }
3299
+ let(:localized_times) { true }
3300
+ let(:request_url) { "https://api.cronofy.com/v1/available_periods?tzid=#{tzid}&localized_times=true" }
3301
+ let(:method) { :get }
3302
+
3303
+ let(:correct_response_code) { 200 }
3304
+ let(:correct_response_body) do
3305
+ {
3306
+ "available_periods" => [
3307
+ {
3308
+ "available_period_id" => "qTtZdczOccgaPncGJaCiLg",
3309
+ "start" => "2020-07-26T15:30:00Z",
3310
+ "end" => "2020-07-26T17:00:00Z"
3311
+ }
3312
+ ]
3313
+ }
3314
+ end
3315
+
3316
+ let(:correct_mapped_result) do
3317
+ period = correct_response_body['available_periods'][0]
3318
+
3319
+ [
3320
+ Cronofy::AvailablePeriod.new(
3321
+ available_period_id: period['available_period_id'],
3322
+ start: period['start'],
3323
+ end: period['end']
3324
+ )
3325
+ ]
3326
+ end
3327
+
3328
+ subject { client.get_available_periods(tzid: tzid, localized_times: true) }
3329
+
3330
+ it_behaves_like 'a Cronofy request'
3331
+ it_behaves_like 'a Cronofy request with mapped return value'
3332
+ end
3333
+ end
3334
+
3335
+ describe '#delete_available_period' do
3336
+ let(:available_period_id) { 'default'}
3337
+ let(:request_url) { "https://api.cronofy.com/v1/available_periods" }
3338
+ let(:method) { :delete }
3339
+ let(:request_body) {
3340
+ { available_period_id: available_period_id}
3341
+ }
3342
+ let(:correct_response_code) { 202 }
3343
+ let(:correct_response_body) { "" }
3344
+ let(:correct_mapped_result) { nil }
3345
+
3346
+ subject { client.delete_available_period(available_period_id) }
3347
+
3348
+ it_behaves_like 'a Cronofy request'
3349
+ it_behaves_like 'a Cronofy request with mapped return value'
3350
+ end
3155
3351
  end
metadata CHANGED
@@ -1,30 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cronofy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.34.0
4
+ version: 0.37.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergii Paryzhskyi
8
8
  - Garry Shutler
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-11-06 00:00:00.000000000 Z
12
+ date: 2021-01-14 00:00:00.000000000 Z
13
13
  dependencies:
14
- - !ruby/object:Gem::Dependency
15
- name: oauth2
16
- requirement: !ruby/object:Gem::Requirement
17
- requirements:
18
- - - "~>"
19
- - !ruby/object:Gem::Version
20
- version: '1.0'
21
- type: :runtime
22
- prerelease: false
23
- version_requirements: !ruby/object:Gem::Requirement
24
- requirements:
25
- - - "~>"
26
- - !ruby/object:Gem::Version
27
- version: '1.0'
28
14
  - !ruby/object:Gem::Dependency
29
15
  name: hashie
30
16
  requirement: !ruby/object:Gem::Requirement
@@ -34,7 +20,7 @@ dependencies:
34
20
  version: '2.1'
35
21
  - - "<"
36
22
  - !ruby/object:Gem::Version
37
- version: '4'
23
+ version: '5'
38
24
  type: :runtime
39
25
  prerelease: false
40
26
  version_requirements: !ruby/object:Gem::Requirement
@@ -44,7 +30,21 @@ dependencies:
44
30
  version: '2.1'
45
31
  - - "<"
46
32
  - !ruby/object:Gem::Version
47
- version: '4'
33
+ version: '5'
34
+ - !ruby/object:Gem::Dependency
35
+ name: oauth2
36
+ requirement: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.0'
41
+ type: :runtime
42
+ prerelease: false
43
+ version_requirements: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.0'
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: bundler
50
50
  requirement: !ruby/object:Gem::Requirement
@@ -99,14 +99,14 @@ dependencies:
99
99
  requirements:
100
100
  - - "~>"
101
101
  - !ruby/object:Gem::Version
102
- version: '1.21'
102
+ version: 3.9.1
103
103
  type: :development
104
104
  prerelease: false
105
105
  version_requirements: !ruby/object:Gem::Requirement
106
106
  requirements:
107
107
  - - "~>"
108
108
  - !ruby/object:Gem::Version
109
- version: '1.21'
109
+ version: 3.9.1
110
110
  description: Ruby wrapper for Cronofy's unified calendar API
111
111
  email:
112
112
  - parizhskiy@gmail.com
@@ -141,7 +141,7 @@ homepage: https://github.com/cronofy/cronofy-ruby
141
141
  licenses:
142
142
  - MIT
143
143
  metadata: {}
144
- post_install_message:
144
+ post_install_message:
145
145
  rdoc_options: []
146
146
  require_paths:
147
147
  - lib
@@ -156,10 +156,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
156
156
  - !ruby/object:Gem::Version
157
157
  version: '0'
158
158
  requirements: []
159
- rubygems_version: 3.0.6
160
- signing_key:
159
+ rubygems_version: 3.2.4
160
+ signing_key:
161
161
  specification_version: 4
162
- summary: Cronofy - one API for all the calendars
162
+ summary: Cronofy - the scheduling platform for business
163
163
  test_files:
164
164
  - spec/spec_helper.rb
165
165
  - spec/response_parser_spec.rb