@rubiii has previously shown (Savon soap body problem) that you can customize Savon requests with
class SomeXML
def self.to_s
"<some>xml</some>"
end
end
client.request :some_action do
soap.body = SomeXML
end
But why would you use a class method like this? It would seem more likely that you would ask an instance of a class to turn itself into a hash for the request body. i.e.
@instance = SomeClass.new
client.request :some_action do
soap.body = @instance.to_soap
end
However, when I try doing this, @instance variable isn't in 'scope' within the request block. So I get a can't call method to_soap on nil. But if instead I use a class method then I can get it to work. i.e.
class SomeClass
@@soap_hash = nil
def self.soap_hash=(hash)
@@soap_hash = hash
end
def self.soap_hash
@@soap_hash
end
end
SomeClass.soap_hash = @instance.to_soap
client.request :some_action do
soap.body = SomeClass.soap_hash
end
I don't get it?