You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
562 B
25 lines
562 B
require 'json'
|
|
require 'open-uri'
|
|
|
|
require_relative 'config'
|
|
|
|
Forecaster = Struct.new(:api_key) do
|
|
def self.forecast(location)
|
|
forecaster.forecast(location)
|
|
end
|
|
|
|
def self.forecaster
|
|
return @forecaster if defined?(@forecaster)
|
|
|
|
@forecaster = self.new(Forecast::Config['FORECAST_API_KEY'])
|
|
end
|
|
|
|
def forecast(location)
|
|
lat, long = location.lat, location.long
|
|
units = Forecast::Config['FORECAST_UNITS']
|
|
url = "https://api.forecast.io/forecast/#{api_key}/#{lat},#{long}?units=#{units}"
|
|
response = JSON.load(open(url))
|
|
end
|
|
end
|
|
|