yweather 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +6 -0
- data/CHANGELOG +3 -0
- data/Gemfile +2 -0
- data/Guardfile +9 -0
- data/LICENSE +504 -0
- data/README.md +109 -0
- data/Rakefile +14 -0
- data/bin/yweather +30 -0
- data/lib/yweather.rb +22 -0
- data/lib/yweather/astronomy.rb +12 -0
- data/lib/yweather/atmosphere.rb +34 -0
- data/lib/yweather/client.rb +80 -0
- data/lib/yweather/condition.rb +71 -0
- data/lib/yweather/forecast.rb +22 -0
- data/lib/yweather/image.rb +19 -0
- data/lib/yweather/location.rb +15 -0
- data/lib/yweather/response.rb +87 -0
- data/lib/yweather/units.rb +20 -0
- data/lib/yweather/utils.rb +7 -0
- data/lib/yweather/version.rb +3 -0
- data/lib/yweather/wind.rb +15 -0
- data/spec/bin/yweather_spec.rb +7 -0
- data/spec/cassettes/invalid_weather_transaction.yml +44 -0
- data/spec/cassettes/invalid_woeid_conversion_transaction.yml +38 -0
- data/spec/cassettes/valid_weather_transaction.yml +66 -0
- data/spec/cassettes/valid_weather_transaction_with_zipcode_conversion.yml +101 -0
- data/spec/cassettes/valid_woeid_conversion_transaction.yml +38 -0
- data/spec/lib/yweather/astronomy_spec.rb +27 -0
- data/spec/lib/yweather/atmosphere_spec.rb +25 -0
- data/spec/lib/yweather/client_spec.rb +58 -0
- data/spec/lib/yweather/condition_spec.rb +25 -0
- data/spec/lib/yweather/forecast_spec.rb +25 -0
- data/spec/lib/yweather/image_spec.rb +25 -0
- data/spec/lib/yweather/location_spec.rb +25 -0
- data/spec/lib/yweather/response_spec.rb +49 -0
- data/spec/lib/yweather/units_spec.rb +25 -0
- data/spec/lib/yweather/wind_spec.rb +25 -0
- data/spec/spec_helper.rb +34 -0
- data/spec/support/helpers/spec_parse_helpers.rb +25 -0
- data/spec/support/helpers/spec_yweather_helpers.rb +16 -0
- data/yweather.gemspec +39 -0
- metadata +283 -0
@@ -0,0 +1,20 @@
|
|
1
|
+
module Yweather
|
2
|
+
class Units
|
3
|
+
|
4
|
+
FAHRENHEIT = 'f'
|
5
|
+
CELSIUS = 'c'
|
6
|
+
|
7
|
+
attr_reader :temperature
|
8
|
+
attr_reader :distance
|
9
|
+
attr_reader :pressure
|
10
|
+
attr_reader :speed
|
11
|
+
|
12
|
+
def initialize(data)
|
13
|
+
@temperature = data[:temperature]
|
14
|
+
@distance = data[:distance]
|
15
|
+
@pressure = data[:pressure]
|
16
|
+
@speed = data[:speed]
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: http://weather.yahooapis.com/forecastrss?w=abadwoeid&u=f
|
6
|
+
body: ''
|
7
|
+
headers:
|
8
|
+
accept:
|
9
|
+
- ! '*/*; q=0.5, application/xml'
|
10
|
+
accept-encoding:
|
11
|
+
- gzip, deflate
|
12
|
+
user-agent:
|
13
|
+
- Ruby
|
14
|
+
response:
|
15
|
+
status:
|
16
|
+
code: 200
|
17
|
+
message: OK
|
18
|
+
headers:
|
19
|
+
date:
|
20
|
+
- Sat, 14 Jan 2012 00:25:59 GMT
|
21
|
+
cache-control:
|
22
|
+
- private, max-age=1800
|
23
|
+
expires:
|
24
|
+
- Sat, 14 Jan 2012 00:55:59 GMT
|
25
|
+
connection:
|
26
|
+
- close
|
27
|
+
transfer-encoding:
|
28
|
+
- chunked
|
29
|
+
content-type:
|
30
|
+
- text/xml;charset=UTF-8
|
31
|
+
content-encoding:
|
32
|
+
- gzip
|
33
|
+
body: !binary |-
|
34
|
+
H4sIAAAAAAAAA1yQQU/DMAyF7/0VXpC4tWk7hkZJuwNi0jghMYQ4odB4bUSb
|
35
|
+
REm6sn9Ppm2McYgU2e99th9bfPcdbNE6qVVJsiQlgKrWQqqmJK/rZTwn4DxX
|
36
|
+
gndaYUl26AgsqohZ586+fO8LJOWK3Yjct2hL0npvCkpDOTnWkh1vtU5q3VPl
|
37
|
+
aCDQ7GxsUP96xnFMxmmibUPzNJ3SNKOhTcfGzW8+jHZXJGxQt1wp7MLPS99h
|
38
|
+
9b6HT+DtMAtieLRWW0YP3YgJdLWVxoeN/2uPyr+KiEmPfXVkP0i/A6U9bPSg
|
39
|
+
xIl5gYxWass7KWClzOCBbrTFmjsfzlyMJf/kYtQoxTXvzf1QbqLLcYwextHT
|
40
|
+
VWyfT8UmcQzcyPlvhM7k5xghPGPRORTBOKgvFLC0Ep64gmwK2W2Rz4rZHTy/
|
41
|
+
rCFPsxziuIp+AAAA//8DADpJF5P0AQAA
|
42
|
+
http_version: '1.1'
|
43
|
+
recorded_at: Sat, 14 Jan 2012 00:25:59 GMT
|
44
|
+
recorded_with: VCR 2.0.0.rc1
|
@@ -0,0 +1,38 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: post
|
5
|
+
uri: https://query.yahooapis.com/v1/public/yql
|
6
|
+
body: q=select+woeid+from+geo.places+where+text+%3D+%27292929%2C+usa%27&env=http://datatables.org/alltables.env&format=json
|
7
|
+
headers:
|
8
|
+
accept:
|
9
|
+
- ! '*/*'
|
10
|
+
user-agent:
|
11
|
+
- Ruby
|
12
|
+
connection:
|
13
|
+
- close
|
14
|
+
response:
|
15
|
+
status:
|
16
|
+
code: 200
|
17
|
+
message: OK
|
18
|
+
headers:
|
19
|
+
access-control-allow-origin:
|
20
|
+
- ! '*'
|
21
|
+
cache-control:
|
22
|
+
- public, max-age=86399, stale-while-revalidate=86399
|
23
|
+
content-type:
|
24
|
+
- application/json;charset=utf-8
|
25
|
+
vary:
|
26
|
+
- Accept-Encoding
|
27
|
+
date:
|
28
|
+
- Sat, 14 Jan 2012 00:18:11 GMT
|
29
|
+
server:
|
30
|
+
- YTS/1.20.7
|
31
|
+
age:
|
32
|
+
- '1'
|
33
|
+
connection:
|
34
|
+
- close
|
35
|
+
body: ! '{"query":{"count":8,"created":"2012-01-14T00:18:11Z","lang":"en-US","results":{"place":[{"woeid":"23424977"},{"woeid":"2101027"},{"woeid":"1118473"},{"woeid":"24855952"},{"woeid":"28477735"},{"woeid":"28433002"},{"woeid":"832684"},{"woeid":"55968184"}]}}}'
|
36
|
+
http_version: '1.1'
|
37
|
+
recorded_at: Sat, 14 Jan 2012 00:18:11 GMT
|
38
|
+
recorded_with: VCR 2.0.0.rc1
|
@@ -0,0 +1,66 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: http://weather.yahooapis.com/forecastrss?w=12786794&u=f
|
6
|
+
body: ''
|
7
|
+
headers:
|
8
|
+
accept:
|
9
|
+
- ! '*/*; q=0.5, application/xml'
|
10
|
+
accept-encoding:
|
11
|
+
- gzip, deflate
|
12
|
+
user-agent:
|
13
|
+
- Ruby
|
14
|
+
response:
|
15
|
+
status:
|
16
|
+
code: 200
|
17
|
+
message: OK
|
18
|
+
headers:
|
19
|
+
date:
|
20
|
+
- Sat, 14 Jan 2012 00:15:52 GMT
|
21
|
+
cache-control:
|
22
|
+
- public, max-age=1800
|
23
|
+
expires:
|
24
|
+
- Sat, 14 Jan 2012 00:45:52 GMT
|
25
|
+
vary:
|
26
|
+
- Accept-Encoding
|
27
|
+
content-type:
|
28
|
+
- text/xml;charset=UTF-8
|
29
|
+
content-encoding:
|
30
|
+
- gzip
|
31
|
+
age:
|
32
|
+
- '0'
|
33
|
+
transfer-encoding:
|
34
|
+
- chunked
|
35
|
+
connection:
|
36
|
+
- keep-alive
|
37
|
+
server:
|
38
|
+
- YTS/1.19.8
|
39
|
+
body: !binary |-
|
40
|
+
H4sIAAAAAAAAA8RVS2/jNhA+x7+CYS9tEYt62IljyFrsemEsmhyCOkFRLBYG
|
41
|
+
LTESsRQpkFS0/vcd6uVHiqKn9iKJnNc3M9+M4g8/SoHemDZcyRUOPB8jJlOV
|
42
|
+
cZmv8MvzZrrAyFgqMyqUZCt8YAajD8nk6irWxhwtQ2cJvqRZHhpGb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CcbGoh0JClY/PlsFKXNukek58rrd54Bvtvf0CXgNtf
|
59
|
+
WR8agmKUPBds3Pnr7gfmHP4CGYOzb9+Sy80/8moADJQ5tIzBPXlOeIORUA0w
|
60
|
+
C0hWQGWBbnDVsfCsObhnY3h/sdfOg0CrxiCzd0HuhyCz+RCk7erg3MV2zvOa
|
61
|
+
Z4ibJ6ZL+gjDtcKvVBiGk7HyzuvOD3bBbHe38/1dO1rOrF0/3doh4+8+dt2G
|
62
|
+
1/V0imjF52OFaTo7NhhAlO0+ZxmY1vI7dMjR1GUBFQtulwEMWYiets/dyE2n
|
63
|
+
yeQvAAAA//8DALaxTRAUCQAA
|
64
|
+
http_version: '1.1'
|
65
|
+
recorded_at: Sat, 14 Jan 2012 00:15:52 GMT
|
66
|
+
recorded_with: VCR 2.0.0.rc1
|
@@ -0,0 +1,101 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: post
|
5
|
+
uri: https://query.yahooapis.com/v1/public/yql
|
6
|
+
body: q=select+woeid+from+geo.places+where+text+%3D+%2766206%2C+usa%27&env=http://datatables.org/alltables.env&format=json
|
7
|
+
headers:
|
8
|
+
accept:
|
9
|
+
- ! '*/*'
|
10
|
+
user-agent:
|
11
|
+
- Ruby
|
12
|
+
connection:
|
13
|
+
- close
|
14
|
+
response:
|
15
|
+
status:
|
16
|
+
code: 200
|
17
|
+
message: OK
|
18
|
+
headers:
|
19
|
+
access-control-allow-origin:
|
20
|
+
- ! '*'
|
21
|
+
cache-control:
|
22
|
+
- public, max-age=86400, stale-while-revalidate=86400
|
23
|
+
content-type:
|
24
|
+
- application/json;charset=utf-8
|
25
|
+
vary:
|
26
|
+
- Accept-Encoding
|
27
|
+
date:
|
28
|
+
- Sat, 14 Jan 2012 00:15:53 GMT
|
29
|
+
server:
|
30
|
+
- YTS/1.20.7
|
31
|
+
age:
|
32
|
+
- '2'
|
33
|
+
connection:
|
34
|
+
- close
|
35
|
+
body: ! '{"query":{"count":1,"created":"2012-01-14T00:15:54Z","lang":"en-US","results":{"place":{"woeid":"12786794"}}}}'
|
36
|
+
http_version: '1.1'
|
37
|
+
recorded_at: Sat, 14 Jan 2012 00:15:54 GMT
|
38
|
+
- request:
|
39
|
+
method: get
|
40
|
+
uri: http://weather.yahooapis.com/forecastrss?w=12786794&u=f
|
41
|
+
body: ''
|
42
|
+
headers:
|
43
|
+
accept:
|
44
|
+
- ! '*/*; q=0.5, application/xml'
|
45
|
+
accept-encoding:
|
46
|
+
- gzip, deflate
|
47
|
+
user-agent:
|
48
|
+
- Ruby
|
49
|
+
response:
|
50
|
+
status:
|
51
|
+
code: 200
|
52
|
+
message: OK
|
53
|
+
headers:
|
54
|
+
date:
|
55
|
+
- Sat, 14 Jan 2012 00:15:54 GMT
|
56
|
+
cache-control:
|
57
|
+
- public, max-age=1800
|
58
|
+
expires:
|
59
|
+
- Sat, 14 Jan 2012 00:45:54 GMT
|
60
|
+
vary:
|
61
|
+
- Accept-Encoding
|
62
|
+
content-type:
|
63
|
+
- text/xml;charset=UTF-8
|
64
|
+
content-encoding:
|
65
|
+
- gzip
|
66
|
+
age:
|
67
|
+
- '0'
|
68
|
+
transfer-encoding:
|
69
|
+
- chunked
|
70
|
+
connection:
|
71
|
+
- keep-alive
|
72
|
+
server:
|
73
|
+
- YTS/1.19.8
|
74
|
+
body: !binary |-
|
75
|
+
H4sIAAAAAAAAA8RVS2/jNhA+x79iol7aIhYly04cQ9Zi1wtj0eQQ1AmKYrEw
|
76
|
+
aImRiKVIgaTi9b/vUC8/UhQ9tRdJ5Ly+mflmFH/4UQp4Y9pwJZde6AceMJmq
|
77
|
+
jMt86b08r8dzD4ylMqNCSbb0Dsx48CEZXV3F2pij5cRZoi9pFoc9o7ZgeukV
|
78
|
+
1lYLQvDa7+78Ay2U8lNVEmkIeiDh0TBnarDZ7/f+PvKVzskkCCIShATFZJ+b
|
79
|
+
+XRbKfOT5zBcxWlBpWTCHUax5Vaw5E8X4hr+aCPCGB4Z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RbNQSZvgty3weZzvogTVd75y62c57X
|
96
|
+
PANunpgu6SMO19J7pcIwLxkq77xug3AbTrd32yDYNqPlzJr1064dMvzuY9dt
|
97
|
+
fF2Px0ArPh8qTNPpscEIomz2OcvQtJbfsUOOpi4LrFh4uwhxyKbwtHluR248
|
98
|
+
TkZ/AQAA//8DADeGX0EUCQAA
|
99
|
+
http_version: '1.1'
|
100
|
+
recorded_at: Sat, 14 Jan 2012 00:15:54 GMT
|
101
|
+
recorded_with: VCR 2.0.0.rc1
|
@@ -0,0 +1,38 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: post
|
5
|
+
uri: https://query.yahooapis.com/v1/public/yql
|
6
|
+
body: q=select+woeid+from+geo.places+where+text+%3D+%2766206%2C+usa%27&env=http://datatables.org/alltables.env&format=json
|
7
|
+
headers:
|
8
|
+
accept:
|
9
|
+
- ! '*/*'
|
10
|
+
user-agent:
|
11
|
+
- Ruby
|
12
|
+
connection:
|
13
|
+
- close
|
14
|
+
response:
|
15
|
+
status:
|
16
|
+
code: 200
|
17
|
+
message: OK
|
18
|
+
headers:
|
19
|
+
access-control-allow-origin:
|
20
|
+
- ! '*'
|
21
|
+
cache-control:
|
22
|
+
- public, max-age=86400, stale-while-revalidate=86400
|
23
|
+
content-type:
|
24
|
+
- application/json;charset=utf-8
|
25
|
+
vary:
|
26
|
+
- Accept-Encoding
|
27
|
+
date:
|
28
|
+
- Sat, 14 Jan 2012 00:15:52 GMT
|
29
|
+
server:
|
30
|
+
- YTS/1.20.7
|
31
|
+
age:
|
32
|
+
- '2'
|
33
|
+
connection:
|
34
|
+
- close
|
35
|
+
body: ! '{"query":{"count":1,"created":"2012-01-14T00:15:53Z","lang":"en-US","results":{"place":{"woeid":"12786794"}}}}'
|
36
|
+
http_version: '1.1'
|
37
|
+
recorded_at: Sat, 14 Jan 2012 00:15:53 GMT
|
38
|
+
recorded_with: VCR 2.0.0.rc1
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Yweather::Astronomy do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
@client ||= Yweather::Client.new
|
7
|
+
@response ||= @client.get_response_for_woeid(default_woeid)
|
8
|
+
@astronomy = @response.astronomy
|
9
|
+
end
|
10
|
+
|
11
|
+
context "accessors" do
|
12
|
+
[:sunrise, :sunset].each do |acc|
|
13
|
+
it "reads and writes :#{acc}", :vcr => {:cassette_name => "valid_weather_transaction"} do
|
14
|
+
has_rw_accessor(@astronomy, acc)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
it "has a valid sunrise", :vcr => {:cassette_name => "valid_weather_transaction"} do
|
20
|
+
@astronomy.sunrise.should_not be_nil
|
21
|
+
end
|
22
|
+
|
23
|
+
it "has a valid sunset", :vcr => {:cassette_name => "valid_weather_transaction"} do
|
24
|
+
@astronomy.sunset.should_not be_nil
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Yweather::Atmosphere do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
@client ||= Yweather::Client.new
|
7
|
+
@response ||= @client.get_response_for_woeid(default_woeid)
|
8
|
+
@atmosphere = @response.atmosphere
|
9
|
+
end
|
10
|
+
|
11
|
+
context "accessors" do
|
12
|
+
[:humidity, :visibility, :pressure, :barometer].each do |acc|
|
13
|
+
it "reads and writes :#{acc}", :vcr => {:cassette_name => "valid_weather_transaction"} do
|
14
|
+
has_rw_accessor(@atmosphere, acc)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
[:humidity, :visibility, :pressure, :barometer].each do |acc|
|
20
|
+
it "has a valid #{acc}", :vcr => {:cassette_name => "valid_weather_transaction"} do
|
21
|
+
@atmosphere.send(acc).should_not be_nil
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Yweather::Client do
|
4
|
+
|
5
|
+
before do
|
6
|
+
@client ||= Yweather::Client.new
|
7
|
+
end
|
8
|
+
|
9
|
+
context "using valid data" do
|
10
|
+
it "has a readonly :response accessor", :vcr => {:cassette_name => "valid_weather_transaction"} do
|
11
|
+
has_readonly_accessor(@client, :response)
|
12
|
+
end
|
13
|
+
|
14
|
+
it "converts a ZIPCODE to a WOEID", :vcr => {:cassette_name => "valid_woeid_conversion_transaction"} do
|
15
|
+
response = @client.send(:woeid_from_zipcode, default_zipcode)
|
16
|
+
response.should == default_woeid.to_s
|
17
|
+
end
|
18
|
+
|
19
|
+
it "pulls the weather feed as XML for a given WOEID", :vcr => {:cassette_name => "valid_weather_transaction"} do
|
20
|
+
xml = @client.get_feed_for_woeid(default_woeid, :format => :xml)
|
21
|
+
is_xml?(xml).should be_true
|
22
|
+
end
|
23
|
+
|
24
|
+
it "pulls the weather feed as JSON for a given WOEID", :vcr => {:cassette_name => "valid_weather_transaction"} do
|
25
|
+
json = @client.get_feed_for_woeid(default_woeid, :format => :json)
|
26
|
+
is_json?(json).should be_true
|
27
|
+
end
|
28
|
+
|
29
|
+
it "pulls the weather feed as JSON for a given ZIPCODE", :vcr => {:cassette_name => "valid_weather_transaction_with_zipcode_conversion"} do
|
30
|
+
json = @client.get_feed_for_zipcode(default_zipcode, :format => :json)
|
31
|
+
is_json?(json).should be_true
|
32
|
+
end
|
33
|
+
|
34
|
+
it "gets the weather as a Yweather::Response object for WOEID", :vcr => {:cassette_name => "valid_weather_transaction"} do
|
35
|
+
response = @client.get_response_for_woeid(default_woeid)
|
36
|
+
response.is_a?(Yweather::Response).should be_true
|
37
|
+
end
|
38
|
+
|
39
|
+
it "gets the weather as a Yweather::Response object for ZIPCODE", :vcr => {:cassette_name => "valid_weather_transaction_with_zipcode_conversion"} do
|
40
|
+
response = @client.get_response_for_zipcode(default_zipcode)
|
41
|
+
response.is_a?(Yweather::Response).should be_true
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context "using invalid data" do
|
46
|
+
it "fails to convert a ZIPCODE to a WOEID", :vcr => {:cassette_name => "invalid_woeid_conversion_transaction"} do
|
47
|
+
expect {
|
48
|
+
@client.send(:woeid_from_zipcode, 292929)
|
49
|
+
}.should raise_error Yweather::YweatherException
|
50
|
+
end
|
51
|
+
|
52
|
+
it "fails to pull the weather feed", :vcr => {:cassette_name => "invalid_weather_transaction"} do
|
53
|
+
expect {
|
54
|
+
@client.get_feed_for_woeid('abadwoeid')
|
55
|
+
}.should raise_error Yweather::YweatherException
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|