Ruby question

Cole Tuininga colet at code-energy.com
Fri Oct 2 09:14:35 EDT 2009


Hey folks - I'm working on a short term project that requires me to use
Ruby, so I spent some time with the O'Reilly "Learning Ruby" book.  Now
I'm stuck though, and so far my Google-fu has proved inadequate.  As I
know we have a number of Rubyists on the list, I thought I might try
asking here.  :)

I'm having to make use of the Ruby built in SOAP lib (via
SOAP::RPC::Driver), and I should start off by making mention that there
is currently no WSDL available for the SOAP interface I'm trying to talk
to.  The responses to my SOAP calls are hashes, and therein lies the
problem.

When I make the SOAP call,

response = soap_driver.SOAPFunction(args)

the response var gets turned into a SOAP::Mapping::Object.  If I knew
for sure what keys I was going to be getting in return, this would be
fine.  I could just access each value like: response[key]

The problem is that I don't know what keys are going to be returned.
And because the returned object doesn't support methods like each, keys,
or values I had to put together a hack to get the list of keys.  I did
it a little something like this:

# Filter out methods that are normally part of a mapping object
keys = response.methods - SOAP::MAPPING::Object.instance_methods

# Filter out setter methods
keys = keys.grep(/[^=]$/)

Now, at this point I can go through the remaining keys easily enough.
The thing is that this seems like an awfully hackish approach.  I'm
assuming that there's an easier/more elegant way and that I'm just not
aware of it because of my newbie position.  Can anybody offer a way to
put together the keys in a cleaner manner?

Note, I do not have the option of setting up WSDL, nor can I use soap4r.

Thanks in advance, and let me know if I'm not providing enough
information here.

-- 
Cole Tuininga
Lead Developer
colet at code-energy.com


More information about the gnhlug-discuss mailing list