ya_yahoo_weather 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,23 @@
1
+ # http://developer.yahoo.com/weather/
2
+ module YaYahooWeather
3
+ class Client
4
+ @@YAHOO_WEATHER_API = "http://weather.yahooapis.com/forecastrss"
5
+
6
+ def get_weather_conditions_by_woeid(woeid)
7
+ begin
8
+ url = @@YAHOO_WEATHER_API + "?w=" + woeid.to_s + "&u=f"
9
+ response = do_http_get(url)
10
+ response_hash = Nori.parse(response)
11
+ response_hash['rss']['channel']['item']['yweather:condition']
12
+ rescue => e
13
+ raise RuntimeError.new("Failed to get weather. woeid => #{woeid.inspect} url => #{url.inspect} e => #{e.inspect}")
14
+ end
15
+ end
16
+
17
+ private
18
+ def do_http_get(url)
19
+ Net::HTTP.get_response(URI.parse(url)).body.to_s
20
+ end
21
+
22
+ end
23
+ end
@@ -1,3 +1,3 @@
1
1
  module YaYahooWeather
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -1,5 +1,6 @@
1
+ require "net/http"
2
+ require "nori"
3
+
1
4
  require "ya_yahoo_weather/version"
5
+ require "ya_yahoo_weather/client"
2
6
 
3
- module YaYahooWeather
4
- # Your code goes here...
5
- end
@@ -0,0 +1,94 @@
1
+ require './lib/ya_yahoo_weather'
2
+
3
+ def sample
4
+ <<END
5
+ <?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
6
+ <rss version="2.0" xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#">
7
+ <channel>
8
+ <title>Yahoo! Weather - Sunnyvale, CA</title>
9
+ <link>http://us.rd.yahoo.com/dailynews/rss/weather/Sunnyvale__CA/*http://weather.yahoo.com/forecast/USCA1116_f.html</link>
10
+ <description>Yahoo! Weather for Sunnyvale, CA</description>
11
+ <language>en-us</language>
12
+ <lastBuildDate>Fri, 18 Dec 2009 9:38 am PST</lastBuildDate>
13
+ <ttl>60</ttl>
14
+ <yweather:location city="Sunnyvale" region="CA" country="United States"/>
15
+ <yweather:units temperature="F" distance="mi" pressure="in" speed="mph"/>
16
+ <yweather:wind chill="50" direction="0" speed="0" />
17
+ <yweather:atmosphere humidity="94" visibility="3" pressure="30.27" rising="1" />
18
+ <yweather:astronomy sunrise="7:17 am" sunset="4:52 pm"/>
19
+ <image>
20
+ <title>Yahoo! Weather</title>
21
+ <width>142</width>
22
+ <height>18</height>
23
+ <link>http://weather.yahoo.com</link>
24
+ <url>http://l.yimg.com/a/i/us/nws/th/main_142b.gif</url>
25
+ </image>
26
+ <item>
27
+ <title>Conditions for Sunnyvale, CA at 9:38 am PST</title>
28
+ <geo:lat>37.37</geo:lat>
29
+ <geo:long>-122.04</geo:long>
30
+ <link>http://us.rd.yahoo.com/dailynews/rss/weather/Sunnyvale__CA/*http://weather.yahoo.com/forecast/USCA1116_f.html</link>
31
+ <pubDate>Fri, 18 Dec 2009 9:38 am PST</pubDate>
32
+ <yweather:condition text="Mostly Cloudy" code="28" temp="50" date="Fri, 18 Dec 2009 9:38 am PST" />
33
+ <description><![CDATA[
34
+ <img src="http://l.yimg.com/a/i/us/we/52/28.gif"/><br />
35
+ <b>Current Conditions:</b><br />
36
+ Mostly Cloudy, 50 F<BR />
37
+ <BR /><b>Forecast:</b><BR />
38
+ Fri - Partly Cloudy. High: 62 Low: 49<br />
39
+ Sat - Partly Cloudy. High: 65 Low: 49<br />
40
+ <br />
41
+ <a href="http://us.rd.yahoo.com/dailynews/rss/weather/Sunnyvale__CA/*http://weather.yahoo.com/forecast/USCA1116_f.html">Full Forecast at Yahoo! Weather</a><BR/><BR/>
42
+ (provided by <a href="http://www.weather.com" >The Weather Channel</a>)<br/>
43
+ ]]></description>
44
+ <yweather:forecast day="Fri" date="18 Dec 2009" low="49" high="62" text="Partly Cloudy" code="30" />
45
+ <yweather:forecast day="Sat" date="19 Dec 2009" low="49" high="65" text="Partly Cloudy" code="30" />
46
+ <guid isPermaLink="false">USCA1116_2009_12_18_9_38_PST</guid>
47
+ </item>
48
+ </channel>
49
+ </rss>
50
+ END
51
+ end
52
+
53
+ describe YaYahooWeather::Client do
54
+ # copied from http://developer.yahoo.com/weather/
55
+ describe "#initialize" do
56
+ it "should instantiate" do
57
+ client = YaYahooWeather::Client.new
58
+ end
59
+ end
60
+ describe "#get_weather_conditions_by_woeid" do
61
+ context "on success" do
62
+ before :each do
63
+ @client = YaYahooWeather::Client.new
64
+ @client.stub!(:do_http_get).and_return(sample)
65
+ end
66
+ it "should return non-null result" do
67
+ response = @client.get_weather_conditions_by_woeid("mywoeid")
68
+ response.should_not be_nil
69
+ end
70
+ describe "the result" do
71
+ before :each do
72
+ @response = @client.get_weather_conditions_by_woeid("mywoeid")
73
+ end
74
+ it "should be a hash" do
75
+ @response.instance_of?(Hash).should be_true
76
+ end
77
+ it "should contain the condition code" do
78
+ @response['@code'].to_i.should == 28
79
+ end
80
+ end
81
+ end
82
+ context "on error" do
83
+ before :each do
84
+ @client = YaYahooWeather::Client.new
85
+ @client.stub!(:do_http_get).and_raise("Yahoo hates you")
86
+ end
87
+ it "should raise runtime exception" do
88
+ lambda {
89
+ @client.get_weather_conditions_by_woeid("mywoeid")
90
+ }.should raise_exception
91
+ end
92
+ end
93
+ end
94
+ end
@@ -11,6 +11,9 @@ Gem::Specification.new do |s|
11
11
 
