Class: AllscriptsUnityClient::JSONClientDriver

Inherits:
ClientDriver
  • Object
show all
Defined in:
lib/allscripts_unity_client/json_client_driver.rb

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

#appname, #base_unity_url, #log, #logger, #password, #proxy, #security_token, #timezone, #username

Instance Method Summary collapse

Methods inherited from ClientDriver

#log?, #security_token?

Constructor Details

#initialize(base_unity_url, username, password, appname, proxy = nil, timezone = nil, logger = nil, log = true) ⇒ JSONClientDriver

Returns a new instance of JSONClientDriver.



10
11
12
13
14
15
16
17
# File 'lib/allscripts_unity_client/json_client_driver.rb', line 10

def initialize(base_unity_url, username, password, appname, proxy = nil, timezone = nil, logger = nil, log = true)
  super

  # Disable HTTPI logging
  HTTPI.log = false

  @json_base_url = "#{@base_unity_url}#{UNITY_JSON_ENDPOINT}"
end

Instance Attribute Details

#json_base_urlObject

Returns the value of attribute json_base_url.



6
7
8
# File 'lib/allscripts_unity_client/json_client_driver.rb', line 6

def json_base_url
  @json_base_url
end

Instance Method Details

#client_typeObject



19
20
21
# File 'lib/allscripts_unity_client/json_client_driver.rb', line 19

def client_type
  return :json
end

#get_security_token!(parameters = {}) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/allscripts_unity_client/json_client_driver.rb', line 40

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
  }
  request = create_httpi_request("#{@json_base_url}/GetToken", request_data)

  start_timer
  response = HTTPI.post(request, :net_http_persistent)
  end_timer

  raise_if_response_error(response.body)
  log_get_security_token

  @security_token = response.body
end

#magic(parameters = {}) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/allscripts_unity_client/json_client_driver.rb', line 23

def magic(parameters = {})
  request_data = JSONUnityRequest.new(parameters, @timezone, @appname, @security_token)
  request = create_httpi_request("#{@json_base_url}/MagicJson", request_data.to_hash)

  start_timer
  response = HTTPI.post(request)
  end_timer

  response = JSON.parse(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



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/allscripts_unity_client/json_client_driver.rb', line 62

def retire_security_token!(parameters = {})
  token = parameters[:token] || @security_token
  appname = parameters[:appname] || @appname

  request_data = {
    "Token" => token,
    "Appname" => appname
  }
  request = create_httpi_request("#{@json_base_url}/RetireSecurityToken", request_data)

  start_timer
  response = HTTPI.post(request, :net_http_persistent)
  end_timer

  raise_if_response_error(response.body)
  log_retire_security_token

  @security_token = nil
end