Pulling XML from Amazon API

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?

On 1/5/06, jotto [email protected] 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 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.org/stdlib/

Devin

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

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?

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
(Ruby/Amazon) for a solution on how to
handle XML content of HTTP requests.
Cheers,
V.-


http://www.braveworld.net/riva