views:

87

answers:

1

I have a Rails application which uses another Rails application's API trough a WSDL file. I'd like to somehow cache or define as a constant the "handle" to the API which I create like this:

serv = SOAP::WSDLDriverFactory.new(APP_CONFIG['api_url']).create_rpc_driver

Reloading this for all methods which use the API is both slow and not very DRY. The API does not change very often so I would like to just create the "handle" when launching the application and always use the same "handle" for all connections.

How and where do I define this kind of global variable? I know constants can be set in environment.rb but it doesn't seem to work if I try to define this line there, get some kind of timeout error.

A: 

I would suggest using the soap4r utility, wsdl2ruby.rb to generate the soap driver and use it. Soap4r is one of those weird libraries that is in both the Ruby 1.8.6 distribution and available as a gem.

gem install soap4r
wsdl2ruby.rb --help

You will want to do something like this:

wsdl2ruby.rb --wsdl http://your/wsdl/url --type client
ottobar
I like the current setup, it works very well. The only thing I'd like to change, if possible is to skip the reloading of the WSDL on each request. Your suggestion would mean I'd have to re-run wsdl2ruby every time the API changes (and perhaps even change the code to use the API?).
peku