Pulling XML from Amazon API

J

jotto

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?
 
L

Lyndon Samson

------=_Part_46073_27916843.1136439909371
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

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 =3D http.get(loc).body.to_s

}
}

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

------=_Part_46073_27916843.1136439909371--
 
J

jotto

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?
 
D

Damphyr

jotto said:
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-amazon.shtml) for a solution on how to
handle XML content of HTTP requests.
Cheers,
V.-

--
http://www.braveworld.net/riva

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top