dock_health_api 0.3.6 → 0.4.1

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: ee077425b72c248b6d549be0e696dbb962f64c76b09eaf07000acdf9353aeebd
4
+ data.tar.gz: db0e1fa7d75f574d16cd46cc71a838f24f1f31083371cfea78109874d4e16c2c
5
5
  SHA512:
6
- metadata.gz: 93add110d6f99cdcc768468a6defde6509b7f2bb7889a5566b6c0940ef971d66dce821cb5dd72ef6a4d593efb016f73af6386ec1c7de944069731fc0fc1be20b
7
- data.tar.gz: ad01c17339126a686d0783148a22ee4c6950b612cb3183e58c5cf5f88d333f38102012988ded26759c2c0b53f8150504639fd1b8c52006a202e86e79cf732154
6
+ metadata.gz: 64276bf68cd5d90cbda50a3c6a6cf30a761fb8ba8f9d98b4c0dadbdb4f365fe49dc20aaea6c8c485e395076b3b33a13576f9f443176235797f7e3999317c1b77
7
+ data.tar.gz: f1e60b666372844d91f10e2d358a250826286845be052e1352ac9922ddd686869420f15a3de3e8a882157c2483914b498891631d7c09f77ff9bf9f401280c9f3
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)
data/README.md CHANGED
@@ -94,7 +94,7 @@ DockHealthApi::TaskList.delete(id: "<tasklist ID>")
94
94
  params = { taskList: { type: "tasklist type", id: "<tasklist id>" }, user: { type: "user type", id: "<user id>" } }
95
95
  DockHealthApi::TaskList::User.put(params)
96
96
  # Update role for existing user in tasklist
97
- params = { taskList: { type: "tasklist type", id: "<tasklist id>" }, user: { type: "user type", id: "<user id>", userRole: "user role"} }
97
+ params = { taskList: { type: "tasklist type", id: "<tasklist id>" }, user: { type: "user type", id: "<user id>" }, userRole: "user role" }
98
98
  DockHealthApi::TaskList::User.update(params)
99
99
  # Delete existing user from tasklist
100
100
  params = { taskList: { type: "tasklist type", id: "<tasklist id>" }, user: { type: "user type", id: "<user id>" } }
@@ -114,14 +114,16 @@ DockHealthApi::Webhook.put(params)
114
114
  DockHealthApi::Webhook.delete(id: "<webhook id>")
115
115
 
116
116
  # Get Specific Organization
117
- DockHealthApi::Organization.get('id of user')
117
+ DockHealthApi::Organization.get('id of organization')
118
118
  # Create Organization
119
119
  DockHealthApi::Organization.create(organization_data)
120
120
  # Update Specific Organization
121
121
  DockHealthApi::Organization.update(updated_organization_data)
122
122
  # Delete Specific Organization (can't be an active Organization)
123
123
  DockHealthApi::Organization.delete({id: "id of organization"})
124
-
124
+ # Add User to Organization
125
+ params = { userId: "<user id>", organizationId: "<organization id>" }
126
+ DockHealthApi::Organization::User.update(params)
125
127
 
126
128
  ```
127
129
 
@@ -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"
@@ -11,7 +11,7 @@ module DockHealthApi
11
11
  end
12
12
 
13
13
  def self.list(**params)
14
- headers = {"x-api-key": "#{ENV["DOCK_HEALTH_API"]}", "x-user-id": "#{ENV["DOCK_USER"]}", "x-organization-id": "#{ENV["DOCK_ORG"]}"}
14
+ headers = {"x-api-key": "#{ENV["DOCK_HEALTH_API"]}", "x-user-id": "#{ENV["DOCK_USER"]}", "x-organization-id": client.config.org_id}
15
15
  response = execute_request(:get, "#{resource_url}", headers: headers, params: params)
16
16
  return response.parsed
17
17
  new(response.parsed)
@@ -7,7 +7,7 @@ module DockHealthApi
7
7
  extend DockHealthApi::Crud::List
8
8
 
9
9
  def self.list(**params)
10
- headers = {"x-api-key": "#{ENV["DOCK_HEALTH_API"]}", "x-user-id": "#{ENV["DOCK_USER"]}", "x-organization-id": "#{ENV["DOCK_ORG"]}"}
10
+ headers = {"x-api-key": "#{ENV["DOCK_HEALTH_API"]}", "x-user-id": "#{ENV["DOCK_USER"]}", "x-organization-id": client.config.org_id}
11
11
  response = execute_request(:get, "#{resource_url}", headers: headers, params: params)
12
12
  return response.parsed
13
13
  new(response.parsed)
@@ -1,3 +1,3 @@
1
1
  module DockHealthApi
2
- VERSION = "0.3.6"
2
+ VERSION = "0.4.1"
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.1
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-12-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: oauth2