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.

24 lines
509 B

require 'json'
require 'open-uri'
require_relative 'alfred'
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(Alfred::Config['FORECAST_API_KEY'])
end
def forecast(location)
lat, long = location.lat, location.long
url = "https://api.forecast.io/forecast/#{api_key}/#{lat},#{long}?units=auto"
response = JSON.load(open(url))
end
end