Search code examples
rubysoap4r

Webservice with a method named "type". How to consume it using ruby?


I am consuming a web service using ruby (1.8.7) and soap4r (1.5.8). The web service has a method named "type" and I am not able to get the value.

@driver=SOAP::WSDLDriverFactory.new(WSDL_URL).create_rpc_driver
result = @driver.GetJob(:jobid => "123")
puts "jobname is #{result.name}"
puts "jobtype is #{result.type}"

The fourth line gives me "warning: Object#type is deprecated; use Object#class". I know that Object.type is deprecated. I want to call the "type" method of the result obtained from the web service. I don't own the web service so I can't change it.

Any help appreciated. Thanks in advance.


Solution

  • The type method is probably invoked using method_missing and when the method exists on Object this mechanism doesn't work. If so this little piece of monkey patching gets rid of Object.type:

    class Object
      undef_method :type
    end
    

    Put this code somewhere before the call to the web service and it should work.

    Another way to solve it is upgrading to ruby 1.9. The type method is gone!