cronofy 0.9.0 → 0.10.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
  SHA1:
3
- metadata.gz: 326fa8f77f51139784236c0a9e2f73cdc53edecc
4
- data.tar.gz: 3b314897d498fcf530953ac9bd44bcfd7b21f533
3
+ metadata.gz: e337b294d628d5677d58763c49dd46441d66edcf
4
+ data.tar.gz: 7ad6ea54a3fd5cba4b43f7f2533368574fa1639e
5
5
  SHA512:
6
- metadata.gz: b36221de26d3abf310b4be4ce4ea29a7c02bf0858ea36f9924488559fd9db24dea773b07c0a8d47863f940bb0484b4349a1b6796538c437c25b6d9dd1325591c
7
- data.tar.gz: d78d17162887646dbfc909290ceabc2fb2bd080253597a54c0aa3be452504d01112dd1b1b91c323734b023bdae071b211a419a2994e0a5b7d7c60194544209c9
6
+ metadata.gz: ae50423467418330fbe878fbf70fbb2e8547c69e17b94858b0d66e1c9e700d0e54d1c827fbdb2abb16f7aa796f5ad5c8d81d3878d742266858051918c508dd76
7
+ data.tar.gz: 747e9ef78b0da42569496a3ff48ebdce4213be8848dc1a8332cd1c4d507e419fd23c5c8c057f49b08b6a055cae017a22d31ee7f7407422abefea714edb3d8dca
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
+
5
+ gem "rack", "~> 1.0"
data/lib/cronofy/auth.rb CHANGED
@@ -11,7 +11,7 @@ module Cronofy
11
11
  @auth_client = OAuth2::Client.new(client_id, client_secret, site: ::Cronofy.app_url, connection_opts: { headers: { "User-Agent" => "Cronofy Ruby #{::Cronofy::VERSION}" } })
12
12
  @api_client = OAuth2::Client.new(client_id, client_secret, site: ::Cronofy.api_url, connection_opts: { headers: { "User-Agent" => "Cronofy Ruby #{::Cronofy::VERSION}" } })
13
13
 
14
- set_access_token(token, refresh_token) if token
14
+ set_access_token(token, refresh_token) if token || refresh_token
15
15
  end
16
16
 
17
17
  # Internal: generate a URL for authorizing the application with Cronofy
@@ -52,8 +52,15 @@ module Cronofy
52
52
  end
53
53
 
54
54
  # Internal: Refreshes the access token
55
- # Returns Hash of token elements to allow client to update in local store for user
55
+ #
56
+ # Returns Hash of token elements to allow client to update in local store
57
+ # for user
58
+ #
59
+ # Raises Cronofy::CredentialsMissingError if no credentials available.
56
60
  def refresh!
61
+ raise CredentialsMissingError.new("No credentials to refresh") unless access_token
62
+ raise CredentialsMissingError.new("No refresh_token provided") unless access_token.refresh_token
63
+
57
64
  do_request do
58
65
  @access_token = access_token.refresh!
59
66
  Credentials.new(@access_token)
@@ -71,12 +78,16 @@ module Cronofy
71
78
  # Internal: Revokes the refresh token and corresponding access tokens.
72
79
  #
73
80
  # Returns nothing.
81
+ #
82
+ # Raises Cronofy::CredentialsMissingError if no credentials available.
74
83
  def revoke!
84
+ raise CredentialsMissingError.new("No credentials to revoke") unless access_token
85
+
75
86
  do_request do
76
87
  body = {
77
88
  client_id: @api_client.id,
78
89
  client_secret: @api_client.secret,
79
- token: access_token.refresh_token,
90
+ token: access_token.refresh_token || access_token.token,
80
91
  }
81
92
 
82
93
  @api_client.request(:post, "/oauth/token/revoke", body: body)
@@ -455,6 +455,7 @@ module Cronofy
455
455
  # been revoked.
456
456
  # Raises Cronofy::AuthenticationFailureError if the client ID and secret are
457
457
  # not valid.
458
+ # Raises Cronofy::CredentialsMissingError if no credentials available.
458
459
  def refresh_access_token
459
460
  @auth.refresh!
460
461
  end
@@ -471,6 +472,7 @@ module Cronofy
471
472
  #
472
473
  # Raises Cronofy::AuthenticationFailureError if the client ID and secret are
473
474
  # not valid.
475
+ # Raises Cronofy::CredentialsMissingError if no credentials available.
474
476
  def revoke_authorization
475
477
  @auth.revoke!
476
478
  end
@@ -1,3 +1,3 @@
1
1
  module Cronofy
2
- VERSION = "0.9.0".freeze
2
+ VERSION = "0.10.0".freeze
3
3
  end
@@ -243,46 +243,114 @@ describe Cronofy::Auth do
243
243
  end
244
244
 
245
245
  describe '#refresh!' do
