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
-
#response ⇒ Object
readonly
Returns the value of attribute response.
-
#wsdl ⇒ Object
readonly
Returns the value of attribute wsdl.
Class Method Summary collapse
Instance Method Summary collapse
-
#body ⇒ Object
Return the body of the message as a Hash.
-
#connected? ⇒ Boolean
Returns true if the service has established communication with the remote server.
-
#doc ⇒ Object
Return the response as a Nokogiri document.
- #initialize ⇒ Object
-
#operations ⇒ Object
Returns an array of operations that can be called on the remote service.
-
#to_hash ⇒ Object
Return the response as a Hash.
-
#to_xml ⇒ Object
Return the xml response.
-
#xpath(path) ⇒ Object
Return value at xpath.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(*args) ⇒ Object (private)
99 100 101 102 103 104 |
# File 'lib/soap-object.rb', line 99 def method_missing(*args) operation =args.shift = args.shift type = .is_a?(String) ? :xml : :message call(operation, {type => }) end |
Instance Attribute Details
#response ⇒ Object (readonly)
Returns the value of attribute response.
36 37 38 |
# File 'lib/soap-object.rb', line 36 def response @response end |
#wsdl ⇒ Object (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
#body ⇒ Object
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.
50 51 52 |
# File 'lib/soap-object.rb', line 50 def connected? not @client.nil? end |
#doc ⇒ Object
Return the response as a Nokogiri document
93 94 95 |
# File 'lib/soap-object.rb', line 93 def doc response.doc end |
#initialize ⇒ Object
38 39 40 |
# File 'lib/soap-object.rb', line 38 def initialize @client = Savon.client(client_properties) end |
#operations ⇒ Object
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_hash ⇒ Object
Return the response as a Hash
79 80 81 |
# File 'lib/soap-object.rb', line 79 def to_hash response.hash end |
#to_xml ⇒ Object
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 |