Class: DockHealthApi::Client
- Inherits:
-
Object
- Object
- DockHealthApi::Client
- Includes:
- Singleton
- Defined in:
- lib/dock_health_api/client.rb
Constant Summary collapse
- BUFFER =
120
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
- #connection ⇒ Object
- #get_iframe_token ⇒ Object
- #get_token ⇒ Object
- #iframe_token ⇒ Object
- #iframe_token_about_to_expire? ⇒ Boolean
- #iframe_token_connection ⇒ Object
- #iframe_token_expiration_time ⇒ Object
-
#initialize ⇒ Client
constructor
A new instance of Client.
- #token ⇒ Object
- #token_about_to_expire? ⇒ Boolean
- #token_connection ⇒ Object
- #token_expiration_time ⇒ Object
Constructor Details
#initialize ⇒ Client
Returns a new instance of Client.
12 13 14 |
# File 'lib/dock_health_api/client.rb', line 12 def initialize @config = DockHealthApi.config end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
10 11 12 |
# File 'lib/dock_health_api/client.rb', line 10 def config @config end |
Instance Method Details
#connection ⇒ Object
16 17 18 |
# File 'lib/dock_health_api/client.rb', line 16 def connection @connection ||= OAuth2::Client.new(config.api_key, config.api_secret, token_url: config.token_url, raise_errors: false) end |
#get_iframe_token ⇒ Object
60 61 62 63 64 65 |
# File 'lib/dock_health_api/client.rb', line 60 def get_iframe_token @iframe_token_connection = connection.client_credentials.get_token(scope:"dockhealth/system.embedded.launch") return @iframe_token_connection if @iframe_token_connection.nil? @iframe_token_expiration_time = Time.now + @iframe_token_connection.expires_in @iframe_token_connection end |
#get_token ⇒ Object
54 55 56 57 58 |
# File 'lib/dock_health_api/client.rb', line 54 def get_token @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") @token_expiration_time = Time.now + @token_connection.expires_in @token_connection end |
#iframe_token ⇒ Object
50 51 52 |
# File 'lib/dock_health_api/client.rb', line 50 def iframe_token @iframe_token ||= iframe_token_connection.token end |
#iframe_token_about_to_expire? ⇒ Boolean
42 43 44 |
# File 'lib/dock_health_api/client.rb', line 42 def iframe_token_about_to_expire? Time.now + BUFFER > iframe_token_expiration_time end |
#iframe_token_connection ⇒ Object
33 34 35 36 |
# File 'lib/dock_health_api/client.rb', line 33 def iframe_token_connection get_iframe_token if @iframe_token_connection.nil? || iframe_token_about_to_expire? @iframe_token_connection end |
#iframe_token_expiration_time ⇒ Object
38 39 40 |
# File 'lib/dock_health_api/client.rb', line 38 def iframe_token_expiration_time @iframe_token_expiration_time ||= Time.now + @iframe_token_connection.expires_in end |
#token ⇒ Object
46 47 48 |
# File 'lib/dock_health_api/client.rb', line 46 def token @token ||= token_connection.token end |
#token_about_to_expire? ⇒ Boolean
29 30 31 |
# File 'lib/dock_health_api/client.rb', line 29 def token_about_to_expire? Time.now + BUFFER > token_expiration_time end |
#token_connection ⇒ Object
20 21 22 23 |
# File 'lib/dock_health_api/client.rb', line 20 def token_connection get_token if @token_connection.nil? || token_about_to_expire? @token_connection end |
#token_expiration_time ⇒ Object
25 26 27 |
# File 'lib/dock_health_api/client.rb', line 25 def token_expiration_time @token_expiration_time ||= Time.now + @token_connection.expires_in end |