246
- subject do
247
- Cronofy::Auth.new(client_id, client_secret, access_token, refresh_token).refresh!
246
+ context "access_token and refresh_token present" do
247
+ subject do
248
+ Cronofy::Auth.new(client_id, client_secret, access_token, refresh_token).refresh!
249
+ end
250
+
251
+ it_behaves_like 'an authorization request'
248
252
  end
249
253
 
250
- it_behaves_like 'an authorization request'
254
+ context "no refresh_token" do
255
+ subject do
256
+ Cronofy::Auth.new(client_id, client_secret, access_token, nil).refresh!
257
+ end
258
+
259
+ it "raises a credentials missing error" do
260
+ expect { subject }.to raise_error(Cronofy::CredentialsMissingError)
261
+ end
262
+ end
263
+
264
+ context "no access_token or refresh_token" do
265
+ subject do
266
+ Cronofy::Auth.new(client_id, client_secret, nil, nil).refresh!
267
+ end
268
+
269
+ it "raises a credentials missing error" do
270
+ expect { subject }.to raise_error(Cronofy::CredentialsMissingError)
271
+ end
272
+ end
273
+
274
+ context "only refresh_token" do
275
+ subject do
276
+ Cronofy::Auth.new(client_id, client_secret, nil, refresh_token).refresh!
277
+ end
278
+
279
+ it_behaves_like 'an authorization request'
280
+ end
251
281
  end
252
282
 
253
283
  describe "#revoke!" do
254
- let(:auth) do
255
- Cronofy::Auth.new(client_id, client_secret, access_token, refresh_token)
284
+ shared_examples 'successful revocation' do
285
+ let!(:revocation_request) do
286
+ stub_request(:post, "https://api.cronofy.com/oauth/token/revoke")
287
+ .with(
288
+ body: {
289
+ client_id: client_id,
290
+ client_secret: client_secret,
291
+ token: revoke_token,
292
+ },
293
+ headers: {
294
+ 'Content-Type' => 'application/x-www-form-urlencoded',
295
+ 'User-Agent' => "Cronofy Ruby #{Cronofy::VERSION}",
296
+ }
297
+ )
298
+ .to_return(
299
+ status: response_status,
300
+ )
301
+ end
302
+
303
+ before do
304
+ auth.revoke!
305
+ end
306
+
307
+ it "unsets the access token" do
308
+ expect(auth.access_token).to be_nil
309
+ end
310
+
311
+ it "makes the revocation request" do
312
+ expect(revocation_request).to have_been_requested
313
+ end
256
314
  end
257
315
 
258
- let!(:revocation_request) do
259
- stub_request(:post, "https://api.cronofy.com/oauth/token/revoke")
260
- .with(
261
- body: {
262
- client_id: client_id,
263
- client_secret: client_secret,
264
- token: refresh_token,
265
- },
266
- headers: {
267
- 'Content-Type' => 'application/x-www-form-urlencoded',
268
- 'User-Agent' => "Cronofy Ruby #{Cronofy::VERSION}",
269
- }
270
- )
271
- .to_return(
272
- status: response_status,
273
- )
316
+ context "access_token and refresh_token present" do
317
+ let(:auth) do
318
+ Cronofy::Auth.new(client_id, client_secret, access_token, refresh_token)
319
+ end
320
+
321
+ let(:revoke_token) { refresh_token }
322
+
323
+ it_behaves_like 'successful revocation'
274
324
  end
275
325
 
276
- before do
277
- auth.revoke!
326
+ context "only refresh_token" do
327
+ let(:auth) do
328
+ Cronofy::Auth.new(client_id, client_secret, nil, refresh_token)
329
+ end
330
+
331
+ let(:revoke_token) { refresh_token }
332
+
333
+ it_behaves_like 'successful revocation'
278
334
  end
279
335
 
280
- it "unsets the access token" do
281
- expect(auth.access_token).to be_nil
336
+ context "only access_token" do
337
+ let(:auth) do
338
+ Cronofy::Auth.new(client_id, client_secret, access_token, nil)
339
+ end
340
+
341
+ let(:revoke_token) { access_token }
342
+
343
+ it_behaves_like 'successful revocation'
282
344
  end
283
345
 
284
- it "makes the revocation request" do
285
- expect(revocation_request).to have_been_requested
346
+ context "no access_token or refresh_token" do
347
+ let(:auth) do
348
+ Cronofy::Auth.new(client_id, client_secret, nil, nil)
349
+ end
350
+
351
+ it "raises a credentials missing error" do
352
+ expect { auth.revoke! }.to raise_error(Cronofy::CredentialsMissingError)
353
+ end
286
354
  end
287
355
  end
288
356
  end
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.9.0
4
+ version: 0.10.0
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: 2016-05-23 00:00:00.000000000 Z
12
+ date: 2016-07-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: oauth2