Module: Kraut::Client
- Defined in:
- lib/kraut/client.rb
Overview
Kraut::Client
Wraps a Savon::Client
and executes SOAP requests.
Class Method Summary collapse
-
.auth_request(method, body = {}) ⇒ Object
Executes a SOAP request to a given
method
with an optionalbody
Hash. -
.client ⇒ Object
Returns a memoized
Savon::Client
for executing SOAP requests. -
.request(method, body = {}) ⇒ Object
Executes a SOAP request to a given
method
with an optionalbody
Hash.
Class Method Details
.auth_request(method, body = {}) ⇒ Object
Executes a SOAP request to a given method
with an optional body
Hash. Adds application authentication credentials and delegates to the request
method.
33 34 35 36 37 |
# File 'lib/kraut/client.rb', line 33 def auth_request(method, body = {}) body[:in0] = { "aut:name" => Application.name, "aut:token" => Application.token } body[:order!] = body.keys.sort_by { |key| key.to_s } request method, body end |
.client ⇒ Object
Returns a memoized Savon::Client
for executing SOAP requests.
40 41 42 43 44 45 |
# File 'lib/kraut/client.rb', line 40 def client @client ||= Savon::Client.new do wsdl.endpoint = Kraut.endpoint wsdl.namespace = "urn:SecurityServer" end end |
.request(method, body = {}) ⇒ Object
Executes a SOAP request to a given method
with an optional body
Hash. Ensures to always raise SOAP faults if they happen and returns a response Hash.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/kraut/client.rb', line 16 def request(method, body = {}) response = client.request :wsdl, method do soap.namespaces["xmlns:aut"] = Kraut.namespace soap.body = body end if response.soap_fault? handle_soap_fault response.soap_fault else response.to_hash["#{method}_response".to_sym] end rescue Savon::SOAP::Fault => soap_fault handle_soap_fault soap_fault end |