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'
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.
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!.
-
#initialize(options) ⇒ JSONClientDriver
constructor
A new instance of JSONClientDriver.
- #magic(parameters = {}) ⇒ Object
-
#retire_security_token!(parameters = {}) ⇒ Object
See Client#retire_security_token!.
- #set_http_client_ssl_config ⇒ Object
- #set_http_client_timeouts ⇒ Object
Methods inherited from ClientDriver
Constructor Details
#initialize(options) ⇒ JSONClientDriver
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/allscripts_unity_client/json_client_driver.rb', line 12 def initialize() super @connection = HTTPClient.new( proxy: .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 |
Instance Method Details
#build_uri(request_location) ⇒ Object
42 43 44 |
# File 'lib/allscripts_unity_client/json_client_driver.rb', line 42 def build_uri(request_location) "#{@options.base_unity_url}#{[UNITY_JSON_ENDPOINT, request_location].join('/')}" end |
#client_type ⇒ Object
46 47 48 |
# File 'lib/allscripts_unity_client/json_client_driver.rb', line 46 def client_type :json end |
#get_security_token!(parameters = {}) ⇒ Object
See Client#get_security_token!.
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/allscripts_unity_client/json_client_driver.rb', line 67 def get_security_token!(parameters = {}) username = parameters[:username] || .username password = parameters[:password] || .password appname = parameters[:appname] || .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 raise_if_response_error(response.body) log_get_security_token @security_token = response.body end |
#magic(parameters = {}) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/allscripts_unity_client/json_client_driver.rb', line 50 def magic(parameters = {}) request_data = JSONUnityRequest.new(parameters, .timezone, .appname, @security_token) start_timer response = @connection.post(build_uri('MagicJson'), MultiJson.dump(request_data.to_hash)) end_timer response = MultiJson.load(response.body) raise_if_response_error(response) log_magic(request_data) response = JSONUnityResponse.new(response, .timezone) response.to_hash end |
#retire_security_token!(parameters = {}) ⇒ Object
See Client#retire_security_token!.
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/allscripts_unity_client/json_client_driver.rb', line 89 def retire_security_token!(parameters = {}) token = parameters[:token] || @security_token appname = parameters[:appname] || .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 end |
#set_http_client_ssl_config ⇒ Object
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/allscripts_unity_client/json_client_driver.rb', line 31 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
25 26 27 28 29 |
# File 'lib/allscripts_unity_client/json_client_driver.rb', line 25 def set_http_client_timeouts @connection.connect_timeout = .timeout || 90 @connection.send_timeout = .timeout || 90 @connection.receive_timeout = .timeout || 90 end |