Sha256: 76acc5ab0c0ef3c1b15b7b8d0d25766fe95c60db336c79b92fd33f56f78bbf78

Contents?: true

Size: 661 Bytes

Versions: 2

Compression:

Stored size: 661 Bytes

Contents

require 'faraday'
require 'json'
require 'date'

module GeekWeather
  class Forecast
  	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
  end
end
require_relative "./forecast/day"

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
geek_weather-0.1.1 lib/geek_weather/forecast.rb
geek_weather-0.1.0 lib/geek_weather/forecast.rb