dock_health_api 0.3.6 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d075dd5e8af51bb7f8ce46fd3ec8700fd9ad05c48b06e8110df741280883eba5
4
- data.tar.gz: 83d0f7dc243f9f7fb3b4b6761bee25fb6e1e590256428d18480f8d4e659f30ee
3
+ metadata.gz: 7948e2eee630eae60b00389c067560a4db5400cca6ed56134619d95a97667bab
4
+ data.tar.gz: aaba98419dd489685a6f88274b43eeaa28224f012f35725498777ed480b12a86
5
5
  SHA512:
6
- metadata.gz: 93add110d6f99cdcc768468a6defde6509b7f2bb7889a5566b6c0940ef971d66dce821cb5dd72ef6a4d593efb016f73af6386ec1c7de944069731fc0fc1be20b
7
- data.tar.gz: ad01c17339126a686d0783148a22ee4c6950b612cb3183e58c5cf5f88d333f38102012988ded26759c2c0b53f8150504639fd1b8c52006a202e86e79cf732154
6
+ metadata.gz: 96a369151547d0cfba4b61a0776013db3ccb63172ae51b948e5b52637ab9bf16fbde5d32654d29a4f4a16ea534aeace8353f1ae1f739141f6f2b8307604bf6f7
7
+ data.tar.gz: 5c30bc833f4b9d5bf02d202aac2c1c29abd1b0ee5481cbc9a0ef3516318d8a51ca5f8c2da6740c029e93d16115904192add23d3e839719d025f3935e9a93a695
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dock_health_api (0.3.0)
4
+ dock_health_api (0.4.0)
5
5
  oauth2 (~> 1.4)
6
6
  ostruct
7
7
  rspec (~> 3.0)
@@ -17,11 +17,46 @@ module DockHealthApi
17
17
  end
18
18
 
19
19
  def token_connection
20
- @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")
20
+ unless @token_connection
21
+ get_token
22
+ else
23
+ get_token if token_expired?(DockHealthApi.token_expires_at)
24
+ end
25
+ @token_connection
26
+ end
27
+
28
+ def iframe_token_connection
29
+ get_iframe_token
30
+ @iframe_token_connection
21
31
  end
22
32
 
23
33
  def token
24
34
  @token ||= token_connection.token
25
35
  end
36
+
37
+ def iframe_token
38
+ @iframe_token ||= iframe_token_connection.token
39
+ end
40
+
41
+ def token_expired?(expires_at)
42
+ Time.now > expires_at
43
+ end
44
+
45
+ def get_token
46
+ @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)
49
+ end
50
+
51
+ def get_iframe_token
52
+ @iframe_token_connection = connection.client_credentials.get_token(scope:"dockhealth/system.embedded.launch")
53
+ return @iframe_token_connection if @iframe_token_connection.nil?
54
+ 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
+ end
26
61
  end
27
62
  end
@@ -1,6 +1,6 @@
1
1
  module DockHealthApi
2
2
  class Config
3
- attr_accessor :api_key, :api_secret, :api_base, :token_url, :resource_url, :org_id, :user_id, :api
3
+ attr_accessor :api_key, :api_secret, :api_base, :token_url, :resource_url, :org_id, :user_id, :api, :iframe_token, :token, :iframe_token_expires_at, :token_expires_at
4
4
 
5
5
  def initialize
6
6
  @token_url = "https://dock-health-dev.auth.us-east-1.amazoncognito.com/oauth2/token"
@@ -1,3 +1,3 @@
1
1
  module DockHealthApi
2
- VERSION = "0.3.6"
2
+ VERSION = "0.4.0"
3
3
  end
@@ -29,6 +29,7 @@ module DockHealthApi
29
29
  autoload :CustomField, "dock_health_api/resources/customfield"
30
30
 
31
31
  @config = DockHealthApi::Config.new
32
+ @iframe_base_url = "https://dev.dockhealth.app/#/auth/embedded?"
32
33
 
33
34
  class << self
34
35
  attr_reader :config
@@ -43,5 +44,55 @@ module DockHealthApi
43
44
  def_delegators :@config, :org_id, :org_id=
44
45
  def_delegators :@config, :user_id, :user_id=
45
46
  def_delegators :@config, :api, :api=
47
+ def_delegators :@config, :iframe_token, :iframe_token=
48
+ def_delegators :@config, :iframe_token_expires_at, :iframe_token_expires_at=
49
+ def_delegators :@config, :token, :token=
50
+ def_delegators :@config, :token_expires_at, :token_expires_at=
51
+
52
+ def receive_iframe_token
53
+ Client.active_client.iframe_token_connection if iframe_token_expired?
54
+ end
55
+
56
+ def iframe_token_expired?
57
+ return Time.now > self.iframe_token_expires_at if self.iframe_token_expires_at
58
+ true
59
+ end
60
+
61
+ def iframe_url(arg={})
62
+ DockHealthApi.receive_iframe_token
63
+ dock_user_id = arg[:user_id]
64
+ view_type = arg[:view_type]
65
+ target_type = arg[:target_type]
66
+ target_id = arg[:target_id]
67
+
68
+ @iframe_base_url+"authToken=#{iframe_token}&dockOrganizationId=#{org_id}&dockUserId=#{dock_user_id}&viewType=#{view_type}&targetType=#{target_type}&targetId=#{target_id}"
69
+ end
70
+
71
+ def patient_url(arg={})
72
+ receive_iframe_token
73
+ view_type = "PATIENT"
74
+ target_type = "PATIENT"
75
+ dock_user_id = arg[:user_id]
76
+ target_id = arg[:patient_id]
77
+
78
+ @iframe_base_url+"authToken=#{iframe_token}&dockOrganizationId=#{org_id}&dockUserId=#{dock_user_id}&viewType=#{view_type}&targetType=#{target_type}&targetId=#{target_id}"
79
+ end
80
+
81
+
82
+ def user_url(arg={})
83
+ receive_iframe_token
84
+ dock_user_id = arg[:user_id]
85
+
86
+ @iframe_base_url+"authToken=#{iframe_token}&dockOrganizationId=#{org_id}&dockUserId=#{dock_user_id}"
87
+ end
88
+
89
+ def tasklist_url(arg={})
90
+ receive_iframe_token
91
+ view_type = "LIST"
92
+ target_type = "LIST"
93
+ target_id = arg[:tasklist_id]
94
+
95
+ @iframe_base_url+"authToken=#{iframe_token}&dockOrganizationId=#{org_id}&dockUserId=#{user_id}&viewType=#{view_type}&targetType=#{target_type}&targetId=#{target_id}"
96
+ end
46
97
  end
47
98
  end
data/spec/client_spec.rb CHANGED
@@ -32,4 +32,16 @@ RSpec.describe DockHealthApi::Client do
32
32
  expect(token_connection.token).to_not be(nil)
33
33
  end
34
34
  end
35
- end
35
+
36
+ describe "#get_iframe_token" do
37
+ let (:iframe_token_connection) { DockHealthApi::Client.active_client.iframe_token_connection }
38
+
39
+ it 'should return a OAuth2::AccessToken object for iframe' do
40
+ expect(iframe_token_connection.is_a?(OAuth2::AccessToken))
41
+ end
42
+
43
+ it 'should return include an iframe token' do
44
+ expect(iframe_token_connection.token).to_not be(nil)
45
+ end
46
+ end
47
+ end
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.3.6
4
+ version: 0.4.0
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: 2022-08-22 00:00:00.000000000 Z
12
+ date: 2022-09-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: oauth2