dock_health_api 0.5.5 → 0.5.6

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: 16bead509bc4ac6ce1933a1556fa99bdfcfcfa74983fa6746a9a1db128192f34
4
- data.tar.gz: 8addd57bd9d99fd89805abc37a00d85ff6fc04c34fa2ae23e11da20a1dd3127d
3
+ metadata.gz: 6d06240d8efd2c2ac6c4b49cb3d6525379498665991a0c873efdb72707bd489d
4
+ data.tar.gz: c082a4f60607579cc01a7e4f10655e0b954c6b4bb1641f981c663b7bc569b920
5
5
  SHA512:
6
- metadata.gz: ab9842ad4661c0ddc4f14c09c666a482eeaf0b5b71cbc2b7a6241738b5acff4c18d1be4a7642ec07e1f9338d8105ce28b7e7b2e1177dc28613f2a1a14f503689
7
- data.tar.gz: c395ad1e5ece0e1e394039b15adfd6ab309fef3c002f8178b3a939b6e1c5fad7049b0abb6517a6db63112edd18da0138f43cc09b9932018b59bc9f2cd0e35f6f
6
+ metadata.gz: b4ed56ce48bd425eb26d9e96daa60f37ca13fdcc16f95340662d0a62db14e1f5d535a033f4bfcc57561d5c9eb4bd5d5c8cc7df2701a044c92a0084e62d92f955
7
+ data.tar.gz: 77b3bbd488d916dec0ac6f77364cd5d2949e24112d53ba16a7ca1768f680d1c711a7cf91ee9358c2b1c24d10f9000b8f4206348af0245dad2573b54ef5a17437
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dock_health_api (0.5.5)
4
+ dock_health_api (0.5.6)
5
5
  oauth2 (~> 1.4)
6
6
  ostruct
7
7
  rspec (~> 3.0)
@@ -48,6 +48,7 @@ GEM
48
48
 
49
49
  PLATFORMS
50
50
  arm64-darwin-21
51
+ ruby
51
52
  x86_64-linux
52
53
 
53
54
  DEPENDENCIES
@@ -1,15 +1,20 @@
1
1
  require "oauth2"
2
+ require 'singleton'
2
3
 
3
4
  module DockHealthApi
4
5
  class Client
6
+ BUFFER = 120
7
+
8
+ include Singleton
9
+
5
10
  attr_reader :config
6
11
 
7
- def initialize(config = {})
8
- @config = config
12
+ def initialize
13
+ @config = DockHealthApi.config
9
14
  end
10
15
 
11
- def self.active_client
12
- new(DockHealthApi.config)
16
+ def active_client
17
+ instance
13
18
  end
14
19
 
15
20
  def connection
@@ -17,14 +22,18 @@ module DockHealthApi
17
22
  end
18
23
 
19
24
  def token_connection
20
- unless @token_connection
21
- get_token
22
- else
23
- get_token if token_expired?(DockHealthApi.token_expires_at)
24
- end
25
+ get_token if @token_connection.nil? || token_about_to_expire?
25
26
  @token_connection
26
27
  end
27
28
 
29
+ def token_expiration_time
30
+ @token_expiration_time ||= Time.now + @token_connection.expires_in
31
+ end
32
+
33
+ def token_about_to_expire?
34
+ Time.now + BUFFER > token_expiration_time
35
+ end
36
+
28
37
  def iframe_token_connection
29
38
  get_iframe_token
30
39
  @iframe_token_connection
@@ -38,25 +47,17 @@ module DockHealthApi
38
47
  @iframe_token ||= iframe_token_connection.token
39
48
  end
40
49
 
41
- def token_expired?(expires_at)
42
- Time.now > expires_at
43
- end
44
-
45
50
  def get_token
46
51
  @token_connection = connection.client_credentials.get_token(scope:"dockhealth/system.developer.read dockhealth/user.all.write dockhealth/user.all.read dockhealth/system.developer.write dockhealth/patient.all.read dockhealth/patient.all.write")
47
- DockHealthApi.token = @token_connection.token
48
- DockHealthApi.token_expires_at = token_expiration_time(@token_connection.expires_in)
52
+ @token_expiration_time = Time.now + @token_connection.expires_in
53
+ @token_connection
49
54
  end
50
55
 
51
56
  def get_iframe_token
52
57
  @iframe_token_connection = connection.client_credentials.get_token(scope:"dockhealth/system.embedded.launch")
53
58
  return @iframe_token_connection if @iframe_token_connection.nil?
54
59
  DockHealthApi.iframe_token = @iframe_token_connection.token
55
- DockHealthApi.iframe_token_expires_at = token_expiration_time(@iframe_token_connection.expires_in)
56
- end
57
-
58
- def token_expiration_time(expires_in)
59
- Time.now + expires_in
60
+ DockHealthApi.iframe_token_expires_at = Time.now + @iframe_token_connection.expires_in
60
61
  end
61
62
  end
62
63
  end
@@ -9,7 +9,7 @@ module DockHealthApi
9
9
  end
10
10
 
11
11
  def self.client
12
- @client ||= DockHealthApi::Client.active_client
12
+ DockHealthApi::Client.instance
13
13
  end
14
14
 
15
15
  def self.resource_url
@@ -1,3 +1,3 @@
1
1
  module DockHealthApi
2
- VERSION = "0.5.5"
2
+ VERSION = "0.5.6"
3
3
  end
data/spec/client_spec.rb CHANGED
@@ -4,25 +4,20 @@ require 'spec_helper'
4
4
  RSpec.describe DockHealthApi::Client do
5
5
  let(:config) { DockHealthApi::Config.new }
6
6
 
7
- it 'should be able to be initialized with a Config object' do
8
- client = DockHealthApi::Client.new(config)
9
- expect(client.config).to eq(config)
10
- end
11
-
12
- describe '#active_client' do
7
+ describe '#instance' do
13
8
  it 'should config new client with standard config' do
14
- expect(DockHealthApi::Client.active_client.config).to eq(DockHealthApi.config)
9
+ expect(DockHealthApi::Client.instance.config).to eq(DockHealthApi.config)
15
10
  end
16
11
  end
17
12
 
18
13
  describe "#connection" do
19
14
  it 'should initialize an OAuth2::Client object' do
20
- expect(DockHealthApi::Client.active_client.connection.is_a?(OAuth2::Client))
15
+ expect(DockHealthApi::Client.instance.connection.is_a?(OAuth2::Client))
21
16
  end
22
17
  end
23
18
 
24
19
  describe "#token_connection" do
25
- let (:token_connection) { DockHealthApi::Client.active_client.token_connection }
20
+ let (:token_connection) { DockHealthApi::Client.instance.token_connection }
26
21
 
27
22
  it 'should return a OAuth2::AccessToken object' do
28
23
  expect(token_connection.is_a?(OAuth2::AccessToken))
@@ -34,7 +29,7 @@ RSpec.describe DockHealthApi::Client do
34
29
  end
35
30
 
36
31
  describe "#get_iframe_token" do
37
- let (:iframe_token_connection) { DockHealthApi::Client.active_client.iframe_token_connection }
32
+ let (:iframe_token_connection) { DockHealthApi::Client.instance.iframe_token_connection }
38
33
 
39
34
  it 'should return a OAuth2::AccessToken object for iframe' do
40
35
  expect(iframe_token_connection.is_a?(OAuth2::AccessToken))
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dock_health_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.5
4
+ version: 0.5.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Magomero
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2023-01-04 00:00:00.000000000 Z
12
+ date: 2023-01-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: oauth2