class AllscriptsUnityClient::JSONClientDriver
A ClientDriver
that supports Unity’s JSON endpoints.
Constants
- TOKEN_REGEX
- UBIQUITY_JSON_ENDPOINT
- UNITY_JSON_ENDPOINT
Attributes
Public Class Methods
Source
# File lib/allscripts_unity_client/json_client_driver.rb, line 14 def initialize(options) super @connection = Faraday.new do |conn| conn.request :json conn.adapter Faraday.default_adapter conn.options.timeout = @options.timeout || 90 conn.options.open_timeout = @options.timeout || 90 conn.proxy = @options.proxy if @options.proxy end @text_connection = Faraday.new do |conn| conn.request :json conn.adapter Faraday.default_adapter conn.options.timeout = @options.timeout || 90 conn.options.open_timeout = @options.timeout || 90 conn.proxy = @options.proxy if @options.proxy end end
Calls superclass method
AllscriptsUnityClient::ClientDriver::new
Public Instance Methods
Source
# File lib/allscripts_unity_client/json_client_driver.rb, line 34 def build_uri(request_location) endpoint = @options.use_ubiquity ? UBIQUITY_JSON_ENDPOINT : UNITY_JSON_ENDPOINT "#{@options.base_unity_url}#{[endpoint, request_location].join('/')}" end
Source
# File lib/allscripts_unity_client/json_client_driver.rb, line 39 def client_type :json end
Source
# File lib/allscripts_unity_client/json_client_driver.rb, line 88 def get_security_token!(parameters = {}) username = get_username(parameters) password = parameters[:password] || @options.password appname = parameters[:appname] || @options.appname request_data = { 'Username' => username, 'Password' => password, 'Appname' => appname } start_timer response = @text_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
Source
# File lib/allscripts_unity_client/json_client_driver.rb, line 68 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
Source
# File lib/allscripts_unity_client/json_client_driver.rb, line 43 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
Source
# File lib/allscripts_unity_client/json_client_driver.rb, line 116 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
Source
# File lib/allscripts_unity_client/json_client_driver.rb, line 141 def revoke_authentication @user_authentication = nil end
Source
# File lib/allscripts_unity_client/json_client_driver.rb, line 136 def user_authenticated? return false if @user_authentication.nil? @user_authentication.is_a?(Hash) && !@user_authentication.empty? end
Private Instance Methods
Source
# File lib/allscripts_unity_client/json_client_driver.rb, line 165 def get_username(parameters = {}) username = parameters[:username] || @options.username if @options.use_ubiquity username = "#{@options.ubiquity_id}:#{username}" end username end
Source
# File lib/allscripts_unity_client/json_client_driver.rb, line 155 def raise_if_response_error(response) if response.nil? raise APIError, 'Response was empty' elsif response.is_a?(Array) && !response[0].nil? && !response[0]['Error'].nil? raise APIError, response[0]['Error'] elsif response.is_a?(String) && response.include?('error:') raise APIError, response end end
@param [Array,String,nil] response
@return [nil]
@todo This method should be responsible creating an ‘APIError` not raising it. The sender should be responsible for raising the error so the stack trace starts in the method where the failure occured.