Class: EnpitWeather::Weather

Inherits:
Object
  • Object
show all
Defined in:
lib/enpit_weather.rb

Instance Method Summary collapse

Instance Method Details

#displayCityWeather(data) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/enpit_weather.rb', line 18

def displayCityWeather(data)
  data.each do |w_data|
    hash = JSON.parse(w_data)

    city = hash["city"]["name"]
    weather_main = hash["list"][0]["weather"][0]["main"]
    weather_desc = hash["list"][0]["weather"][0]["description"]

    $stdout.print "City: ", city, "\n"
    $stdout.print "Weather: ", weather_main, "\n"
    $stdout.print "Weather Description: ", weather_desc, "\n"
  end
end

#getCityWeatherObject



8
9
10
11
12
13
14
15
16
# File 'lib/enpit_weather.rb', line 8

def getCityWeather
  c = HTTPClient.new
  weather = Array.new
  ["2112669", "1850310", "1863501", "1853226", "2113014", "1850147", "1860291"].each do |city|
    w = c.get('http://api.openweathermap.org/data/2.5/forecast/daily?APPID=b13a40b93c4e20f046c45c3667b7d6a0&id=' + city + '&lang=ja&cnt=1&units').body
    weather.push(w)
  end
  weather
end