Class: AllscriptsUnityClient::SOAPClientDriver

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

Constant Summary collapse

UNITY_SOAP_ENDPOINT =
'/Unity/UnityService.svc/unityservice'
UNITY_ENDPOINT_NAMESPACE =
'http://www.allscripts.com/Unity/IUnityService'

Constants inherited from ClientDriver

ClientDriver::LOG_FILE

Instance Attribute Summary collapse

Attributes inherited from ClientDriver

#options, #security_token

Instance Method Summary collapse

Methods inherited from ClientDriver

#security_token?

Constructor Details

#initialize(options) ⇒ SOAPClientDriver

Returns a new instance of SOAPClientDriver.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/allscripts_unity_client/soap_client_driver.rb', line 10

def initialize(options)
  super

  client_proxy = @options.proxy
  base_unity_url = "#{@options.base_unity_url}#{UNITY_SOAP_ENDPOINT}"

  @savon_client = Savon.client do
    # Removes the wsdl: namespace from body elements in the SOAP
    # request. Unity doesn't recognize elements otherwise.
    namespace_identifier nil

    # Manually registers SOAP endpoint since Unity WSDL is not very
    # good.
    endpoint base_unity_url

    # Manually register SOAP namespace. This URL isn't live, but the
    # internal SOAP endpoints expect it.
    namespace 'http://www.allscripts.com/Unity'

    # Register proxy with Savon if one was given.
    unless client_proxy.nil?
      proxy client_proxy
    end

    # Unity expects the SOAP envelop to be namespaced with soap:
    env_namespace :soap

    # Unity uses Microsoft style CamelCase for keys. Only really useful when using
    # symbol keyed hashes.
    convert_request_keys_to :camelcase

    # Enable gzip on HTTP responses. Unity does not currently support this
    # as of Born On 10/7/2013, but it doesn't hurt to future-proof. If gzip
    # is ever enabled, this library will get a speed bump for free.
    headers({ 'Accept-Encoding' => 'gzip,deflate'})

    # Disable Savon logs
    log false
  end
end

Instance Attribute Details

#savon_clientObject

Returns the value of attribute savon_client.



5
6
7
# File 'lib/allscripts_unity_client/soap_client_driver.rb', line 5

def savon_client
  @savon_client
end

Instance Method Details

#client_typeObject



51
52
53
# File 'lib/allscripts_unity_client/soap_client_driver.rb', line 51

def client_type
  :soap
end

#get_security_token!(parameters = {}) ⇒ Object



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
104
105
106
107
# File 'lib/allscripts_unity_client/soap_client_driver.rb', line 79

def get_security_token!(parameters = {})
  username = parameters[:username] || @options.username
  password = parameters[:password] || @options.password
  appname = parameters[:appname] || @options.appname

  call_data = {
    message: {
      'Username' => username,
      'Password' => password,
      'Appname' => appname
    },
    soap_action: "#{UNITY_ENDPOINT_NAMESPACE}/GetSecurityToken"
  }

  begin
    start_timer
    response = nil
    NewRelicSupport.trace_execution_scoped_if_available(self.class, ["Custom/UnitySOAP/GetToken"]) do
      response = @savon_client.call('GetSecurityToken', call_data)
      end_timer
    end
  rescue Savon::SOAPFault => e
    raise APIError, e.message
  end

  log_get_security_token

  @security_token = response.body[:get_security_token_response][:get_security_token_result]
end

#magic(parameters = {}) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/allscripts_unity_client/soap_client_driver.rb', line 55

def magic(parameters = {})
  request_data = UnityRequest.new(parameters, @options.timezone, @options.appname, @security_token)
  call_data = {
    message: request_data.to_hash,
    soap_action: "#{UNITY_ENDPOINT_NAMESPACE}/Magic"
  }

  response = nil
  begin
    start_timer
    NewRelicSupport.trace_execution_scoped_if_available(self.class, ["Custom/UnitySOAP/#{parameters[:action]}"]) do
      response = @savon_client.call('Magic', call_data)
      end_timer
    end
  rescue Savon::SOAPFault => e
    raise APIError, e.message
  end

  log_magic(request_data)

  response = UnityResponse.new(response.body, @options.timezone)
  response.to_hash
end

#retire_security_token!(parameters = {}) ⇒ Object



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/allscripts_unity_client/soap_client_driver.rb', line 109

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

  call_data = {
    message: {
      'Token' => token,
      'Appname' => appname
    },
    soap_action: "#{UNITY_ENDPOINT_NAMESPACE}/RetireSecurityToken"
  }

  begin
    start_timer
    NewRelicSupport.trace_execution_scoped_if_available(self.class, ["Custom/UnitySOAP/RetireSecurityToken"]) do
      @savon_client.call('RetireSecurityToken', call_data)
      end_timer
    end
  rescue Savon::SOAPFault => e
    raise APIError, e.message
  end

  log_retire_security_token

  @security_token = nil
end