Class: SoapClient
- Inherits:
-
Object
- Object
- SoapClient
- Defined in:
- lib/clearconnect/soap_client.rb
Instance Method Summary collapse
-
#generic_request(message) ⇒ Object
Encodes request, packages into required node, sends, decodes response.
-
#initialize(username, password, session) ⇒ SoapClient
constructor
A new instance of SoapClient.
-
#post_request(query) ⇒ Object
Takes a query of format { :key => ‘value’ } where :key is the properly formatted parameter and ‘value’ is the string value Parameters can be nested like so: { :tempRecords => { :tempRecord => [ { :key1 = ‘value1’, :key2 => ‘value2’ }, { :key1 => ‘value3’ } ] } } will produce <tempRecords><tempRecord><key1>value1</key1><key2>value2</key2></tempRecord><tempRecord><key1>value3</key1></tempRecord></tempRecords>.
- #xml_decode(xml_string) ⇒ Object
- #xml_encode(xml_string) ⇒ Object
Constructor Details
#initialize(username, password, session) ⇒ SoapClient
Returns a new instance of SoapClient.
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/clearconnect/soap_client.rb', line 2 def initialize(username, password, session) wsdl = HTTParty.get(ClearConnect.configuration.endpoints[:wsdl], :format => 'xml').parsed_response @client = Savon::Client.new( wsdl: wsdl, log_level: :info ) @username = username @password = password @session = session @default_params = { :username => username, :password => password, :resultType => ClearConnect.configuration.format.to_s } end |
Instance Method Details
#generic_request(message) ⇒ Object
Encodes request, packages into required node, sends, decodes response
19 20 21 22 23 24 25 |
# File 'lib/clearconnect/soap_client.rb', line 19 def generic_request() request = "<requestXmlString>#{xml_encode()}</requestXmlString>" response = @client.call(:tss_request, message: request) # :tss_request_response => {:tss_request_return => [ugly value to be decoded]} # response.body JSON.parse(response.body[:tss_request_response][:tss_request_return])[0] end |
#post_request(query) ⇒ Object
Takes a query of format { :key => ‘value’ } where :key is the properly formatted parameter and ‘value’ is the string value Parameters can be nested like so: { :tempRecords => { :tempRecord => [ { :key1 = ‘value1’, :key2 => ‘value2’ }, { :key1 => ‘value3’ } ] } } will produce <tempRecords><tempRecord><key1>value1</key1><key2>value2</key2></tempRecord><tempRecord><key1>value3</key1></tempRecord></tempRecords>
30 31 32 33 34 |
# File 'lib/clearconnect/soap_client.rb', line 30 def post_request(query) params = @default_params.merge(query) post_data = XmlSimple.xml_out(params, RootName: 'clearviewRequest', NoAttr: true) generic_request(post_data) end |
#xml_decode(xml_string) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/clearconnect/soap_client.rb', line 54 def xml_decode(xml_string) string = xml_string characters = [ { replacement: '&', find: '&' }, { replacement: '"', find: '"' }, { replacement: '<', find: '<' }, { replacement: '>', find: '>' }, { replacement: "'", find: ''' } ] characters.each do |set| new_string = string.gsub(set[:find], set[:replacement]) if not new_string.nil? string = new_string end end return string end |
#xml_encode(xml_string) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/clearconnect/soap_client.rb', line 36 def xml_encode(xml_string) string = xml_string characters = [ { find: '&', replacement: '&' }, { find: '"', replacement: '"' }, { find: '<', replacement: '<' }, { find: '>', replacement: '>' }, { find: "'", replacement: ''' } ] characters.each do |set| new_string = string.gsub(set[:find], set[:replacement]) if not new_string.nil? string = new_string end end return string end |