Class: GeekWeather::Forecast

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

Defined Under Namespace

Classes: Day

Instance Method Summary collapse

Instance Method Details

#call(country_code:, city_name:, forecast_offset: 0) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/geek_weather/forecast.rb', line 7

def call(country_code:, city_name:, forecast_offset: 0)
	api_key = ENV['WUNDERGROUND_API_KEY']
	raise "missing API Key" if api_key.nil?
	api_url = "http://api.wunderground.com/api/#{api_key}/forecast/q/#{country_code}/#{city_name}.json"
	response = Faraday.get(api_url)
		json = JSON.parse(response.body)
		days = json["forecast"]["simpleforecast"]["forecastday"].map do	|day_json|
Day.new(day_json)
		end
		forecast_date = ::Date.today + forecast_offset
		day = days.find{ |day| day.date == forecast_date }
end