barometer-yahoo 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0e705c770ff7bc4657e4c4723756e5c7837fbf7c
4
+ data.tar.gz: 413fa838c3ee8766d13681f8b9f3e63e43b9eebf
5
+ SHA512:
6
+ metadata.gz: 1d2ee8e60157f5164a4bab506b6e14698b227b6499e2390424be9e50aaf3451134a8c26b658c09c7cdf5e9234c8c545ef9f06bc23cd10c56ec0fa13e7c408623
7
+ data.tar.gz: 4d6eb8f33c5fc6bc9409a0ca79e63b8b25002e8d2f8a46bc7086dd68b165e26aa0ece0c115cd168623c0a55e4ddebc8bae4c6336c4695b5abbcbc3355a2cbb28
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
@@ -0,0 +1,9 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1
4
+ - 2.0
5
+ - 1.9.3
6
+ script: 'bundle exec rake'
7
+ branches:
8
+ only:
9
+ - master
data/Gemfile ADDED
@@ -0,0 +1,16 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
3
+
4
+ gem 'rake'
5
+
6
+ group :development, :test do
7
+ gem 'pry'
8
+ gem 'rspec', '>= 2.11'
9
+ end
10
+
11
+ group :test do
12
+ gem 'barometer-support', '>= 0.0.3'
13
+ gem 'multi_json'
14
+ gem 'vcr'
15
+ gem 'webmock'
16
+ end
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Mark Gangl
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,55 @@
1
+ # Barometer::Yahoo
2
+
3
+ [![Build Status](https://travis-ci.org/attack/barometer-yahoo.png?branch=master)](https://travis-ci.org/attack/barometer-yahoo)
4
+ [![Gem Version](https://badge.fury.io/rb/barometer-yahoo.png)](http://badge.fury.io/rb/barometer-yahoo)
5
+ [![Code Climate](https://codeclimate.com/github/attack/barometer-yahoo.png)](https://codeclimate.com/github/attack/barometer-yahoo)
6
+
7
+ A wrapper for the Yahoo weather API. This wrapper is
8
+ barometer compatiable and can be used with or without barometer.
9
+
10
+ ## Usage
11
+
12
+ This wrapper was designed to be used via [Barometer](https://github.com/attack/barometer), or on its own.
13
+
14
+ ### Directly
15
+
16
+ By using this wrapper directly, you lose any Barometer aggregation and
17
+ failover capabilities. Barometer is still dependency to provide a
18
+ framework for query conversion, weather service integration and data
19
+ processing.
20
+
21
+ ```ruby
22
+ query = Barometer::Query.new('42.7243,-73.6927')
23
+ result = Barometer::Yahoo.call(query)
24
+ puts result.current.temperature.c
25
+ ```
26
+
27
+ ### via Barometer
28
+
29
+ Barometer is a weather service framework, providing aggregation and failover
30
+ capabilities. To make Yahoo available to Barometer, you must register
31
+ it as an available weather service.
32
+
33
+ ```ruby
34
+ Barometer::WeatherService.register(:yahoo, Barometer::Yahoo)
35
+ ```
36
+
37
+ Then follow the instructions provided by [Barometer](https://github.com/attack/barometer).
38
+
39
+ ## Contributing
40
+
41
+ 1. Fork it
42
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
43
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
44
+ 4. Push to the branch (`git push origin my-new-feature`)
45
+ 5. Create new Pull Request
46
+
47
+ ## Links
48
+
49
+ * repo: http://github.com/attack/barometer-yahoo
50
+ * travis ci: https://travis-ci.org/attack/barometer-yahoo
51
+ * code climate: https://codeclimate.com/github/attack/barometer-yahoo
52
+
53
+ ## Copyright
54
+
55
+ Copyright (c) 2009-2014 Mark Gangl. See LICENSE for details.
@@ -0,0 +1,9 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec) do |spec|
5
+ spec.pattern = 'spec/**/*_spec.rb'
6
+ spec.rspec_opts = ['--color']
7
+ end
8
+
9
+ task default: :spec
@@ -0,0 +1,24 @@
1
+ # encoding: utf-8
2
+ $:.push File.expand_path('../lib', __FILE__)
3
+ require 'barometer/yahoo/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'barometer-yahoo'
7
+ spec.version = Barometer::Yahoo::VERSION
8
+ spec.authors = ['Mark Gangl']
9
+ spec.email = ['mark@attackcorp.com']
10
+ spec.description = 'A barometer adapter for Yahoo weather'
11
+ spec.summary = spec.description
12
+ spec.homepage = 'https://github.com/attack/barometer-yahoo'
13
+ spec.license = 'MIT'
14
+
15
+ spec.platform = Gem::Platform::RUBY
16
+ spec.required_ruby_version = '>= 1.9.3'
17
+
18
+ spec.files = `git ls-files`.split($/)
19
+ spec.test_files = spec.files.grep(%r{^spec/})
20
+ spec.require_paths = ['lib']
21
+
22
+ spec.add_dependency 'barometer', '~> 0.9.7'
23
+ spec.add_development_dependency 'bundler'
24
+ end
@@ -0,0 +1,27 @@
1
+ require 'barometer'
2
+ require_relative 'yahoo/version'
3
+ require_relative 'yahoo/api'
4
+ require_relative 'yahoo/response'
5
+
6
+ module Barometer
7
+ class Yahoo
8
+ def self.call(query, config={})
9
+ Yahoo.new(query).measure!
10
+ end
11
+
12
+ def initialize(query)
13
+ @query = query
14
+ end
15
+
16
+ def measure!
17
+ api = Yahoo::Api.new(query)
18
+ Yahoo::Response.new.parse(api.get)
19
+ end
20
+
21
+ private
22
+
23
+ attr_reader :query
24
+ end
25
+ end
26
+
27
+ Barometer::WeatherService.register(:yahoo, Barometer::Yahoo)
@@ -0,0 +1,19 @@
1
+ require_relative 'query'
2
+
3
+ module Barometer
4
+ class Yahoo
5
+ class Api < Utils::Api
6
+ def initialize(query)
7
+ @query = Yahoo::Query.new(query)
8
+ end
9
+
10
+ def url
11
+ 'http://weather.yahooapis.com/forecastrss'
12
+ end
13
+
14
+ def unwrap_nodes
15
+ ['rss', 'channel']
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,40 @@
1
+ require 'delegate'
2
+
3
+ module Barometer
4
+ class Yahoo
5
+ class Query < SimpleDelegator
6
+ attr_reader :converted_query
7
+
8
+ def self.accepted_formats
9
+ [:zipcode, :weather_id, :woe_id]
10
+ end
11
+
12
+ def initialize(query)
13
+ super
14
+ @converted_query = convert_query
15
+ end
16
+
17
+ def to_param
18
+ {u: unit_type}.merge(format_query)
19
+ end
20
+
21
+ private
22
+
23
+ def convert_query
24
+ convert!(*self.class.accepted_formats)
25
+ end
26
+
27
+ def format_query
28
+ if converted_query.format == :woe_id
29
+ { w: converted_query.q }
30
+ else
31
+ { p: converted_query.q }
32
+ end
33
+ end
34
+
35
+ def unit_type
36
+ converted_query.metric? ? 'c' : 'f'
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,37 @@
1
+ require_relative 'response/timezone'
2
+ require_relative 'response/location'
3
+ require_relative 'response/current_weather'
4
+ require_relative 'response/forecasted_weather'
5
+
6
+ module Barometer
7
+ class Yahoo
8
+ class Response
9
+ def initialize
10
+ @response = Barometer::Response.new
11
+ end
12
+
13
+ def parse(payload)
14
+ response.add_query(payload.query)
15
+
16
+ response.timezone = Yahoo::Response::TimeZone.new(payload).parse
17
+ response.location = Yahoo::Response::Location.new(payload).parse
18
+ response.current = Yahoo::Response::CurrentWeather.new(payload, timezone).parse
19
+ response.forecast = Yahoo::Response::ForecastedWeather.new(payload, timezone, current_sun).parse
20
+
21
+ response
22
+ end
23
+
24
+ private
25
+
26
+ attr_reader :response
27
+
28
+ def timezone
29
+ response.timezone
30
+ end
31
+
32
+ def current_sun
33
+ response.current.sun
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,84 @@
1
+ require_relative 'sun'
2
+ require 'ostruct'
3
+
4
+ module Barometer
5
+ class Yahoo
6
+ class Response
7
+ class CurrentWeather
8
+ def initialize(payload, timezone)
9
+ @payload = payload
10
+ @timezone = timezone
11
+ @current = Barometer::Response::Current.new # needs query or metric
12
+ end
13
+
14
+ def parse
15
+ current.observed_at = observed_at, '%a, %d %b %Y %l:%M %P %Z'
16
+ current.stale_at = stale_at
17
+ current.condition = condition
18
+ current.icon = icon
19
+ current.temperature = temperature
20
+ current.humidity = humidity
21
+ current.pressure = pressure
22
+ current.visibility = visibility
23
+ current.wind_chill = wind_chill
24
+ current.wind = wind
25
+ current.sun = Yahoo::Response::Sun.new(payload, base_time).parse
26
+
27
+ current
28
+ end
29
+
30
+ private
31
+
32
+ attr_reader :payload, :timezone, :current
33
+
34
+ def units
35
+ payload.units
36
+ end
37
+
38
+ def base_time
39
+ OpenStruct.new(timezone: timezone, base: current.observed_at)
40
+ end
41
+
42
+ def observed_at
43
+ payload.fetch('item', 'pubDate')
44
+ end
45
+
46
+ def stale_at
47
+ (current.observed_at + (60 * 60 * 1)) if current.observed_at
48
+ end
49
+
50
+ def condition
51
+ payload.fetch('item', 'condition', '@text')
52
+ end
53
+
54
+ def icon
55
+ payload.fetch('item', 'condition', '@code')
56
+ end
57
+
58
+ def temperature
59
+ [units, payload.fetch('item', 'condition', '@temp')]
60
+ end
61
+
62
+ def humidity
63
+ payload.fetch('atmosphere', '@humidity')
64
+ end
65
+
66
+ def pressure
67
+ [units, payload.fetch('atmosphere', '@pressure')]
68
+ end
69
+
70
+ def visibility
71
+ [units, payload.fetch('atmosphere', '@visibility')]
72
+ end
73
+
74
+ def wind_chill
75
+ [units, payload.fetch('wind', '@chill')]
76
+ end
77
+
78
+ def wind
79
+ [units, payload.fetch('wind', '@speed'), payload.fetch('wind', '@direction').to_f]
80
+ end
81
+ end
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,69 @@
1
+ module Barometer
2
+ class Yahoo
3
+ class Response
4
+ class ForecastedWeather
5
+ def initialize(payload, timezone, current_sun)
6
+ @payload = payload
7
+ @timezone = timezone
8
+ @current_sun = current_sun
9
+ @predictions = Barometer::Response::PredictionCollection.new
10
+ end
11
+
12
+ def parse
13
+ each_prediction do |prediction, forecast_payload|
14
+ prediction.date = date(forecast_payload), timezone
15
+ prediction.icon = icon(forecast_payload)
16
+ prediction.condition = condition(forecast_payload)
17
+ prediction.high = high(forecast_payload)
18
+ prediction.low = low(forecast_payload)
19
+ prediction.sun = sun(forecast_payload, prediction.starts_at, prediction.ends_at)
20
+ end
21
+
22
+ predictions
23
+ end
24
+
25
+ private
26
+
27
+ attr_reader :payload, :timezone, :predictions, :current_sun
28
+
29
+ def units
30
+ payload.units
31
+ end
32
+
33
+ def each_prediction
34
+ payload.fetch_each('item', 'forecast') do |forecast_payload|
35
+ predictions.build do |prediction|
36
+ yield prediction, forecast_payload
37
+ end
38
+ end
39
+ end
40
+
41
+ def date(forecast_payload)
42
+ forecast_payload.fetch('@date')
43
+ end
44
+
45
+ def icon(forecast_payload)
46
+ forecast_payload.fetch('@code')
47
+ end
48
+
49
+ def condition(forecast_payload)
50
+ forecast_payload.fetch('@text')
51
+ end
52
+
53
+ def high(forecast_payload)
54
+ [units, forecast_payload.fetch('@high')]
55
+ end
56
+
57
+ def low(forecast_payload)
58
+ [units, forecast_payload.fetch('@low')]
59
+ end
60
+
61
+ def sun(forecast_payload, starts_at, ends_at)
62
+ utc_rise_time = Utils::Time.utc_merge_base_plus_time(starts_at, current_sun.rise)
63
+ utc_set_time = Utils::Time.utc_merge_base_plus_time(ends_at, current_sun.set)
64
+ Data::Sun.new(rise: utc_rise_time, set: utc_set_time)
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,45 @@
1
+ module Barometer
2
+ class Yahoo
3
+ class Response
4
+ class Location
5
+ def initialize(payload)
6
+ @payload = payload
7
+ end
8
+
9
+ def parse
10
+ Data::Location.new(
11
+ city: city,
12
+ state_code: state_code,
13
+ country_code: country_code,
14
+ latitude: latitude,
15
+ longitude: longitude
16
+ )
17
+ end
18
+
19
+ private
20
+
21
+ attr_reader :payload
22
+
23
+ def city
24
+ payload.fetch('location', '@city')
25
+ end
26
+
27
+ def state_code
28
+ payload.fetch('location', '@region')
29
+ end
30
+
31
+ def country_code
32
+ payload.fetch('location', '@country')
33
+ end
34
+
35
+ def latitude
36
+ payload.fetch('item', 'lat')
37
+ end
38
+
39
+ def longitude
40
+ payload.fetch('item', 'long')
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,41 @@
1
+ module Barometer
2
+ class Yahoo
3
+ class Response
4
+ class Sun
5
+ def initialize(payload, base_time)
6
+ @payload = payload
7
+ @base_time = base_time
8
+ end
9
+
10
+ def parse
11
+ return if local_rise_time.nil? || local_set_time.nil?
12
+ Data::Sun.new(rise: utc_rise_time, set: utc_set_time)
13
+ end
14
+
15
+ private
16
+
17
+ attr_reader :payload, :base_time
18
+
19
+ def local_rise_time
20
+ @local_rise_time ||= Utils::Time.parse(payload.fetch('astronomy', '@sunrise'))
21
+ end
22
+
23
+ def local_set_time
24
+ @local_set_time ||= Utils::Time.parse(payload.fetch('astronomy', '@sunset'))
25
+ end
26
+
27
+ def utc_rise_time
28
+ Utils::Time.utc_from_base_plus_local_time(
29
+ base_time.timezone, base_time.base, local_rise_time.hour, local_rise_time.min
30
+ )
31
+ end
32
+
33
+ def utc_set_time
34
+ Utils::Time.utc_from_base_plus_local_time(
35
+ base_time.timezone, base_time.base, local_set_time.hour, local_set_time.min
36
+ )
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,13 @@
1
+ module Barometer
2
+ class Yahoo
3
+ class Response
4
+ class TimeZone < Barometer::WeatherService::Response::TimeZone
5
+ private
6
+
7
+ def time_zone
8
+ payload.using(/ ([A-Z]+)$/).fetch('item', 'pubDate')
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,5 @@
1
+ module Barometer
2
+ class Yahoo
3
+ VERSION = '0.0.1'
4
+ end
5
+ end
@@ -0,0 +1 @@
1
+ {"http_interactions":[{"request":{"method":"get","uri":"http://weather.yahooapis.com/forecastrss?p=90210&u=c","body":{"encoding":"UTF-8","string":""},"headers":{"User-Agent":["HTTPClient/1.0 (2.3.4.1, ruby 2.1.1 (2014-02-24))"],"Accept":["*/*"],"Date":["Tue, 06 May 2014 12:42:01 GMT"]}},"response":{"status":{"code":200,"message":"OK"},"headers":{"Date":["Tue, 06 May 2014 12:42:01 GMT"],"P3p":["policyref=\"http://info.yahoo.com/w3c/p3p.xml\", CP=\"CAO DSP COR CUR ADM DEV TAI PSA PSD IVAi IVDi CONi TELo OTPi OUR DELi SAMi OTRi UNRi PUBi IND PHY ONL UNI PUR FIN COM NAV INT DEM CNT STA POL HEA PRE LOC GOV\""],"Cache-Control":["max-age=200, public"],"Vary":["Accept-Encoding"],"Content-Length":["2771"],"Content-Type":["text/xml;charset=UTF-8"],"Age":["0"],"Via":["http/1.1 ats13.weather.bf1.yahoo.com (ApacheTrafficServer/4.0.2 [cMsSfW]), http/1.1 r22.ycpi.bf1.yahoo.net (ApacheTrafficServer/4.0.2 [cMsSfW])"],"Server":["ATS"],"Connection":["keep-alive"]},"body":{"encoding":"UTF-8","string":"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?>\n\t\t<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#\">\n\t\t\t<channel>\n\t\t\n<title>Yahoo! Weather - Beverly Hills, CA</title>\n<link>http://us.rd.yahoo.com/dailynews/rss/weather/Beverly_Hills__CA/*http://weather.yahoo.com/forecast/USCA0090_c.html</link>\n<description>Yahoo! Weather for Beverly Hills, CA</description>\n<language>en-us</language>\n<lastBuildDate>Tue, 06 May 2014 4:51 am PDT</lastBuildDate>\n<ttl>60</ttl>\n<yweather:location city=\"Beverly Hills\" region=\"CA\" country=\"US\"/>\n<yweather:units temperature=\"C\" distance=\"km\" pressure=\"mb\" speed=\"km/h\"/>\n<yweather:wind chill=\"14\" direction=\"40\" speed=\"4.83\" />\n<yweather:atmosphere humidity=\"69\" visibility=\"16.09\" pressure=\"1010.8\" rising=\"0\" />\n<yweather:astronomy sunrise=\"5:59 am\" sunset=\"7:40 pm\"/>\n<image>\n<title>Yahoo! Weather</title>\n<width>142</width>\n<height>18</height>\n<link>http://weather.yahoo.com</link>\n<url>http://l.yimg.com/a/i/brand/purplelogo//uh/us/news-wea.gif</url>\n</image>\n<item>\n<title>Conditions for Beverly Hills, CA at 4:51 am PDT</title>\n<geo:lat>34.08</geo:lat>\n<geo:long>-118.4</geo:long>\n<link>http://us.rd.yahoo.com/dailynews/rss/weather/Beverly_Hills__CA/*http://weather.yahoo.com/forecast/USCA0090_c.html</link>\n<pubDate>Tue, 06 May 2014 4:51 am PDT</pubDate>\n<yweather:condition text=\"Partly Cloudy\" code=\"29\" temp=\"14\" date=\"Tue, 06 May 2014 4:51 am PDT\" />\n<description><![CDATA[\n<img src=\"http://l.yimg.com/a/i/us/we/52/29.gif\"/><br />\n<b>Current Conditions:</b><br />\nPartly Cloudy, 14 C<BR />\n<BR /><b>Forecast:</b><BR />\nTue - Partly Cloudy. High: 21 Low: 12<br />\nWed - Sunny. High: 22 Low: 12<br />\nThu - AM Clouds/PM Sun. High: 21 Low: 13<br />\nFri - Sunny. High: 24 Low: 14<br />\nSat - Sunny. High: 26 Low: 16<br />\n<br />\n<a href=\"http://us.rd.yahoo.com/dailynews/rss/weather/Beverly_Hills__CA/*http://weather.yahoo.com/forecast/USCA0090_c.html\">Full Forecast at Yahoo! Weather</a><BR/><BR/>\n(provided by <a href=\"http://www.weather.com\" >The Weather Channel</a>)<br/>\n]]></description>\n<yweather:forecast day=\"Tue\" date=\"6 May 2014\" low=\"12\" high=\"21\" text=\"Partly Cloudy\" code=\"30\" />\n<yweather:forecast day=\"Wed\" date=\"7 May 2014\" low=\"12\" high=\"22\" text=\"Sunny\" code=\"32\" />\n<yweather:forecast day=\"Thu\" date=\"8 May 2014\" low=\"13\" high=\"21\" text=\"AM Clouds/PM Sun\" code=\"30\" />\n<yweather:forecast day=\"Fri\" date=\"9 May 2014\" low=\"14\" high=\"24\" text=\"Sunny\" code=\"32\" />\n<yweather:forecast day=\"Sat\" date=\"10 May 2014\" low=\"16\" high=\"26\" text=\"Sunny\" code=\"32\" />\n<guid isPermaLink=\"false\">USCA0090_2014_05_10_7_00_PDT</guid>\n</item>\n</channel>\n</rss>\n\n<!-- fan1581.sports.bf1.yahoo.com Tue May 6 12:42:01 PST 2014 -->\n"},"http_version":null},"recorded_at":"Tue, 06 May 2014 12:42:01 GMT"}],"recorded_with":"VCR 2.9.0"}
@@ -0,0 +1,22 @@
1
+ require 'rspec'
2
+ require 'pry'
3
+ require 'vcr'
4
+ require 'webmock/rspec'
5
+ require 'barometer/support'
6
+
7
+ require_relative '../lib/barometer/yahoo'
8
+
9
+ Dir['./spec/support/**/*.rb'].sort.each {|f| require f}
10
+
11
+ VCR.configure do |config|
12
+ config.cassette_library_dir = 'spec/cassettes'
13
+ config.hook_into :webmock
14
+ config.default_cassette_options = { record: :none, serialize_with: :json }
15
+ config.configure_rspec_metadata!
16
+ end
17
+
18
+ RSpec.configure do |config|
19
+ config.treat_symbols_as_metadata_keys_with_true_values = true
20
+ config.include Barometer::Support::Matchers
21
+ config.include Barometer::Support::Factory
22
+ end
@@ -0,0 +1,73 @@
1
+ require_relative '../spec_helper'
2
+
3
+ module Barometer
4
+ describe Yahoo::Response do
5
+ it "parses the timezones correctly for current weather" do
6
+ payload = Barometer::Utils::Payload.new({
7
+ "item" => {
8
+ "pubDate" => "Sun, 14 Apr 2013 1:24 pm PDT"
9
+ }
10
+ })
11
+ response = Yahoo::Response.new.parse(payload)
12
+
13
+ utc_observed_at = Time.utc(2013,4,14,20,24,0)
14
+ utc_stale_at = Time.utc(2013,4,14,21,24,0)
15
+
16
+ expect( response.current.observed_at.utc ).to eq utc_observed_at
17
+ expect( response.current.stale_at.utc ).to eq utc_stale_at
18
+ expect( response.timezone.to_s ).to eq 'PDT'
19
+ end
20
+
21
+ it "parses the timezones correctly for forecasted weather" do
22
+ payload = Barometer::Utils::Payload.new({
23
+ "item" => {
24
+ "pubDate" => "Sun, 14 Apr 2013 1:24 pm PDT",
25
+ "forecast" => [
26
+ {
27
+ "@date" => "14 Apr 2013"
28
+ }
29
+ ]
30
+ },
31
+ "astronomy" => {
32
+ "@sunrise" => "6:44 am",
33
+ "@sunset" => "5:32 pm"
34
+ }
35
+ })
36
+ response = Yahoo::Response.new.parse(payload)
37
+
38
+ utc_starts_at = Time.utc(2013,4,14,7,0,0)
39
+ utc_ends_at = Time.utc(2013,4,15,6,59,59)
40
+
41
+ expect( response.forecast[0].starts_at.utc ).to eq utc_starts_at
42
+ expect( response.forecast[0].ends_at.utc ).to eq utc_ends_at
43
+ end
44
+
45
+ it "parses sun timezones correctly" do
46
+ payload = Barometer::Utils::Payload.new({
47
+ "item" => {
48
+ "pubDate" => "Sun, 14 Apr 2013 1:24 pm PDT",
49
+ "forecast" => [
50
+ {
51
+ "@date" => "15 Apr 2013"
52
+ }
53
+ ]
54
+ },
55
+ "astronomy" => {
56
+ "@sunrise" => "6:44 am",
57
+ "@sunset" => "5:32 pm"
58
+ }
59
+ })
60
+ response = Yahoo::Response.new.parse(payload)
61
+
62
+ utc_current_sun_rise = Time.utc(2013,4,14,13,44,0)
63
+ utc_current_sun_set = Time.utc(2013,4,15,0,32,0)
64
+ utc_forecast_sun_rise = Time.utc(2013,4,15,13,44,0)
65
+ utc_forecast_sun_set = Time.utc(2013,4,16,0,32,0)
66
+
67
+ expect( response.current.sun.rise.utc ).to eq utc_current_sun_rise
68
+ expect( response.current.sun.set.utc ).to eq utc_current_sun_set
69
+ expect( response.forecast[0].sun.rise ).to eq utc_forecast_sun_rise
70
+ expect( response.forecast[0].sun.set.utc ).to eq utc_forecast_sun_set
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,62 @@
1
+ require_relative 'spec_helper'
2
+
3
+ module Barometer
4
+ describe Yahoo, vcr: {
5
+ cassette_name: 'Yahoo'
6
+ } do
7
+ it "auto-registers this weather service as :yahoo" do
8
+ Barometer::WeatherService.source(:yahoo).should == Barometer::Yahoo
9
+ end
10
+
11
+ describe ".call" do
12
+ let(:converted_query) { Barometer::ConvertedQuery.new('90210', :zipcode, :metric) }
13
+ let(:query) { build_query.tap{|q|q.stub(:convert! => converted_query)} }
14
+
15
+ subject { Barometer::Yahoo.call(query) }
16
+
17
+ it "asks the query to convert to accepted formats" do
18
+ query.should_receive(:convert!).with(:zipcode, :weather_id, :woe_id)
19
+ subject
20
+ end
21
+
22
+ it "includes the expected data" do
23
+ subject.query.should == '90210'
24
+ subject.format.should == :zipcode
25
+ subject.should be_metric
26
+
27
+ should have_data(:current, :observed_at).as_format(:time)
28
+ should have_data(:current, :stale_at).as_format(:time)
29
+
30
+ should have_data(:current, :humidity).as_format(:float)
31
+ should have_data(:current, :condition).as_format(:string)
32
+ should have_data(:current, :icon).as_format(:number)
33
+ should have_data(:current, :temperature).as_format(:temperature)
34
+ should have_data(:current, :wind_chill).as_format(:temperature)
35
+ should have_data(:current, :wind).as_format(:vector)
36
+ should have_data(:current, :pressure).as_format(:pressure)
37
+ should have_data(:current, :visibility).as_format(:distance)
38
+ should have_data(:current, :sun, :rise).as_format(:time)
39
+ should have_data(:current, :sun, :set).as_format(:time)
40
+
41
+ should have_data(:location, :city).as_value("Beverly Hills")
42
+ should have_data(:location, :state_code).as_value("CA")
43
+ should have_data(:location, :country_code).as_value("US")
44
+ should have_data(:location, :latitude).as_value(34.08)
45
+ should have_data(:location, :longitude).as_value(-118.4)
46
+
47
+ should have_data(:timezone, :to_s).as_format(/^P[DS]T$/i)
48
+
49
+ subject.forecast.size.should == 5
50
+ should have_forecast(:starts_at).as_format(:time)
51
+ should have_forecast(:ends_at).as_format(:time)
52
+ should have_forecast(:icon).as_format(:number)
53
+ should have_forecast(:condition).as_format(:string)
54
+ should have_forecast(:high).as_format(:temperature)
55
+ should have_forecast(:low).as_format(:temperature)
56
+ should have_forecast(:sun, :rise).as_format(:time)
57
+ should have_forecast(:sun, :set).as_format(:time)
58
+ end
59
+ end
60
+
61
+ end
62
+ end
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: barometer-yahoo
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Mark Gangl
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: barometer
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.9.7
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.9.7
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: A barometer adapter for Yahoo weather
42
+ email:
43
+ - mark@attackcorp.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - ".travis.yml"
50
+ - Gemfile
51
+ - LICENSE.txt
52
+ - README.md
53
+ - Rakefile
54
+ - barometer-yahoo.gemspec
55
+ - lib/barometer/yahoo.rb
56
+ - lib/barometer/yahoo/api.rb
57
+ - lib/barometer/yahoo/query.rb
58
+ - lib/barometer/yahoo/response.rb
59
+ - lib/barometer/yahoo/response/current_weather.rb
60
+ - lib/barometer/yahoo/response/forecasted_weather.rb
61
+ - lib/barometer/yahoo/response/location.rb
62
+ - lib/barometer/yahoo/response/sun.rb
63
+ - lib/barometer/yahoo/response/timezone.rb
64
+ - lib/barometer/yahoo/version.rb
65
+ - spec/cassettes/Yahoo.json
66
+ - spec/spec_helper.rb
67
+ - spec/yahoo/response_spec.rb
68
+ - spec/yahoo_spec.rb
69
+ homepage: https://github.com/attack/barometer-yahoo
70
+ licenses:
71
+ - MIT
72
+ metadata: {}
73
+ post_install_message:
74
+ rdoc_options: []
75
+ require_paths:
76
+ - lib
77
+ required_ruby_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: 1.9.3
82
+ required_rubygems_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ requirements: []
88
+ rubyforge_project:
89
+ rubygems_version: 2.2.2
90
+ signing_key:
91
+ specification_version: 4
92
+ summary: A barometer adapter for Yahoo weather
93
+ test_files:
94
+ - spec/cassettes/Yahoo.json
95
+ - spec/spec_helper.rb
96
+ - spec/yahoo/response_spec.rb
97
+ - spec/yahoo_spec.rb