cronofy 0.35.0 → 0.37.2

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: c20768b0500ee2cb9e902443eada181d2cddafad064febfe1d9e89481fc3d242
4
- data.tar.gz: 822d3f453e190ef16b42a07a24ceeba06375bc8641d544cf09085d79f6fce101
3
+ metadata.gz: 3e09c2030d7992753a4e8f0e52af1d00d2ab6ced77f5e5b81336cb97a5c98ec6
4
+ data.tar.gz: 464b7a63bdfb341f67da6f4556e4ee66b36db144d9d41270c9204ee6a10ca56c
5
5
  SHA512:
6
- metadata.gz: 4992da5ff0a8becd7237982e8867b67b8f32e56d5293c3758b05494b38f05307b841e9109f1299cd968e4d0b1f9f6d16da463553d8167d6bc8113c613440f122
7
- data.tar.gz: 505d13d30dfced6e3c7524ceecd7efcaa51bbede71761f948a3583c91d4c35e65d3481d8851da78a03ed28ad870307bbc30ec6f18a8b0a5904926204aae17f62
6
+ metadata.gz: f6a6f59a184da190d6905b495a0c067437ab422561ccf26f23e1e7d6f48fd0a0d2c63bb033d46f760b9ce24e958539a58e319b8a160c2fc2a719f4f1e3f31bcd
7
+ data.tar.gz: a777db3452a6cc462ba526447c17fe0790d73dd8b08517d62363ac3f5d9b7cb076d2b77ef614ed51f981941451362bd0f568fab4749c08bdc9bc38533974729b
@@ -1,3 +1,23 @@
1
+ ## [0.37.2]
2
+
3
+ * Support `query_periods` as well as the original `available_periods` for Availability Query and Sequenced Availability [#91]
4
+
5
+ ## [0.37.1]
6
+
7
+ * Rename `data_centre` to `data_centre` (with aliases for backwards compatibility) [#90]
8
+
9
+ ## [0.37.0]
10
+
11
+ * Add `revoke_by_token` and `revoke_by_sub` to the Client [#86]
12
+
13
+ ## [0.36.1]
14
+
15
+ * Loosen the version requirement on Hashie to allow 4.X
16
+
17
+ ## [0.36.0]
18
+
19
+ * Add support for Available Periods [#81]
20
+
1
21
  ## [0.35.0]
2
22
 
3
23
  * Add specific errors for network issues [#77]
@@ -162,6 +182,11 @@
162
182
  [0.33.0]: https://github.com/cronofy/cronofy-ruby/releases/tag/v0.33.0
163
183
  [0.34.0]: https://github.com/cronofy/cronofy-ruby/releases/tag/v0.34.0
164
184
  [0.35.0]: https://github.com/cronofy/cronofy-ruby/releases/tag/v0.35.0
185
+ [0.36.0]: https://github.com/cronofy/cronofy-ruby/releases/tag/v0.36.0
186
+ [0.36.1]: https://github.com/cronofy/cronofy-ruby/releases/tag/v0.36.1
187
+ [0.37.0]: https://github.com/cronofy/cronofy-ruby/releases/tag/v0.37.0
188
+ [0.37.1]: https://github.com/cronofy/cronofy-ruby/releases/tag/v0.37.1
189
+ [0.37.2]: https://github.com/cronofy/cronofy-ruby/releases/tag/v0.37.2
165
190
 
166
191
  [#13]: https://github.com/cronofy/cronofy-ruby/pull/13
167
192
  [#16]: https://github.com/cronofy/cronofy-ruby/pull/16
@@ -201,3 +226,8 @@
201
226
  [#74]: https://github.com/cronofy/cronofy-ruby/pull/74
202
227
  [#75]: https://github.com/cronofy/cronofy-ruby/pull/75
203
228
  [#77]: https://github.com/cronofy/cronofy-ruby/pull/77
229
+ [#81]: https://github.com/cronofy/cronofy-ruby/pull/81
230
+ [#85]: https://github.com/cronofy/cronofy-ruby/pull/85
231
+ [#86]: https://github.com/cronofy/cronofy-ruby/pull/86
232
+ [#90]: https://github.com/cronofy/cronofy-ruby/pull/90
233
+ [#91]: https://github.com/cronofy/cronofy-ruby/pull/91
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: {}):
@@ -793,7 +803,7 @@ module Cronofy
793
803
  # for a single participant group.
794
804
  # :required_duration - An Integer representing the minimum number
795
805
  # of minutes of availability required.
796
- # :available_periods - An Array of available time periods Hashes,
806
+ # :query_periods - An Array of available time periods Hashes,
797
807
  # each must specify a start and end Time.
798
808
  # :start_interval - An Integer representing the start interval
799
809
  # of minutes for the availability query.
@@ -823,7 +833,7 @@ module Cronofy
823
833
  options[:buffer] = map_availability_buffer(buffer)
824
834
  end
825
835
 
826
- translate_available_periods(options[:available_periods])
836
+ translate_available_periods(options[:query_periods] || options[:available_periods])
827
837
 
828
838
  response = post("/v1/availability", options)
829
839
 
@@ -837,7 +847,7 @@ module Cronofy
837
847
  # Public: Performs an sequenced availability query.
838
848
  #
839
849
  # options - The Hash options used to refine the selection (default: {}):
840
- # :sequence - An Array of sequence defintions containing
850
+ # :sequence - An Array of sequence defintions containing
841
851
  # a Hash of:
842
852
  # :sequence_id - A String to uniquely identify this part
843
853
  # of the proposed sequence.
@@ -851,7 +861,7 @@ module Cronofy
851
861
  # of minutes for the availability query.
852
862
  # :buffer - An Hash containing the buffer to apply to
853
863
  # the availability query.
854
- # :available_periods - An Array of available time periods Hashes,
864
+ # :query_periods - An Array of available time periods Hashes,
855
865
  # each must specify a start and end Time.
856
866
  #
857
867
  # Returns an Array of Sequences.
@@ -868,7 +878,7 @@ module Cronofy
868
878
  def sequenced_availability(options = {})
869
879
  options[:sequence] = map_availability_sequence(options[:sequence])
870
880
 
871
- translate_available_periods(options[:available_periods])
881
+ translate_available_periods(options[:query_periods] || options[:available_periods])
872
882
 
873
883
  response = post("/v1/sequenced_availability", options)
874
884
  parse_collection(Sequence, "sequences", response)
@@ -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
 
@@ -1,3 +1,3 @@
1
1
  module Cronofy
2
- VERSION = "0.35.0".freeze
2
+ VERSION = "0.37.2".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
@@ -266,6 +266,7 @@ describe Cronofy::Client do
266
266
  ],
267
267
  }
268
268
  end
269
+
269
270
  let(:request_body) do
270
271
  {
271
272
  :event_id => "qTtZdczOccgaPncGJaCiLg",
@@ -1718,6 +1719,57 @@ describe Cronofy::Client do
1718
1719
  it_behaves_like 'a Cronofy request'
1719
1720
  it_behaves_like 'a Cronofy request with mapped return value'
1720
1721
  end
1722
+
1723
+ context "when given query_periods instead of available_periods" do
1724
+ let(:participants) do
1725
+ { members: %w{acc_567236000909002 acc_678347111010113} }
1726
+ end
1727
+
1728
+ let(:required_duration) { 60 }
1729
+
1730
+ let(:query_periods) do
1731
+ [
1732
+ { start: Time.parse("2017-01-03T09:00:00Z"), end: Time.parse("2017-01-03T18:00:00Z") },
1733
+ { start: Time.parse("2017-01-04T09:00:00Z"), end: Time.parse("2017-01-04T18:00:00Z") },
1734
+ ]
1735
+ end
1736
+
1737
+ let(:request_body) do
1738
+ {
1739
+ "participants" => [
1740
+ {
1741
+ "members" => [
1742
+ { "sub" => "acc_567236000909002" },
1743
+ { "sub" => "acc_678347111010113" }
1744
+ ],
1745
+ "required" => "all"
1746
+ }
1747
+ ],
1748
+ "query_periods" => [
1749
+ {
1750
+ "start" => "2017-01-03T09:00:00Z",
1751
+ "end" => "2017-01-03T18:00:00Z"
1752
+ },
1753
+ {
1754
+ "start" => "2017-01-04T09:00:00Z",
1755
+ "end" => "2017-01-04T18:00:00Z"
1756
+ }
1757
+ ],
1758
+ "required_duration" => { "minutes" => 60 },
1759
+ }
1760
+ end
1761
+
1762
+ subject do
1763
+ client.availability(
1764
+ participants: participants,
1765
+ required_duration: required_duration,
1766
+ query_periods: query_periods
1767
+ )
1768
+ end
1769
+
1770
+ it_behaves_like 'a Cronofy request'
1771
+ it_behaves_like 'a Cronofy request with mapped return value'
1772
+ end
1721
1773
  end
1722
1774
  end
1723
1775
 
@@ -1873,6 +1925,18 @@ describe Cronofy::Client do
1873
1925
 
1874
1926
  it_behaves_like 'a Cronofy request'
1875
1927
  it_behaves_like 'a Cronofy request with mapped return value'
1928
+
1929
+ context "when passing query_periods instead" do
1930
+ before do
1931
+ args[:query_periods] = args[:available_periods]
1932
+ args.delete(:available_periods)
1933
+ request_body["query_periods"] = request_body["available_periods"]
1934
+ request_body.delete("available_periods")
1935
+ end
1936
+
1937
+ it_behaves_like 'a Cronofy request'
1938
+ it_behaves_like 'a Cronofy request with mapped return value'
1939
+ end
1876
1940
  end
1877
1941
  end
1878
1942
 
@@ -2325,8 +2389,8 @@ describe Cronofy::Client do
2325
2389
 
2326
2390
  end
2327
2391
 
2328
- describe "Specified data centre" do
2329
- let(:data_centre) { :de }
2392
+ describe "specifying data_centre" do
2393
+ let(:data_center) { :de }
2330
2394
 
2331
2395
  let(:client) do
2332
2396
  Cronofy::Client.new(
@@ -2334,12 +2398,52 @@ describe Cronofy::Client do
2334
2398
  client_secret: 'client_secret_456',
2335
2399
  access_token: token,
2336
2400
  refresh_token: 'refresh_token_456',
2337
- data_centre: data_centre,
2401
+ data_centre: data_center,
2338
2402
  )
2339
2403
  end
2340
2404
 
2341
2405
  describe "Userinfo" do
2342
- let(:request_url) { "https://api-#{data_centre}.cronofy.com/v1/userinfo" }
2406
+ let(:request_url) { "https://api-#{data_center}.cronofy.com/v1/userinfo" }
2407
+
2408
+ describe "#userinfo" do
2409
+ let(:method) { :get }
2410
+
2411
+ let(:correct_response_code) { 200 }
2412
+ let(:correct_response_body) do
2413
+ {
2414
+ "sub" => "ser_5700a00eb0ccd07000000000",
2415
+ "cronofy.type" => "service_account",
2416
+ "cronofy.service_account.domain" => "example.com"
2417
+ }
2418
+ end
2419
+
2420
+ let(:correct_mapped_result) do
2421
+ Cronofy::UserInfo.new(correct_response_body)
2422
+ end
2423
+
2424
+ subject { client.userinfo }
2425
+
2426
+ it_behaves_like "a Cronofy request"
2427
+ it_behaves_like "a Cronofy request with mapped return value"
2428
+ end
2429
+ end
2430
+ end
2431
+
2432
+ describe "specifying data_center" do
2433
+ let(:data_center) { :au }
2434
+
2435
+ let(:client) do
2436
+ Cronofy::Client.new(
2437
+ client_id: 'client_id_123',
2438
+ client_secret: 'client_secret_456',
2439
+ access_token: token,
2440
+ refresh_token: 'refresh_token_456',
2441
+ data_center: data_center,
2442
+ )
2443
+ end
2444
+
2445
+ describe "Userinfo" do
2446
+ let(:request_url) { "https://api-#{data_center}.cronofy.com/v1/userinfo" }
2343
2447
 
2344
2448
  describe "#userinfo" do
2345
2449
  let(:method) { :get }
@@ -3152,4 +3256,160 @@ describe Cronofy::Client do
3152
3256
 
3153
3257
  it_behaves_like 'a Cronofy request'
3154
3258
  end
3259
+
3260
+ describe "#upsert_available_period" do
3261
+ let(:request_url) { 'https://api.cronofy.com/v1/available_periods' }
3262
+ let(:method) { :post }
3263
+ let(:available_period_id) { "test" }
3264
+ let(:request_body) do
3265
+ {
3266
+ available_period_id: available_period_id,
3267
+ start: "2020-07-26T15:30:00Z",
3268
+ end: "2020-07-26T17:00:00Z"
3269
+ }
3270
+ end
3271
+
3272
+ let(:correct_response_code) { 202 }
3273
+ let(:correct_response_body) { "" }
3274
+ let(:correct_mapped_result) { nil }
3275
+
3276
+ subject {
3277
+ client.upsert_available_period(available_period_id,
3278
+ start: request_body[:start],
3279
+ end: request_body[:end]
3280
+ )
3281
+ }
3282
+
3283
+ it_behaves_like 'a Cronofy request'
3284
+ it_behaves_like 'a Cronofy request with mapped return value'
3285
+ end
3286
+
3287
+ describe "#get_available_periods" do
3288
+ context "unfiltered" do
3289
+ let(:request_url) { "https://api.cronofy.com/v1/available_periods" }
3290
+ let(:method) { :get }
3291
+
3292
+ let(:correct_response_code) { 200 }
3293
+ let(:correct_response_body) do
3294
+ {
3295
+ "available_periods" => [
3296
+ {
3297
+ "available_period_id" => "qTtZdczOccgaPncGJaCiLg",
3298
+ "start" => "2020-07-26T15:30:00Z",
3299
+ "end" => "2020-07-26T17:00:00Z"
3300
+ }
3301
+ ]
3302
+ }
3303
+ end
3304
+
3305
+ let(:correct_mapped_result) do
3306
+ period = correct_response_body['available_periods'][0]
3307
+
3308
+ [
3309
+ Cronofy::AvailablePeriod.new(
3310
+ available_period_id: period['available_period_id'],
3311
+ start: period['start'],
3312
+ end: period['end']
3313
+ )
3314
+ ]
3315
+ end
3316
+
3317
+ subject { client.get_available_periods }
3318
+
3319
+ it_behaves_like 'a Cronofy request'
3320
+ it_behaves_like 'a Cronofy request with mapped return value'
3321
+ end
3322
+
3323
+ context "filterd by date range" do
3324
+ let(:tzid) { "America/New_York" }
3325
+ let(:from) { "2020-07-01" }
3326
+ let(:to) { "2020-07-31" }
3327
+ let(:request_url) { "https://api.cronofy.com/v1/available_periods?from=#{from}&to=#{to}&tzid=#{tzid}" }
3328
+ let(:method) { :get }
3329
+
3330
+ let(:correct_response_code) { 200 }
3331
+ let(:correct_response_body) do
3332
+ {
3333
+ "available_periods" => [
3334
+ {
3335
+ "available_period_id" => "qTtZdczOccgaPncGJaCiLg",
3336
+ "start" => "2020-07-26T15:30:00Z",
3337
+ "end" => "2020-07-26T17:00:00Z"
3338
+ }
3339
+ ]
3340
+ }
3341
+ end
3342
+
3343
+ let(:correct_mapped_result) do
3344
+ period = correct_response_body['available_periods'][0]
3345
+
3346
+ [
3347
+ Cronofy::AvailablePeriod.new(
3348
+ available_period_id: period['available_period_id'],
3349
+ start: period['start'],
3350
+ end: period['end']
3351
+ )
3352
+ ]
3353
+ end
3354
+
3355
+ subject { client.get_available_periods(from: from, to: to, tzid: tzid) }
3356
+
3357
+ it_behaves_like 'a Cronofy request'
3358
+ it_behaves_like 'a Cronofy request with mapped return value'
3359
+ end
3360
+
3361
+ context "requesting localized times" do
3362
+ let(:tzid) { "America/New_York" }
3363
+ let(:localized_times) { true }
3364
+ let(:request_url) { "https://api.cronofy.com/v1/available_periods?tzid=#{tzid}&localized_times=true" }
3365
+ let(:method) { :get }
3366
+
3367
+ let(:correct_response_code) { 200 }
3368
+ let(:correct_response_body) do
3369
+ {
3370
+ "available_periods" => [
3371
+ {
3372
+ "available_period_id" => "qTtZdczOccgaPncGJaCiLg",
3373
+ "start" => "2020-07-26T15:30:00Z",
3374
+ "end" => "2020-07-26T17:00:00Z"
3375
+ }
3376
+ ]
3377
+ }
3378
+ end
3379
+
3380
+ let(:correct_mapped_result) do
3381
+ period = correct_response_body['available_periods'][0]
3382
+
3383
+ [
3384
+ Cronofy::AvailablePeriod.new(
3385
+ available_period_id: period['available_period_id'],
3386
+ start: period['start'],
3387
+ end: period['end']
3388
+ )
3389
+ ]
3390
+ end
3391
+
3392
+ subject { client.get_available_periods(tzid: tzid, localized_times: true) }
3393
+
3394
+ it_behaves_like 'a Cronofy request'
3395
+ it_behaves_like 'a Cronofy request with mapped return value'
3396
+ end
3397
+ end
3398
+
3399
+ describe '#delete_available_period' do
3400
+ let(:available_period_id) { 'default'}
3401
+ let(:request_url) { "https://api.cronofy.com/v1/available_periods" }
3402
+ let(:method) { :delete }
3403
+ let(:request_body) {
3404
+ { available_period_id: available_period_id}
3405
+ }
3406
+ let(:correct_response_code) { 202 }
3407
+ let(:correct_response_body) { "" }
3408
+ let(:correct_mapped_result) { nil }
3409
+
3410
+ subject { client.delete_available_period(available_period_id) }
3411
+
3412
+ it_behaves_like 'a Cronofy request'
3413
+ it_behaves_like 'a Cronofy request with mapped return value'
3414
+ end
3155
3415
  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.35.0
4
+ version: 0.37.2
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: 2020-02-07 00:00:00.000000000 Z
12
+ date: 2021-01-15 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.3
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