Forum: Ruby on Rails currency conversion webservice in a rails app?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Eea3feaacbe44706164289d068d94828?d=identicon&s=25 Peter Michaux (Guest)
on 2006-03-22 07:14
(Received via mailing list)
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...

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
Eea3feaacbe44706164289d068d94828?d=identicon&s=25 Peter Michaux (Guest)
on 2006-03-22 18:50
(Received via mailing list)
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")
    #web_client_api :con, :soap,
"http://www.webservicex.net/CurrencyConvertor.asmx?WSDL"
    web_client_api :con, :soap,
"http://www.webserviceX.NET/ConversionRate"

    con.ConversionRate("CND", "USD")
    @rate = con
  end
3ccecc71b9fb0a3d7f00a0bef6f0a63a?d=identicon&s=25 Kent Sibilev (Guest)
on 2006-03-22 22:07
(Received via mailing list)
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.
Eea3feaacbe44706164289d068d94828?d=identicon&s=25 Peter Michaux (Guest)
on 2006-03-22 23:20
(Received via mailing list)
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
3ccecc71b9fb0a3d7f00a0bef6f0a63a?d=identicon&s=25 Kent Sibilev (Guest)
on 2006-03-22 23:24
(Received via mailing list)
If you are using ActionWebService then it should be automatically
included.
Otherwise, my best bet would be config/environment.rb
Eea3feaacbe44706164289d068d94828?d=identicon&s=25 Peter Michaux (Guest)
on 2006-03-23 01:34
(Received via mailing list)
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
91eb330fb36d1e03c856574dfb77d2bc?d=identicon&s=25 Thibaut Barrère (Guest)
on 2006-03-23 08:14
(Received via mailing list)
Hi Peter

here's one way of doing this :

service =
SOAP::RPC::Driver.new("http://www.webservicex.net/CurrencyConvertor.asmx"...
<http://www.webservicex.net/CurrencyConvertor.asmx%...
")
service.default_encodingstyle =
SOAP::EncodingStyle::ASPDotNetHandler::Namespace
service.add_method_with_soapaction("ConversionRate",
"http://www.webserviceX.NET/ConversionRate<http://w...,
"FromCurrency", "ToCurrency")

rate = service.ConversionRate("EUR","GBP")
cheers

Thibaut
--
[blog] http://www.dotnetguru2.org/tbarrere
91eb330fb36d1e03c856574dfb77d2bc?d=identicon&s=25 Thibaut Barrère (Guest)
on 2006-03-23 10:37
(Received via mailing list)
you may also want to have a look at this page (which I just discovered)

http://wiki.rubyonrails.org/rails/pages/How+To+Con...

HTH

Thibaut
Eea3feaacbe44706164289d068d94828?d=identicon&s=25 Peter Michaux (Guest)
on 2006-03-23 17:38
(Received via mailing list)
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
91eb330fb36d1e03c856574dfb77d2bc?d=identicon&s=25 Thibaut Barrère (Guest)
on 2006-03-23 17:59
(Received via mailing list)
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
432fcf0d43d64c1189d9672716ac679d?d=identicon&s=25 Ken Kousen (kousen)
on 2006-03-24 00:05
(Received via mailing list)
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
ken.kousen@kousenit.com
Eea3feaacbe44706164289d068d94828?d=identicon&s=25 Peter Michaux (Guest)
on 2006-03-24 07:34
(Received via mailing list)
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
3ccecc71b9fb0a3d7f00a0bef6f0a63a?d=identicon&s=25 Kent Sibilev (Guest)
on 2006-03-24 23:12
(Received via mailing list)
It works for me. What version of soap4r are you using?

$ ruby -rsoap/soap -e 'puts SOAP::Version'
1.5.5
Eea3feaacbe44706164289d068d94828?d=identicon&s=25 Peter Michaux (Guest)
on 2006-03-24 23:31
(Received via mailing list)
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
Eea3feaacbe44706164289d068d94828?d=identicon&s=25 Peter Michaux (Guest)
on 2006-03-25 00:15
(Received via mailing list)
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
This topic is locked and can not be replied to.