12
12
  s.rubyforge_project = "ya_yahoo_weather"
13
13
 
14
+ s.add_development_dependency('rspec')
15
+ s.add_dependency('nori')
16
+
14
17
  s.files = `git ls-files`.split("\n")
15
18
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
19
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: ya_yahoo_weather
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.1
5
+ version: 0.0.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - John Hinnegan
@@ -10,10 +10,31 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-06-01 00:00:00 -07:00
13
+ date: 2011-06-02 00:00:00 -07:00
14
14
  default_executable:
15
- dependencies: []
16
-
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: rspec
18
+ prerelease: false
19
+ requirement: &id001 !ruby/object:Gem::Requirement
20
+ none: false
21
+ requirements:
22
+ - - ">="
23
+ - !ruby/object:Gem::Version
24
+ version: "0"
25
+ type: :development
26
+ version_requirements: *id001
27
+ - !ruby/object:Gem::Dependency
28
+ name: nori
29
+ prerelease: false
30
+ requirement: &id002 !ruby/object:Gem::Requirement
31
+ none: false
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: "0"
36
+ type: :runtime
37
+ version_requirements: *id002
17
38
  description:
18
39
  email:
19
40
  - john@thinknear.com
@@ -28,7 +49,9 @@ files:
28
49
  - Gemfile
29
50
  - Rakefile
30
51
  - lib/ya_yahoo_weather.rb
52
+ - lib/ya_yahoo_weather/client.rb
31
53
  - lib/ya_yahoo_weather/version.rb
54
+ - spec/ya_yahoo_weather/client_spec.rb
32
55
  - ya_yahoo_weather.gemspec
33
56
  has_rdoc: true
34
57
  homepage:
@@ -58,5 +81,5 @@ rubygems_version: 1.6.2
58
81
  signing_key:
59
82
  specification_version: 3
60
83
  summary: A gem to call yahoo weather
61
- test_files: []
62
-
84
+ test_files:
85
+ - spec/ya_yahoo_weather/client_spec.rb