Module: SoapObject

Defined in:
lib/soap-object.rb,
lib/soap-object/factory.rb,
lib/soap-object/class_methods.rb

Overview

module to make it simpler to tests SOAP web services. The goal is to abstract all information about how your call and parse results from the web service within the soap objects.

class ZipCodeService

include SoapObject

wsdl 'http://www.webservicex.net/uszip.asmx?WSDL'

def get_zipcode_info(zip_code)
  get_info_by_zip 'USZip' => zip_code
end

def state
  message[:state]
end

message
  response.body[:get_info_by_zip_response][:get_info_by_zip_result][:new_data_set][:table]
end

end

There are many additional properties that can be set to configure the service calls. See the comments for SoapObject::ClassMethods to view all of the options.

Defined Under Namespace

Modules: ClassMethods, Factory

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(*args) ⇒ Object (private)



102
103
104
105
106
107
# File 'lib/soap-object.rb', line 102

def method_missing(*args)
  operation =args.shift
  message = args.shift
  type = message.is_a?(String) ? :xml : :message
  call(operation, {type => message})
end

Instance Attribute Details

#responseObject (readonly)

Returns the value of attribute response.



36
37
38
# File 'lib/soap-object.rb', line 36

def response
  @response
end

#wsdlObject (readonly)

Returns the value of attribute wsdl.



36
37
38
# File 'lib/soap-object.rb', line 36

def wsdl
  @wsdl
end

Class Method Details

.included(cls) ⇒ Object



42
43
44
# File 'lib/soap-object.rb', line 42

def self.included(cls)
  cls.extend SoapObject::ClassMethods
end

Instance Method Details

#bodyObject

Return the body of the message as a Hash



86
87
88
# File 'lib/soap-object.rb', line 86

def body
  response.body
end

#connected?Boolean

Returns true if the service has established communication with the remote server.

Returns:

  • (Boolean)


50
51
52
# File 'lib/soap-object.rb', line 50

def connected?
  not @client.nil?
end

#docObject

Return the response as a Nokogiri document



93
94
95
# File 'lib/soap-object.rb', line 93

def doc
  response.doc
end

#initializeObject



38
39
40
# File 'lib/soap-object.rb', line 38

def initialize
  @client = Savon.client(client_properties)
end

#operationsObject

Returns an array of operations that can be called on the remote service.



58
59
60
# File 'lib/soap-object.rb', line 58

def operations
  @client.operations
end

#to_hashObject

Return the response as a Hash



79
80
81
# File 'lib/soap-object.rb', line 79

def to_hash
  response.hash
end

#to_xmlObject

Return the xml response



65
66
67
# File 'lib/soap-object.rb', line 65

def to_xml
  response.to_xml
end

#xpath(path) ⇒ Object

Return value at xpath



72
73
74
# File 'lib/soap-object.rb', line 72

def xpath(path)
  response.xpath(path)
end