Permalink
Browse files

Configured Workaround for Zip Only

  • Loading branch information...
1 parent 42543fd commit 3241d417ca09fea369c7f32abd6dcca1983e71f7 @aspires aspires committed Apr 27, 2012
Showing with 56 additions and 18 deletions.
  1. +2 −0 .gitignore
  2. +3 −0 Gemfile
  3. +14 −0 Gemfile.lock
  4. +2 −0 README.rdoc
  5. +7 −0 demo.rb
  6. +11 −10 lib/yahoo-weather.rb
  7. +3 −3 lib/yahoo-weather/atmosphere.rb
  8. +14 −5 lib/yahoo-weather/client.rb
View
@@ -0,0 +1,2 @@
+/.redcar
+/redcar
View
@@ -0,0 +1,3 @@
+source :rubygems
+
+gem "httparty", "0.8.3"
View
@@ -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
@@ -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
@@ -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
@@ -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'
@@ -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
@@ -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

0 comments on commit 3241d41

Please sign in to comment.