Module: OpenweatherMap
- Defined in:
- lib/openweather_map.rb,
lib/openweather_map/version.rb
Constant Summary collapse
- VERSION =
"0.1.0"
Class Method Summary collapse
Class Method Details
.get_current_weather(city, api_key) ⇒ Object
7 8 9 10 11 12 13 |
# File 'lib/openweather_map.rb', line 7 def self.get_current_weather(city, api_key) url = URI("http://api.openweathermap.org/data/2.5/weather?q=#{city}&lang=pt_br&units=metric&appid=#{api_key}") req = Net::HTTP::Get.new(url.to_s) res = Net::HTTP.start(url.host, url.port) { |http| http.request(req) } par_res = JSON.parse(res.body) par_res['main']['temp'] end |
.get_forecast(city, api_key) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/openweather_map.rb', line 15 def self.get_forecast(city, api_key) url = URI.parse("http://api.openweathermap.org/data/2.5/forecast?q=#{city}&lang=pt_br&cnt=5&units=metric&appid=#{api_key}") req = Net::HTTP::Get.new(url.to_s) res = Net::HTTP.start(url.host, url.port) { |http| http.request(req) } par_res = JSON.parse(res.body) par_res['list'].map { |item| {item['dt_txt']=> item['main']['temp']} } end |