# Currency conversion webservice in a rails app?

**URL:** <https://www.ruby-forum.com/t/currency-conversion-webservice-in-a-rails-app/55577>\
**Category:** Rails\
**Created:** [March 22, 2006, 7:14am UTC](https://www.ruby-forum.com/t/currency-conversion-webservice-in-a-rails-app/55577 "2006-03-22T07:14:22Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![dracos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ea666f/32.png) [@dracos](https://www.ruby-forum.com/u/dracos)\
**Post date:** [March 22, 2006, 7:14am UTC](https://www.ruby-forum.com/t/currency-conversion-webservice-in-a-rails-app/55577/1 "2006-03-22T07:14:22Z")

</div>

Hi,

I’m interested in using a currency conversion web service in my rails  
app. Does anyone have a free service that they use and like? I found  
this one

[http://www.webservicex.net/WS/WSDetails.aspx?CATID=2&WSID=10](http://www.webservicex.net/WS/WSDetails.aspx?CATID=2&WSID=10)

I’ve tried to make a simple, plain Ruby script to connect to this and  
get a conversion rate without success.

How do I integrate a webservice into my rails app? I have looked in  
the Agile Rails book but can only see a tiny bit about this at the end  
of the web services chapter.

All help greatly appreciated.

Thanks,  
Peter

---

<div class="post-metadata">

**Author:** ![dracos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ea666f/32.png) [@dracos](https://www.ruby-forum.com/u/dracos)\
**Post date:** [March 22, 2006, 6:50pm UTC](https://www.ruby-forum.com/t/currency-conversion-webservice-in-a-rails-app/55577/2 "2006-03-22T18:50:39Z")

</div>

Hi,

> I’m interested in using a currency conversion web service in my rails app.

I’m struggling trying to figure out how to use a webservice and due to  
the small amount of documention I’ve found I stressing that I won’t  
get it working. I have tried the following but I get “undefined method  
`web\_client\_api’ for #StoreController:0x26a37f8”. I looked in my  
environment config files and the actionwebservice package is not being  
skipped as far as I can tell. (In fact I’ve used it to create a web  
service server so it must be working.)

I have no real idea how to set these few lines of code up and would  
really appreciate some pointers.

Feeling a little let down by page 438 in the Agile Rails book,  
Peter

# in my controller

def conversion  
#con = ActionWebService::Client::Soap.new(WhatGoesHere?,  
“[http://www.webserviceX.NET/ConversionRate](http://www.webserviceX.NET/ConversionRate)”)  
#web\_client\_api :con, :soap,  
“[http://www.webservicex.net/CurrencyConvertor.asmx?WSDL](http://www.webservicex.net/CurrencyConvertor.asmx?WSDL)”  
web\_client\_api :con, :soap,  
“[http://www.webserviceX.NET/ConversionRate](http://www.webserviceX.NET/ConversionRate)”

```
con.ConversionRate("CND", "USD")
@rate = con

```

end

---

<div class="post-metadata">

**Author:** ![dracos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ea666f/32.png) [@dracos](https://www.ruby-forum.com/u/dracos)\
**Post date:** [March 22, 2006, 10:07pm UTC](https://www.ruby-forum.com/t/currency-conversion-webservice-in-a-rails-app/55577/3 "2006-03-22T22:07:09Z")

</div>

ActionWebService::Client::Soap has a special purpose in sense of that  
you  
should use it only for calling your own services with defined  
ActionWebService::API. In order to call third party web services you’re  
better of using soap4r API directly.

Kent.

---

<div class="post-metadata">

**Author:** ![dracos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ea666f/32.png) [@dracos](https://www.ruby-forum.com/u/dracos)\
**Post date:** [March 22, 2006, 11:24pm UTC](https://www.ruby-forum.com/t/currency-conversion-webservice-in-a-rails-app/55577/4 "2006-03-22T23:24:57Z")

</div>

If you are using ActionWebService then it should be automatically  
included.  
Otherwise, my best bet would be config/environment.rb

---

<div class="post-metadata">

**Author:** ![dracos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ea666f/32.png) [@dracos](https://www.ruby-forum.com/u/dracos)\
**Post date:** [March 23, 2006, 1:34am UTC](https://www.ruby-forum.com/t/currency-conversion-webservice-in-a-rails-app/55577/5 "2006-03-23T01:34:36Z")

</div>

Would you happen to have a simple example you could cut and paste for  
me? I looked in my Pickaxe book and don’t see soap4r in the index. I  
can see the SOAP library in the book,

Thanks,  
Peter

---

<div class="post-metadata">

**Author:** ![dracos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ea666f/32.png) [@dracos](https://www.ruby-forum.com/u/dracos)\
**Post date:** [March 22, 2006, 11:20pm UTC](https://www.ruby-forum.com/t/currency-conversion-webservice-in-a-rails-app/55577/6 "2006-03-22T23:20:57Z")

</div>

Hi Kent,

Thanks for the reply.

> ActionWebService::Client::Soap has a special purpose in sense of that you  
> should use it only for calling your own services with defined  
> ActionWebService::API.

OK

> In order to call third party web services you’re  
> better of using soap4r API directly.

I will look into using the Ruby soap4r library. If I want to use it  
from inside rails do I have to include it somewhere? Where do I do  
this?

Thanks,  
Peter

---

<div class="post-metadata">

**Author:** ![dracos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ea666f/32.png) [@dracos](https://www.ruby-forum.com/u/dracos)\
**Post date:** [March 23, 2006, 8:14am UTC](https://www.ruby-forum.com/t/currency-conversion-webservice-in-a-rails-app/55577/7 "2006-03-23T08:14:54Z")

</div>

Hi Peter

here’s one way of doing this :

service =  
SOAP::RPC::Driver.new("[http://www.webservicex.net/CurrencyConvertor.asmx","http://www.webserviceX.NET/](http://www.webservicex.net/CurrencyConvertor.asmx%22,%22http://www.webserviceX.NET/)  
[http://www.webservicex.net/CurrencyConvertor.asmx","http://www.webserviceX.NET/](http://www.webservicex.net/CurrencyConvertor.asmx%22,%22http://www.webserviceX.NET/)  
")  
service.default\_encodingstyle =  
SOAP::EncodingStyle::ASPDotNetHandler::Namespace  
service.add\_method\_with\_soapaction(“ConversionRate”,  
“[http://www.webserviceX.NET/ConversionRate](http://www.webserviceX.NET/ConversionRate)[http://www.webservicex.net/ConversionRate](http://www.webservicex.net/ConversionRate)”,  
“FromCurrency”, “ToCurrency”)

rate = service.ConversionRate(“EUR”,“GBP”)  
cheers

## Thibaut

[blog] [http://www.dotnetguru2.org/tbarrere](http://www.dotnetguru2.org/tbarrere)

---

<div class="post-metadata">

**Author:** ![dracos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ea666f/32.png) [@dracos](https://www.ruby-forum.com/u/dracos)\
**Post date:** [March 23, 2006, 5:38pm UTC](https://www.ruby-forum.com/t/currency-conversion-webservice-in-a-rails-app/55577/8 "2006-03-23T17:38:28Z")

</div>

Hi Thibaut,

Thanks for the code! I tried it and no matter which currencies  
combination I try I get a rate of zero. Did you try this and get a  
different result? It maybe that the web service doesn’t work but I  
hope not.

Thanks,  
Peter

---

<div class="post-metadata">

**Author:** ![dracos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ea666f/32.png) [@dracos](https://www.ruby-forum.com/u/dracos)\
**Post date:** [March 23, 2006, 10:37am UTC](https://www.ruby-forum.com/t/currency-conversion-webservice-in-a-rails-app/55577/9 "2006-03-23T10:37:59Z")

</div>

you may also want to have a look at this page (which I just discovered)

[http://wiki.rubyonrails.org/rails/pages/How+To+Consume+.NET+WebServices/](http://wiki.rubyonrails.org/rails/pages/How+To+Consume+.NET+WebServices/)

HTH

Thibaut

---

<div class="post-metadata">

**Author:** ![dracos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ea666f/32.png) [@dracos](https://www.ruby-forum.com/u/dracos)\
**Post date:** [March 23, 2006, 5:59pm UTC](https://www.ruby-forum.com/t/currency-conversion-webservice-in-a-rails-app/55577/10 "2006-03-23T17:59:29Z")

</div>

Hi Peter

I had this zero rate a some point, can’t remember exactly under which  
circumstances. I finally managed to get the good conversion rate - I’ll  
check my code back at home.

Three ideas until then:

- try the code in IRB to see what’s actually returned
- try adding service.wiredump\_dev = STDERR to dump the communication (on  
the  
webservice webpage you’ll see the expected input and output)
- try ConversionRate(xxxx).to\_f

Thibaut

---

<div class="post-metadata">

**Author:** ![dracos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ea666f/32.png) [@dracos](https://www.ruby-forum.com/u/dracos)\
**Post date:** [March 24, 2006, 12:05am UTC](https://www.ruby-forum.com/t/currency-conversion-webservice-in-a-rails-app/55577/11 "2006-03-24T00:05:56Z")

</div>

I just wanted to mention that the beta book “Enterprise Integration with  
Ruby” by Maik Schmidt (available at the Pragmatic Programmers web site,  
as  
usual) has an extensive section on processing XML files. It also  
discusses  
soap4r, REXML, and any other way of creating or consuming web services  
that  
you can think of.

Like most of their Beta Books, it’s awfully close to being a fully  
polished  
product. In short, that book rocks.

Ken

–  
Kenneth A. Kousen, Ph.D.  
President  
Kousen IT, Inc.  
[http://www.kousenit.com](http://www.kousenit.com)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![dracos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ea666f/32.png) [@dracos](https://www.ruby-forum.com/u/dracos)\
**Post date:** [March 24, 2006, 11:12pm UTC](https://www.ruby-forum.com/t/currency-conversion-webservice-in-a-rails-app/55577/12 "2006-03-24T23:12:20Z")

</div>

It works for me. What version of soap4r are you using?

$ ruby -rsoap/soap -e ‘puts SOAP::Version’  
1.5.5

---

<div class="post-metadata">

**Author:** ![dracos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ea666f/32.png) [@dracos](https://www.ruby-forum.com/u/dracos)\
**Post date:** [March 24, 2006, 11:31pm UTC](https://www.ruby-forum.com/t/currency-conversion-webservice-in-a-rails-app/55577/13 "2006-03-24T23:31:50Z")

</div>

Hi Kent,

It works? You got a number other than zero?

$ ruby -rsoap/soap -e ‘puts SOAP::Version’  
1.5.3-ruby1.8.2

Does this mean I need an upgrade? It would be strange since the Ruby  
runs without error. It is the SOAP response that has the zero. I  
realize it must be something wrong on my end. Maybe I have a typo. Did  
you cut and paste the code?

What is soap4r? Is it just a catchy phrase meaning SOAP in the Ruby  
environment? Or is it a library?

Thanks,  
Peter

---

<div class="post-metadata">

**Author:** ![dracos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ea666f/32.png) [@dracos](https://www.ruby-forum.com/u/dracos)\
**Post date:** [March 24, 2006, 7:34am UTC](https://www.ruby-forum.com/t/currency-conversion-webservice-in-a-rails-app/55577/14 "2006-03-24T07:34:30Z")

</div>

Hi Thibaut,

I’ve been trying to get this working. No luck yet. With wiredump it  
looks like the webservice really is returning zero. Any other ideas?

Thanks,  
Peter

---

<div class="post-metadata">

**Author:** ![dracos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ea666f/32.png) [@dracos](https://www.ruby-forum.com/u/dracos)\
**Post date:** [March 25, 2006, 12:15am UTC](https://www.ruby-forum.com/t/currency-conversion-webservice-in-a-rails-app/55577/15 "2006-03-25T00:15:26Z")

</div>

Hi Kent,

I upgraded from Ruby 1.8.2 to 1.8.4 and now I have SOAP 1.5.5. And the  
example works! Thanks.

Thanks to Thibaut also.

This is a major mystery and stress I hope is now over.

Thanks again,  
Peter
