dock_health_api 0.5.5 → 0.5.6
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/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: 6d06240d8efd2c2ac6c4b49cb3d6525379498665991a0c873efdb72707bd489d
|
4
|
+
data.tar.gz: c082a4f60607579cc01a7e4f10655e0b954c6b4bb1641f981c663b7bc569b920
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b4ed56ce48bd425eb26d9e96daa60f37ca13fdcc16f95340662d0a62db14e1f5d535a033f4bfcc57561d5c9eb4bd5d5c8cc7df2701a044c92a0084e62d92f955
|
7
|
+
data.tar.gz: 77b3bbd488d916dec0ac6f77364cd5d2949e24112d53ba16a7ca1768f680d1c711a7cf91ee9358c2b1c24d10f9000b8f4206348af0245dad2573b54ef5a17437
|
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/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.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-
|
12
|
+
date: 2023-01-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: oauth2
|