Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Configured Workaround for Zip Only

  • Loading branch information...
commit 3241d417ca09fea369c7f32abd6dcca1983e71f7 1 parent 42543fd
@aspires aspires authored
View
2  .gitignore
@@ -0,0 +1,2 @@
+/.redcar
+/redcar
View
3  Gemfile
@@ -0,0 +1,3 @@
+source :rubygems
+
+gem "httparty", "0.8.3"
View
14 Gemfile.lock
@@ -0,0 +1,14 @@
+GEM
+ remote: http://rubygems.org/
+ specs:
+ httparty (0.8.3)
+ multi_json (~> 1.0)
+ multi_xml
+ multi_json (1.3.2)
+ multi_xml (0.4.4)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ httparty (= 0.8.3)
View
2  README.rdoc
@@ -1,5 +1,7 @@
= yahoo-weather
+= Currently Undergoing 1.9.x compatability upgrades, and revamping Lookup_Location()
+
== About
yahoo-weather provides an object-oriented interface to the Yahoo! Weather XML
View
7 demo.rb
@@ -0,0 +1,7 @@
+require_relative "lib/yahoo-weather.rb"
+
+@client = YahooWeather::Client.new('LM816I7V34HgjIFkSrFhatjTI6G1ksJFWwOTVOVOpSssTUFnpRI9iNIijbuQPOaOFR_Y_EmFbPXk03XF45uLqchthxBXWuw')
+
+response = @client.lookup_zip(72072)
+
+p response
View
21 lib/yahoo-weather.rb
@@ -19,6 +19,7 @@
require 'cgi'
require 'time'
require 'nokogiri'
+require "httparty"
class YahooWeather
VERSION = '1.2.0'
@@ -28,13 +29,13 @@ def self._parse_time (text)
end
end
-require 'yahoo-weather/astronomy'
-require 'yahoo-weather/atmosphere'
-require 'yahoo-weather/client'
-require 'yahoo-weather/condition'
-require 'yahoo-weather/forecast'
-require 'yahoo-weather/image'
-require 'yahoo-weather/location'
-require 'yahoo-weather/response'
-require 'yahoo-weather/units'
-require 'yahoo-weather/wind'
+require_relative 'yahoo-weather/astronomy'
+require_relative 'yahoo-weather/atmosphere'
+require_relative 'yahoo-weather/client'
+require_relative 'yahoo-weather/condition'
+require_relative 'yahoo-weather/forecast'
+require_relative 'yahoo-weather/image'
+require_relative 'yahoo-weather/location'
+require_relative 'yahoo-weather/response'
+require_relative 'yahoo-weather/units'
+require_relative 'yahoo-weather/wind'
View
6 lib/yahoo-weather/atmosphere.rb
@@ -32,9 +32,9 @@ def initialize (payload)
# map barometric pressure direction to appropriate constant
@barometer = nil
case payload['rising'].to_i
- when 0: @barometer = Barometer::STEADY
- when 1: @barometer = Barometer::RISING
- when 2: @barometer = Barometer::FALLING
+ when 0; @barometer = Barometer::STEADY
+ when 1; @barometer = Barometer::RISING
+ when 2; @barometer = Barometer::FALLING
end
end
end
View
19 lib/yahoo-weather/client.rb
@@ -1,10 +1,14 @@
# The main client object through which the Yahoo! Weather service may be accessed.
class YahooWeather::Client
+
+ include HTTParty
# the url with which we obtain weather information from yahoo
@@API_URL = "http://weather.yahooapis.com/forecastrss"
-
- def initialize (api_url = @@API_URL)
+ # @@APP_ID = "LIST_FREE_YAHOO_API_HERE"
+
+ def initialize (app_id = @@APP_ID,api_url = @@API_URL)
@api_url = api_url
+ @app_id = app_id
end
# Returns a YahooWeather::Response object detailing the current weather
@@ -46,9 +50,9 @@ def lookup_by_woeid (woeid, units = 'f')
# +Fahrenheit+ as YahooWeather::Units::FAHRENHEIT, or +Celsius+ as
# YahooWeather::Units::CELSIUS, and defaults to fahrenheit.
#
- def lookup_location (location, units = 'f')
- url = @api_url + '?p=' + CGI.escape(location) + '&u=' + CGI.escape(units)
- _lookup(location, url)
+ def lookup_zip(zip, units = 'f')
+ woeid = woe_lookup(zip)
+ lookup_by_woeid(woeid)
end
private
@@ -66,5 +70,10 @@ def _lookup (src, url)
doc = Nokogiri::XML.parse(response)
YahooWeather::Response.new(src, url, doc)
end
+
+ def woe_lookup(zip)
+ p ydata = HTTParty.get("http://where.yahooapis.com/v1/places.q('#{zip}')?appid=[#{@app_id}]")
+ woe_id = ydata["places"]["place"]["woeid"]
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.