Last active
August 29, 2015 14:05
-
-
Save rsbohn/278d51b5f4870fc48207 to your computer and use it in GitHub Desktop.
xiki calls Wunderground.com API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "json" | |
require "rest-client" | |
class Wunderground | |
KEY = "YOUR-KEY-HERE" | |
WU = RestClient::Resource.new "http://api.wunderground.com/api/#{KEY}" | |
Sample = "- 02134/\n- AZ/Wikieup/\n- KSGU/\n- FL/Saint_Petersburg/\n- pws:KFLSTPET42/\n" | |
def self.menu *args | |
return Sample if args == [] | |
first, *rest = *args | |
return raw rest if first == "raw" | |
return current args | |
end | |
def self.current *site | |
site = site.join("/") | |
response = WU["conditions/q/#{site}.json"].get | |
obs = JSON.parse(response) | |
alt = obs["response"] | |
return alt["error"] if alt["error"] != nil | |
return alt["results"] if alt["results"] != nil | |
obs = obs["current_observation"] | |
reply = { | |
:city => obs["observation_location"]["full"], | |
:station_id => obs["station_id"], | |
:time => obs["observation_time"], | |
:weather => obs["weather"], | |
:temperature => obs["temperature_string"], | |
:relative_humidity => obs["relative_humidity"], | |
:pressure => obs["pressure_in"] | |
} | |
return reply | |
end | |
def self.raw *site | |
site = site.join "/" | |
response = WU["conditions/q/#{site}.json"].get | |
return response | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Added self.menu, got the rest working with it.