Forum: Ruby Pulling XML from Amazon API

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.
jotto (Guest)
on 2006-01-05 07:38
(Received via mailing list)
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?
Lyndon S. (Guest)
on 2006-01-05 07:47
(Received via mailing list)
On 1/5/06, jotto <removed_email_address@domain.invalid> 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 (Guest)
on 2006-01-05 07:53
(Received via mailing list)
is that a common way of getting data from an API and manipulating it?
Devin M. (Guest)
on 2006-01-05 07:59
(Received via mailing list)
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
jotto (Guest)
on 2006-01-05 08:29
(Received via mailing list)
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?
Damphyr (Guest)
on 2006-01-05 12:53
(Received via mailing list)
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-amazon.shtml) for a solution on how to
handle XML content of HTTP requests.
Cheers,
V.-

--
http://www.braveworld.net/riva
This topic is locked and can not be replied to.