Class: AllscriptsUnityClient::JSONClientDriver
- Inherits:
-
ClientDriver
- Object
- ClientDriver
- AllscriptsUnityClient::JSONClientDriver
- Defined in:
- lib/allscripts_unity_client/json_client_driver.rb
Overview
A ClientDriver that supports Unity’s JSON endpoints.
Constant Summary collapse
- UNITY_JSON_ENDPOINT =
'/Unity/UnityService.svc/json'
- UBIQUITY_JSON_ENDPOINT =
'/UnityService.svc/json'
- TOKEN_REGEX =
/^"?(\w|-)+"?$/
Constants inherited from ClientDriver
Instance Attribute Summary collapse
-
#connection ⇒ Object
Returns the value of attribute connection.
-
#json_base_url ⇒ Object
Returns the value of attribute json_base_url.
-
#security_token ⇒ Object
Returns the value of attribute security_token.
Attributes inherited from ClientDriver
Instance Method Summary collapse
- #build_uri(request_location) ⇒ Object
- #client_type ⇒ Object
-
#get_security_token!(parameters = {}) ⇒ Object
See Client#get_security_token!.
-
#get_user_authentication(parameters = {}) ⇒ Object
See Client#get_user_authentication.
-
#initialize(options) ⇒ JSONClientDriver
constructor
A new instance of JSONClientDriver.
- #magic(parameters = {}) ⇒ Object
-
#retire_security_token!(parameters = {}) ⇒ Object
See Client#retire_security_token!.
- #revoke_authentication ⇒ Object
- #set_http_client_ssl_config ⇒ Object
- #set_http_client_timeouts ⇒ Object
- #user_authenticated? ⇒ Boolean
Methods inherited from ClientDriver
Constructor Details
#initialize(options) ⇒ JSONClientDriver
Returns a new instance of JSONClientDriver.
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/allscripts_unity_client/json_client_driver.rb', line 14 def initialize() super @connection = HTTPClient.new( proxy: @options.proxy, default_header: {'Content-Type' => 'application/json'} ) set_http_client_ssl_config set_http_client_timeouts end |
Instance Attribute Details
#connection ⇒ Object
Returns the value of attribute connection.
8 9 10 |
# File 'lib/allscripts_unity_client/json_client_driver.rb', line 8 def connection @connection end |
#json_base_url ⇒ Object
Returns the value of attribute json_base_url.
8 9 10 |
# File 'lib/allscripts_unity_client/json_client_driver.rb', line 8 def json_base_url @json_base_url end |
#security_token ⇒ Object
Returns the value of attribute security_token.
8 9 10 |
# File 'lib/allscripts_unity_client/json_client_driver.rb', line 8 def security_token @security_token end |
Instance Method Details
#build_uri(request_location) ⇒ Object
43 44 45 46 |
# File 'lib/allscripts_unity_client/json_client_driver.rb', line 43 def build_uri(request_location) endpoint = @options.use_ubiquity ? UBIQUITY_JSON_ENDPOINT : UNITY_JSON_ENDPOINT "#{@options.base_unity_url}#{[endpoint, request_location].join('/')}" end |
#client_type ⇒ Object
48 49 50 |
# File 'lib/allscripts_unity_client/json_client_driver.rb', line 48 def client_type :json end |
#get_security_token!(parameters = {}) ⇒ Object
See Client#get_security_token!.
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/allscripts_unity_client/json_client_driver.rb', line 97 def get_security_token!(parameters = {}) username = parameters[:username] || @options.username password = parameters[:password] || @options.password appname = parameters[:appname] || @options.appname request_data = { 'Username' => username, 'Password' => password, 'Appname' => appname } start_timer response = @connection.post(build_uri('GetToken'), MultiJson.dump(request_data.to_hash)) end_timer log_get_security_token log_info("Response Status: #{response.status}") if response.status != 200 || TOKEN_REGEX.match(response.body).nil? raise make_get_security_token_error else raise_if_response_error(response.body) @security_token = response.body end end |
#get_user_authentication(parameters = {}) ⇒ Object
See Client#get_user_authentication.
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/allscripts_unity_client/json_client_driver.rb', line 77 def get_user_authentication(parameters = {}) response = magic({ action: 'GetUserAuthentication', userid: parameters[:ehr_userid] || @options.ehr_userid, parameter1: parameters[:ehr_password] || @options.ehr_password }) if response[:valid_user] == 'YES' @user_authentication = response log_info("allscripts_unity_client authentication attempt: success #{@options.base_unity_url}") return true elsif response[:valid_user] == 'NO' log_warn("allscripts_unity_client authentication attempt: failure #{@options.base_unity_url}") return false else raise StandardError.new('Unexpected response from the server') end end |
#magic(parameters = {}) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/allscripts_unity_client/json_client_driver.rb', line 52 def magic(parameters = {}) request = JSONUnityRequest.new(parameters, @options.timezone, @options.appname, @security_token, @options.raw_dates) request_hash = request.to_hash request_data = MultiJson.dump(request_hash) start_timer response = @connection.post(build_uri('MagicJson'), request_data) end_timer # NOTE: ClientDriver#log_magic uses ClientDriver#log_info, which # appends timing info (if end_timer has been called previously), # and then resets the timer. # # It would be nice if future work made this less stateful. log_magic(request) log_info("Response Status: #{response.status}") response = MultiJson.load(response.body) raise_if_response_error(response) response = JSONUnityResponse.new(response, @options.timezone) response.to_hash end |
#retire_security_token!(parameters = {}) ⇒ Object
See Client#retire_security_token!.
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/allscripts_unity_client/json_client_driver.rb', line 125 def retire_security_token!(parameters = {}) token = parameters[:token] || @security_token appname = parameters[:appname] || @options.appname request_data = { 'Token' => token, 'Appname' => appname } start_timer response = @connection.post(build_uri('RetireSecurityToken'), MultiJson.dump(request_data.to_hash)) end_timer raise_if_response_error(response.body) log_retire_security_token @security_token = nil revoke_authentication end |
#revoke_authentication ⇒ Object
149 150 151 |
# File 'lib/allscripts_unity_client/json_client_driver.rb', line 149 def revoke_authentication @user_authentication = nil end |
#set_http_client_ssl_config ⇒ Object
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/allscripts_unity_client/json_client_driver.rb', line 32 def set_http_client_ssl_config = OpenSSL::SSL::OP_ALL &= ~OpenSSL::SSL::OP_DONT_INSERT_EMPTY_FRAGMENTS if defined?(OpenSSL::SSL::OP_DONT_INSERT_EMPTY_FRAGMENTS) |= OpenSSL::SSL::OP_NO_COMPRESSION if defined?(OpenSSL::SSL::OP_NO_COMPRESSION) |= OpenSSL::SSL::OP_NO_SSLv2 if defined?(OpenSSL::SSL::OP_NO_SSLv2) |= OpenSSL::SSL::OP_NO_SSLv3 if defined?(OpenSSL::SSL::OP_NO_SSLv3) @connection.ssl_config. = @connection.ssl_config.ciphers = "ALL:!aNULL:!eNULL:!SSLv2" end |
#set_http_client_timeouts ⇒ Object
26 27 28 29 30 |
# File 'lib/allscripts_unity_client/json_client_driver.rb', line 26 def set_http_client_timeouts @connection.connect_timeout = @options.timeout || 90 @connection.send_timeout = @options.timeout || 90 @connection.receive_timeout = @options.timeout || 90 end |
#user_authenticated? ⇒ Boolean
145 146 147 |
# File 'lib/allscripts_unity_client/json_client_driver.rb', line 145 def user_authenticated? @user_authentication.present? end |