dhc 2.3.0 → 2.4.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: 674d43c54e6a69f47876b85ef1cc08fdd015002ac96f59fada268959d970d356
4
- data.tar.gz: 1e9babbad39edeeedde2269d93108a2a0f604ff56cd7f66de5c960de68328bf8
3
+ metadata.gz: 9547c0b934f2ac6841be72e6f63213dc50d005c6f8559909869dd2ecb12e1e60
4
+ data.tar.gz: 3b7335a60aaffe92da269dd0a8fb7a51e66471136a506f0ae4de651a2ac95d8d
5
5
  SHA512:
6
- metadata.gz: 2f29a2c073127d45a6fcd88fab98b8b82b27f3e64aa40a71eab788af580d972d0df7d2dba16e7ba528a28e21a59bf44bfb7d15a93f13bacfd03b1e6d7a0bf78b
7
- data.tar.gz: 42aadb278b925b63b2c947616ae7c1c6f6d1c7b54487287303c8b3c0b59b54ed0f7b45de501615b8ab854bd73d9e125218ac7c8c205b033566ada8747766ae06
6
+ metadata.gz: 39ed2e1baec1153872532441114157e7c7170f76746c4f8e9f77b585c36d0999f3047298d05daee2128dd13b74f21c87ba7b3822bbc703c5aa0c4da390511f4f
7
+ data.tar.gz: 9a6ae9ca323bf5d69d1668e72ceaa5969d79e2dc315a575df805b53d48c24321f537d6ab135d4e1412840cc52c7d400e71fbf121b985fe9eefbc86dfd38f7e91
data/README.md CHANGED
@@ -475,7 +475,7 @@ Assuming the method `access_token` responds on runtime of the request with `1234
475
475
 
476
476
  If you configure `expires_at` and `refresh` proc in addition to `bearer`, DHC will refresh the bearer token using the defined `refresh` proc in two cases:
477
477
 
478
- 1. before the request if `expires_at` < `DateTime.now + 1.minute`
478
+ 1. before the request if `expires_at.call` < `DateTime.now + 1.minute`
479
479
  2. if the request fails and `refresh(response)` responds to true
480
480
 
481
481
  ```ruby
@@ -489,7 +489,7 @@ refresh = ->(response = nil){
489
489
  end
490
490
  }
491
491
 
492
- DHC.get('http://depay.fi', auth: { bearer: -> { session[:access_token] }, refresh: refresh, expires_at: DateTime.now + 1.day })
492
+ DHC.get('http://depay.fi', auth: { bearer: -> { session[:access_token] }, refresh: refresh, expires_at: -> { session[:expires_at] } })
493
493
  ```
494
494
 
495
495
  ##### Basic Authentication
@@ -28,6 +28,7 @@ class DHC::Auth < DHC::Interceptor
28
28
  end
29
29
 
30
30
  def bearer_expired?(expires_at)
31
+ expires_at = expires_at.call if expires_at.is_a?(Proc)
31
32
  expires_at = DateTime.parse(expires_at) if expires_at.is_a?(String)
32
33
  expires_at < DateTime.now + 1.minute
33
34
  end
data/lib/dhc/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DHC
4
- VERSION ||= '2.3.0'
4
+ VERSION ||= '2.4.0'
5
5
  end
@@ -50,14 +50,14 @@ describe DHC::Auth do
50
50
 
51
51
  it 'refreshes the bearer if it expired' do
52
52
  stub_request(:get, 'http://depay.fi/').with(headers: { 'Authorization' => 'Bearer 2_ACCESS_TOKEN' })
53
- DHC.get('http://depay.fi', auth: { bearer: -> { session[:access_token] }, refresh: refresh, expires_at: (DateTime.now - 1.minute).to_s })
53
+ DHC.get('http://depay.fi', auth: { bearer: -> { session[:access_token] }, refresh: refresh, expires_at: -> { (DateTime.now - 1.minute).to_s } })
54
54
  end
55
55
 
56
56
  it 'can evaluate response errors (like unauthorized) inside the refresh proc' do
57
57
  stub_request(:get, 'http://depay.fi/').with(headers: { 'Authorization' => 'Bearer 2_ACCESS_TOKEN' })
58
58
  .to_return(status: 401, body: { "error_code": 'ACCESS_TOKEN_EXPIRED' }.to_json)
59
59
  stub_request(:get, 'http://depay.fi/').with(headers: { 'Authorization' => 'Bearer 3_ACCESS_TOKEN' })
60
- DHC.get('http://depay.fi', auth: { bearer: -> { session[:access_token] }, refresh: refresh, expires_at: (DateTime.now - 1.minute).to_s })
60
+ DHC.get('http://depay.fi', auth: { bearer: -> { session[:access_token] }, refresh: refresh, expires_at: -> { (DateTime.now - 1.minute).to_s } })
61
61
  end
62
62
  end
63
63
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dhc
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.0
4
+ version: 2.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - https://github.com/DePayFi/dhc/contributors
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-02-02 00:00:00.000000000 Z
11
+ date: 2023-02-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport