Class: AllscriptsUnityClient::JSONClientDriver
Constant Summary
collapse
- UNITY_JSON_ENDPOINT =
'/Unity/UnityService.svc/json'
Constants inherited
from ClientDriver
ClientDriver::LOG_FILE
Instance Attribute Summary collapse
Attributes inherited from ClientDriver
#options, #security_token
Instance Method Summary
collapse
#security_token?
Constructor Details
Returns a new instance of JSONClientDriver.
11
12
13
14
15
16
|
# File 'lib/allscripts_unity_client/json_client_driver.rb', line 11
def initialize(options)
super
@connection = Faraday.new(build_faraday_options) do |conn|
conn.adapter :em_http
end
end
|
Instance Attribute Details
#connection ⇒ Object
Returns the value of attribute connection.
7
8
9
|
# File 'lib/allscripts_unity_client/json_client_driver.rb', line 7
def connection
@connection
end
|
#json_base_url ⇒ Object
Returns the value of attribute json_base_url.
7
8
9
|
# File 'lib/allscripts_unity_client/json_client_driver.rb', line 7
def json_base_url
@json_base_url
end
|
Instance Method Details
#client_type ⇒ Object
18
19
20
|
# File 'lib/allscripts_unity_client/json_client_driver.rb', line 18
def client_type
:json
end
|
#get_security_token!(parameters = {}) ⇒ Object
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
# File 'lib/allscripts_unity_client/json_client_driver.rb', line 47
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
}
response = nil
NewRelicSupport.trace_execution_scoped_if_available(self.class, ["Custom/UnityJSON/GetToken"]) do
response = @connection.post do |request|
request.url "#{UNITY_JSON_ENDPOINT}/GetToken"
request.['Content-Type'] = 'application/json'
request.body = Oj.dump(request_data, mode: :compat)
set_request_timeout(request)
start_timer
end
end_timer
end
raise_if_response_error(response.body)
log_get_security_token
@security_token = response.body
end
|
#magic(parameters = {}) ⇒ Object
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/allscripts_unity_client/json_client_driver.rb', line 22
def magic(parameters = {})
request_data = JSONUnityRequest.new(parameters, @options.timezone, @options.appname, @security_token)
response = nil
NewRelicSupport.trace_execution_scoped_if_available(self.class, ["Custom/UnityJSON/#{parameters[:action]}"]) do
response = @connection.post do |request|
request.url "#{UNITY_JSON_ENDPOINT}/MagicJson"
request.['Content-Type'] = 'application/json'
request.body = Oj.dump(request_data.to_hash, mode: :compat)
set_request_timeout(request)
start_timer
end
end_timer
end
response = Oj.load(response.body, mode: :strict)
raise_if_response_error(response)
log_magic(request_data)
response = JSONUnityResponse.new(response, @options.timezone)
response.to_hash
end
|
#retire_security_token!(parameters = {}) ⇒ Object
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
# File 'lib/allscripts_unity_client/json_client_driver.rb', line 77
def retire_security_token!(parameters = {})
token = parameters[:token] || @security_token
appname = parameters[:appname] || @options.appname
request_data = {
'Token' => token,
'Appname' => appname
}
response = nil
NewRelicSupport.trace_execution_scoped_if_available(self.class, ["Custom/UnityJSON/RetireSecurityToken"]) do
response = @connection.post do |request|
request.url "#{UNITY_JSON_ENDPOINT}/RetireSecurityToken"
request.['Content-Type'] = 'application/json'
request.body = Oj.dump(request_data, mode: :compat)
set_request_timeout(request)
start_timer
end
end_timer
end
raise_if_response_error(response.body)
log_retire_security_token
@security_token = nil
end
|