cronofy 0.37.3 → 0.37.4

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: f398fb44b861ba5df84e244632877a53b050f584c08d15a815cb0e4abaae13bc
4
- data.tar.gz: 8cea161bbef6df1b41a3ff52b29984c9ccd3f713abe279a7137e1e0be89cd7d7
3
+ metadata.gz: 1338eaab0825a963c74f2c5fd3c434d01185a4bbc36fa57504b0e1edd539fe9e
4
+ data.tar.gz: 55a045316dbb1545ee7e4f14284ebbbc0aa7b91848ba28d165968125d2221bb3
5
5
  SHA512:
6
- metadata.gz: 5961670573669f876d06f772a1c96175ac2e37a06fb3b3c6a1c677da86f5cbcb50820aa1e71897b7e8379ec556b55f9b56751efb51037d2f642284e72f0f07ed
7
- data.tar.gz: 7bf5e28b6786f2fee081d09562e9e2dd57a90652994d1755a13b76c9ad9484cb50ef9dce1784fd6921372a3f6b5b29888c2274e99ed13bdb196aa42036133233
6
+ metadata.gz: 38ee7c99226bfe70c6e970a22477de0130e93fe07130b9d2c0a596e17178f66435ec58a97be5f18e9b6ac5624eefef7dde96443a8cc91c85f02818016ed64f7d
7
+ data.tar.gz: 8d0d1641e57b0751988ac5f7978571d2dbd6d6ea12b96ff2314a33d0d9b87c7a11eb5e16775c55b070a312c2efb6b8b353dc3c3f7a8cbe9b3f42c943d6afa21a
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## [0.37.4]
2
+
3
+ * Support client_secret only clients being able to authorize `#availability` calls. [#97]
4
+
1
5
  ## [0.37.3]
2
6
 
3
7
  * Support `hmac_valid` as well as the original `hmac_match` for Client to verify a HMAC from a push notification using the client's secret.[#95]
@@ -192,6 +196,7 @@
192
196
  [0.37.1]: https://github.com/cronofy/cronofy-ruby/releases/tag/v0.37.1
193
197
  [0.37.2]: https://github.com/cronofy/cronofy-ruby/releases/tag/v0.37.2
194
198
  [0.37.3]: https://github.com/cronofy/cronofy-ruby/releases/tag/v0.37.3
199
+ [0.37.4]: https://github.com/cronofy/cronofy-ruby/releases/tag/v0.37.4
195
200
 
196
201
  [#13]: https://github.com/cronofy/cronofy-ruby/pull/13
197
202
  [#16]: https://github.com/cronofy/cronofy-ruby/pull/16
@@ -237,3 +242,4 @@
237
242
  [#90]: https://github.com/cronofy/cronofy-ruby/pull/90
238
243
  [#91]: https://github.com/cronofy/cronofy-ruby/pull/91
239
244
  [#95]: https://github.com/cronofy/cronofy-ruby/pull/95
245
+ [#97]: https://github.com/cronofy/cronofy-ruby/pull/97
@@ -844,7 +844,7 @@ module Cronofy
844
844
 
845
845
  translate_available_periods(options[:query_periods] || options[:available_periods])
846
846
 
847
- response = post("/v1/availability", options)
847
+ response = availability_post("/v1/availability", options)
848
848
 
849
849
  parse_collections(
850
850
  response,
@@ -889,7 +889,7 @@ module Cronofy
889
889
 
890
890
  translate_available_periods(options[:query_periods] || options[:available_periods])
891
891
 
892
- response = post("/v1/sequenced_availability", options)
892
+ response = availability_post("/v1/sequenced_availability", options)
893
893
  parse_collection(Sequence, "sequences", response)
894
894
  end
895
895
 
@@ -1811,6 +1811,17 @@ module Cronofy
1811
1811
  wrapped_request { @auth.api_client.request(:post, url, json_request_args(body)) }
1812
1812
  end
1813
1813
 
1814
+ # Availability Query could originally be authenticated via an access_token
1815
+ # Whilst it should be authed via an API key now, we try access_token first
1816
+ # for backward compatibility
1817
+ def availability_post(url, body)
1818
+ if @auth.access_token
1819
+ post(url, body)
1820
+ else
1821
+ wrapped_request { api_key!.post(url, json_request_args(body)) }
1822
+ end
1823
+ end
1824
+
1814
1825
  def wrapped_request
1815
1826
  yield
1816
1827
  rescue OAuth2::Error => e
@@ -1,3 +1,3 @@
1
1
  module Cronofy
2
- VERSION = "0.37.3".freeze
2
+ VERSION = "0.37.4".freeze
3
3
  end
@@ -1257,6 +1257,17 @@ describe Cronofy::Client do
1257
1257
  let(:request_url) { 'https://api.cronofy.com/v1/availability' }
1258
1258
  let(:request_headers) { json_request_headers }
1259
1259
 
1260
+ let(:client_id) { 'example_id' }
1261
+ let(:client_secret) { 'example_secret' }
1262
+ let(:token) { client_secret }
1263
+
1264
+ let(:client) do
1265
+ Cronofy::Client.new(
1266
+ client_id: client_id,
1267
+ client_secret: client_secret,
1268
+ )
1269
+ end
1270
+
1260
1271
  let(:request_body) do
1261
1272
  {
1262
1273
  "participants" => [
@@ -1770,6 +1781,87 @@ describe Cronofy::Client do
1770
1781
  it_behaves_like 'a Cronofy request'
1771
1782
  it_behaves_like 'a Cronofy request with mapped return value'
1772
1783
  end
1784
+
1785
+ context "when trying to auth with only an access_token, as originally implemented" do
1786
+ let(:access_token) { "access_token_123"}
1787
+ let(:client) { Cronofy::Client.new(access_token: access_token) }
1788
+ let(:request_headers) do
1789
+ {
1790
+ "Authorization" => "Bearer #{access_token}",
1791
+ "User-Agent" => "Cronofy Ruby #{::Cronofy::VERSION}",
1792
+ "Content-Type" => "application/json; charset=utf-8",
1793
+ }
1794
+ end
1795
+
1796
+ let(:participants) do
1797
+ { members: %w{acc_567236000909002 acc_678347111010113} }
1798
+ end
1799
+
1800
+ let(:required_duration) { 60 }
1801
+
1802
+ let(:available_periods) do
1803
+ [
1804
+ { start: Time.parse("2017-01-03T09:00:00Z"), end: Time.parse("2017-01-03T18:00:00Z") },
1805
+ { start: Time.parse("2017-01-04T09:00:00Z"), end: Time.parse("2017-01-04T18:00:00Z") },
1806
+ ]
1807
+ end
1808
+
1809
+ it_behaves_like 'a Cronofy request'
1810
+ it_behaves_like 'a Cronofy request with mapped return value'
1811
+ end
1812
+
1813
+ context "when trying to auth with both a client_secret and access_token" do
1814
+ let(:access_token) { "access_token_123" }
1815
+ let(:client_secret) { "client_secret_456" }
1816
+ let(:client) { Cronofy::Client.new(access_token: access_token, client_secret: client_secret) }
1817
+ let(:request_headers) do
1818
+ {
1819
+ "Authorization" => "Bearer #{access_token}",
1820
+ "User-Agent" => "Cronofy Ruby #{::Cronofy::VERSION}",
1821
+ "Content-Type" => "application/json; charset=utf-8",
1822
+ }
1823
+ end
1824
+
1825
+ let(:participants) do
1826
+ { members: %w{acc_567236000909002 acc_678347111010113} }
1827
+ end
1828
+
1829
+ let(:required_duration) { 60 }
1830
+
1831
+ let(:available_periods) do
1832
+ [
1833
+ { start: Time.parse("2017-01-03T09:00:00Z"), end: Time.parse("2017-01-03T18:00:00Z") },
1834
+ { start: Time.parse("2017-01-04T09:00:00Z"), end: Time.parse("2017-01-04T18:00:00Z") },
1835
+ ]
1836
+ end
1837
+
1838
+ describe "it prefers the access_token for backward compatibility" do
1839
+ it_behaves_like 'a Cronofy request'
1840
+ it_behaves_like 'a Cronofy request with mapped return value'
1841
+ end
1842
+ end
1843
+
1844
+ context "when trying to auth without a client_secret or access_token" do
1845
+ let(:client) { Cronofy::Client.new }
1846
+
1847
+ let(:participants) do
1848
+ { members: %w{acc_567236000909002 acc_678347111010113} }
1849
+ end
1850
+
1851
+ let(:required_duration) { 60 }
1852
+
1853
+ let(:available_periods) do
1854
+ [
1855
+ { start: Time.parse("2017-01-03T09:00:00Z"), end: Time.parse("2017-01-03T18:00:00Z") },
1856
+ { start: Time.parse("2017-01-04T09:00:00Z"), end: Time.parse("2017-01-04T18:00:00Z") },
1857
+ ]
1858
+ end
1859
+
1860
+
1861
+ it "raises an API Key error" do
1862
+ expect{ subject }.to raise_error(Cronofy::CredentialsMissingError)
1863
+ end
1864
+ end
1773
1865
  end
1774
1866
  end
1775
1867
 
@@ -1779,6 +1871,17 @@ describe Cronofy::Client do
1779
1871
  let(:request_url) { 'https://api.cronofy.com/v1/sequenced_availability' }
1780
1872
  let(:request_headers) { json_request_headers }
1781
1873
 
1874
+ let(:client_id) { 'example_id' }
1875
+ let(:client_secret) { 'example_secret' }
1876
+ let(:token) { client_secret }
1877
+
1878
+ let(:client) do
1879
+ Cronofy::Client.new(
1880
+ client_id: client_id,
1881
+ client_secret: client_secret,
1882
+ )
1883
+ end
1884
+
1782
1885
  let(:request_body) do
1783
1886
  {
1784
1887
  "sequence" => [
@@ -1937,6 +2040,45 @@ describe Cronofy::Client do
1937
2040
  it_behaves_like 'a Cronofy request'
1938
2041
  it_behaves_like 'a Cronofy request with mapped return value'
1939
2042
  end
2043
+
2044
+ context "when trying to auth with access_token only" do
2045
+ let(:access_token) { "access_token_123"}
2046
+ let(:client) { Cronofy::Client.new(access_token: access_token) }
2047
+ let(:request_headers) do
2048
+ {
2049
+ "Authorization" => "Bearer #{access_token}",
2050
+ "User-Agent" => "Cronofy Ruby #{::Cronofy::VERSION}",
2051
+ "Content-Type" => "application/json; charset=utf-8",
2052
+ }
2053
+ end
2054
+
2055
+ it_behaves_like 'a Cronofy request'
2056
+ it_behaves_like 'a Cronofy request with mapped return value'
2057
+ end
2058
+
2059
+ context "when trying to auth with both access_token and client_secret provided" do
2060
+ let(:client_id) { 'example_id' }
2061
+ let(:client_secret) { 'example_secret' }
2062
+ let(:access_token) { "access_token_123"}
2063
+
2064
+ let(:client) do
2065
+ Cronofy::Client.new(
2066
+ client_id: client_id,
2067
+ client_secret: client_secret,
2068
+ access_token: access_token,
2069
+ )
2070
+ end
2071
+ let(:request_headers) do
2072
+ {
2073
+ "Authorization" => "Bearer #{access_token}",
2074
+ "User-Agent" => "Cronofy Ruby #{::Cronofy::VERSION}",
2075
+ "Content-Type" => "application/json; charset=utf-8",
2076
+ }
2077
+ end
2078
+
2079
+ it_behaves_like 'a Cronofy request'
2080
+ it_behaves_like 'a Cronofy request with mapped return value'
2081
+ end
1940
2082
  end
1941
2083
  end
1942
2084
 
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.37.3
4
+ version: 0.37.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergii Paryzhskyi
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2021-07-02 00:00:00.000000000 Z
12
+ date: 2022-03-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: hashie
@@ -156,7 +156,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
156
156
  - !ruby/object:Gem::Version
157
157
  version: '0'
158
158
  requirements: []
159
- rubygems_version: 3.2.20
159
+ rubygems_version: 3.2.32
160
160
  signing_key:
161
161
  specification_version: 4
162
162
  summary: Cronofy - the scheduling platform for business