Che tempo fa a Roma oggi?
Per saperlo possiamo sfruttare le Wheather api di Yahoo nella nostra applicazione web fatta con rubyOnRails.
Ecco il metodo del controller:
def index
require 'rexml/document'
url = 'http://weather.yahooapis.com/forecastrss?p=ITXX0067&u=c'
xml = REXML::Document.new Net::HTTP.get(URI.parse(url))
xml.elements.each '//item' do |item|
@item = {
:description => item.elements['description'].text
}
end
end
E nella pagina...
<%= @item%>
Il risultato è questo:
Yahoo Weather API
0
comments
Save to del.icio.us
0 hits!
Subscribe to my feed