[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Pulling XML from Amazon API

jotto

1/5/2006 5:37:00 AM

Take Amazon's API for example, returning a XML file. In my application
(I'm using Rails), I want to allow the user to specify a criteria,
input it into a URL and send that URL to amazon to get the resulting
XML file. My question is.... how in Ruby can I grab the XML and put it
into a variable so I can parse it?

5 Answers

Lyndon Samson

1/5/2006 5:45:00 AM

0

On 1/5/06, jotto <jonathan.otto@gmail.com> wrote:
>
> Take Amazon's API for example, returning a XML file. In my application
> (I'm using Rails), I want to allow the user to specify a criteria,
> input it into a URL and send that URL to amazon to get the resulting
> XML file. My question is.... how in Ruby can I grab the XML and put it
> into a variable so I can parse it?


Heres a starter for .2 Note the use of a Proxy.

Net::HTTP::Proxy(phost, pport, puser, ppwd).start(host) {|http|
xmlStr = http.get(loc).body.to_s

}
}

REXML will let you parse the XML String into a DOM object for further
munging.

jotto

1/5/2006 5:48:00 AM

0

is that a common way of getting data from an API and manipulating it?

Devin Mullins

1/5/2006 5:56:00 AM

0

jotto wrote:

>is that a common way of getting data from an API and manipulating it?
>
>
Isn't amazon's API xmlrpc or soap?

Ruby's std library includes thingies for both:
http://ruby-doc.o...

Devin



jotto

1/5/2006 6:23:00 AM

0

OK, I see now how to use Amazon's through SOAP or XML RPC.... but let's
say the only way to access a particular API is by accessing a URL and
getting XML in return? Is this where you would use a proxy?

Vassilis Rizopoulos

1/5/2006 10:52:00 AM

0

jotto wrote:
> OK, I see now how to use Amazon's through SOAP or XML RPC.... but let's
> say the only way to access a particular API is by accessing a URL and
> getting XML in return? Is this where you would use a proxy?
The use of the proxy is optional (if there is a proxy inbetween then you
need to specify it)
Net::HTTP::Proxy returns a Net::HTTP object if phost is nil, e.g. no
proxy in between.
An alternative is the use of openuri so that you can do IO as if on an
XML file
You can also read the Ruby/Amazon library code
(http://www.caliban.org/ruby/ruby-am...) for a solution on how to
handle XML content of HTTP requests.
Cheers,
V.-

--
http://www.braveworl...

____________________________________________________________________
http://www.f... - äùñåÜí õðçñåóßá çëåêôñïíéêïý ôá÷õäñïìåßïõ.
http://www.f... - free email service for the Greek-speaking.