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
17
18
19
20
|
# File 'lib/allscripts_unity_client/json_client_driver.rb', line 11
def initialize(options)
super
@connection = Faraday.new(url: @options.base_unity_url) do |conn|
if @options.proxy?
conn.proxy @options.proxy
end
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
22
23
24
|
# File 'lib/allscripts_unity_client/json_client_driver.rb', line 22
def client_type
:json
end
|
#get_security_token!(parameters = {}) ⇒ Object
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
# File 'lib/allscripts_unity_client/json_client_driver.rb', line 46
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 = @connection.post do |request|
request.url "#{UNITY_JSON_ENDPOINT}/GetToken"
request.['Content-Type'] = 'application/json'
request.body = JSON.generate(request_data)
start_timer
end
end_timer
raise_if_response_error(response.body)
log_get_security_token
@security_token = response.body
end
|
#magic(parameters = {}) ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/allscripts_unity_client/json_client_driver.rb', line 26
def magic(parameters = {})
request_data = JSONUnityRequest.new(parameters, @options.timezone, @options.appname, @security_token)
response = @connection.post do |request|
request.url "#{UNITY_JSON_ENDPOINT}/MagicJson"
request.['Content-Type'] = 'application/json'
request.body = JSON.generate(request_data.to_hash)
start_timer
end
end_timer
response = JSON.parse(response.body)
raise_if_response_error(response)
log_magic(request_data)
response = JSONUnityResponse.new(response, @options.timezone)
response.to_hash
end
|
#retire_security_token!(parameters = {}) ⇒ Object
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
# File 'lib/allscripts_unity_client/json_client_driver.rb', line 71
def retire_security_token!(parameters = {})
token = parameters[:token] || @security_token
appname = parameters[:appname] || @options.appname
request_data = {
'Token' => token,
'Appname' => appname
}
response = @connection.post do |request|
request.url "#{UNITY_JSON_ENDPOINT}/RetireSecurityToken"
request.['Content-Type'] = 'application/json'
request.body = JSON.generate(request_data)
start_timer
end
end_timer
raise_if_response_error(response.body)
log_retire_security_token
@security_token = nil
end
|