Created
February 14, 2011 14:41
-
-
Save georgkreimer/825959 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# extensions | |
# … | |
module SOAPArray | |
def to_soap_array(item_name = "messageId") | |
result=Array.new | |
self.each do |val| | |
result.push({item_name => val.to_i}) | |
end | |
result | |
end | |
end | |
Array.send :include, SOAPArray | |
# … | |
# client | |
class Client | |
# … | |
def get_messages | |
do_request("GetMessagesRequest").message.presence || Hashie::Mash.new | |
end | |
def received_messages(ids) | |
do_request "ReceivedMessagesRequest", ids.to_soap_array | |
end | |
private | |
def do_request(method, body = nil) | |
response_hash = @client.request(:wsdl, method) do | |
soap.body = body | |
end.to_hash | |
Hashie::Mash.new(response_hash) | |
end | |
end | |
client = Client.new | |
client.received_messages([14,2,3]) | |
# produces XML like this: | |
# <?xml version="1.0" encoding="UTF-8"?> | |
# <env:Envelope xmlns:wsdl="somewebserviceprovider.de" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"> | |
# <env:Body> | |
# <wsdl:ReceivedMessagesRequest>messageId14messageId2messageId3</wsdl:ReceivedMessagesRequest> | |
# </env:Body> | |
#</env:Envelope> | |
# correct XML should be: | |
# <?xml version="1.0" encoding="UTF-8"?> | |
# <env:Envelope xmlns:wsdl="somewebserviceprovider.de" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"> | |
# <env:Body> | |
# <wsdl:ReceivedMessagesRequest> | |
# <messageId>14</messageId> | |
# <messageId>2</messageId> | |
# <messageId>3</messageId> | |
# </wsdl:ReceivedMessagesRequest> | |
# </env:Body> | |
# </env:Envelope> |
works perfect, thx for your help.
you're welcome. btw. if you're only using using the body
method inside the request
block, you could also use a somewhat "secret" little shortcut: https://github.com/rubiii/savon/blob/v0.8.5/lib/savon/client.rb#L112
client.request :wsdl, "ReceivedMessagesRequest", :body => { :message_id => [14, 2, 3] }
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
there you go: