Skip to content

Instantly share code, notes, and snippets.

@rsbohn
Last active August 29, 2015 14:05
Show Gist options
  • Save rsbohn/278d51b5f4870fc48207 to your computer and use it in GitHub Desktop.
Save rsbohn/278d51b5f4870fc48207 to your computer and use it in GitHub Desktop.
xiki calls Wunderground.com API
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
@rsbohn
Copy link
Author

rsbohn commented Aug 31, 2014

Added self.menu, got the rest working with it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment