dock_health_api 0.5.5 → 0.5.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -1
- data/lib/dock_health_api/client.rb +21 -20
- data/lib/dock_health_api/resource.rb +1 -1
- data/lib/dock_health_api/version.rb +1 -1
- data/lib/dock_health_api.rb +1 -1
- data/spec/client_spec.rb +5 -10
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 60108cba91179c4029f17053daa0ee7cde2e6a067e48e35461db07e8c2bcefc0
|
4
|
+
data.tar.gz: 49fd631f9c4f65bc3bdf7570848dad0f6da8a387b67bf65e0b0ff1d2ae8feb31
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 839de68118bab1fb66bc0136ac1d5f53e8585cbcd97a393bd59a767357c94ee8d19c11df84f014c9ccccd0e1829d67a0087ab596fbaa8227d138572b52e26e83
|
7
|
+
data.tar.gz: '0498a398b03fe384825157e1ee6d0135315443edb6ba97d5dd330a5e9d057eff3cf8a70d73e60ffad2231a01e528197046f5bdb9b4c68561626403106dcabd3f'
|
data/Gemfile.lock
CHANGED
@@ -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
|
8
|
-
@config = config
|
12
|
+
def initialize
|
13
|
+
@config = DockHealthApi.config
|
9
14
|
end
|
10
15
|
|
11
|
-
def
|
12
|
-
|
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
|
-
|
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
|
-
|
48
|
-
|
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 =
|
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
|
data/lib/dock_health_api.rb
CHANGED
@@ -53,7 +53,7 @@ module DockHealthApi
|
|
53
53
|
def_delegators :@config, :iframe_base_url, :iframe_base_url=
|
54
54
|
|
55
55
|
def receive_iframe_token
|
56
|
-
Client.
|
56
|
+
Client.instance.iframe_token_connection if iframe_token_expired?
|
57
57
|
end
|
58
58
|
|
59
59
|
def iframe_token_expired?
|
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
|
-
|
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.
|
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.
|
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.
|
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.
|
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.
|
4
|
+
version: 0.5.7
|
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-
|
12
|
+
date: 2023-01-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: oauth2
|