barometer 0.9.4 → 0.9.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +7 -0
  2. data/.travis.yml +2 -5
  3. data/Gemfile +11 -7
  4. data/LICENSE +1 -1
  5. data/README.md +3 -3
  6. data/barometer.gemspec +7 -10
  7. data/lib/barometer/utils/json_reader.rb +2 -3
  8. data/lib/barometer/utils/payload.rb +6 -87
  9. data/lib/barometer/utils/translations/zone_codes.yml +1 -0
  10. data/lib/barometer/version.rb +1 -1
  11. data/lib/barometer/weather_service.rb +0 -1
  12. data/spec/barometer_spec.rb +6 -0
  13. data/spec/spec_helper.rb +0 -11
  14. data/spec/utils/payload_spec.rb +20 -153
  15. data/spec/weather_services/wunderground_v1/current_response_spec.rb +5 -4
  16. data/spec/weather_services/wunderground_v1/forecast_response_spec.rb +23 -22
  17. metadata +32 -170
  18. data/.pelusa.yml +0 -7
  19. data/lib/barometer/weather_services/weather_bug.rb +0 -41
  20. data/lib/barometer/weather_services/weather_bug/current_api.rb +0 -26
  21. data/lib/barometer/weather_services/weather_bug/current_response.rb +0 -33
  22. data/lib/barometer/weather_services/weather_bug/forecast_api.rb +0 -26
  23. data/lib/barometer/weather_services/weather_bug/forecast_response.rb +0 -29
  24. data/lib/barometer/weather_services/weather_bug/query.rb +0 -42
  25. data/lib/barometer/weather_services/weather_bug/response/current_weather.rb +0 -82
  26. data/lib/barometer/weather_services/weather_bug/response/forecasted_weather.rb +0 -67
  27. data/lib/barometer/weather_services/weather_bug/response/location.rb +0 -23
  28. data/lib/barometer/weather_services/weather_bug/response/station.rb +0 -43
  29. data/lib/barometer/weather_services/weather_bug/response/sun.rb +0 -32
  30. data/lib/barometer/weather_services/weather_bug/response/time_helper.rb +0 -52
  31. data/lib/barometer/weather_services/weather_bug/response/timezone.rb +0 -15
  32. data/spec/cassettes/WeatherService_WeatherBug.json +0 -1
  33. data/spec/weather_services/weather_bug/current_response_spec.rb +0 -64
  34. data/spec/weather_services/weather_bug/forecast_response_spec.rb +0 -23
  35. data/spec/weather_services/weather_bug/query_spec.rb +0 -44
  36. data/spec/weather_services/weather_bug_spec.rb +0 -80
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f0f0ccdc7bdbe2c204520c8e83a96a65e8713218
4
+ data.tar.gz: 857448624a6845d4212d5072a04e7e7e804667d8
5
+ SHA512:
6
+ metadata.gz: e06c1684eb7a0128e885112f24a3f4be74b3232092c76518b2d2c7b9eb1908a18a76727898c2d455d9a765d992cd0246f19c6035849abb557f655f77e12183ad
7
+ data.tar.gz: 68bf94862598ae243583813e28e52437ab97b777f4dcfec2c3543786f5b479827eb580f6fcff3254f34b7a7de9e3f65b6cd082f11e35ba75e435ff3548fe283a
@@ -1,13 +1,10 @@
1
1
  language: ruby
2
+ cache: bundler
2
3
  rvm:
4
+ - 2.1.0
3
5
  - 2.0.0
4
6
  - 1.9.3
5
7
  - 1.9.2
6
- - rbx-19mode
7
- script: 'rake'
8
8
  branches:
9
9
  only:
10
10
  - master
11
- matrix:
12
- allow_failures:
13
- - rvm: rbx-19mode
data/Gemfile CHANGED
@@ -1,13 +1,17 @@
1
- source 'http://rubygems.org'
1
+ source 'https://rubygems.org'
2
2
 
3
- group :assets do
4
- platforms :rbx do
5
- gem 'pelusa'
6
- end
3
+ gemspec
4
+
5
+ gem 'rake'
6
+
7
+ group :development, :test do
8
+ gem 'rspec', '>= 2.11'
9
+ gem 'pry'
7
10
  end
8
11
 
9
12
  group :test do
13
+ gem 'barometer-support', '>= 0.0.3'
14
+ gem 'webmock'
15
+ gem 'vcr'
10
16
  gem 'coveralls', require: false
11
17
  end
12
-
13
- gemspec
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2009-2013 Mark G
1
+ Copyright (c) 2009-2014 Mark Gangl
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -19,7 +19,7 @@ support the query directly. See the "[Queries](#queries)" section for more info.
19
19
 
20
20
  ## Key Features
21
21
 
22
- * works with ruby 1.9.x, 2.0, Rubinius (see
22
+ * works with ruby 1.9.x, 2.x (see
23
23
  [Travis CI status](https://travis-ci.org/attack/barometer) to confirm)
24
24
  * supports 5 weather services, more planned
25
25
  * the same query can be used with any supported weather service
@@ -84,7 +84,7 @@ The current available sources are:
84
84
 
85
85
  * Wunderground.com (:wunderground) [default]
86
86
  * Yahoo! Weather (:yahoo)
87
- * WeatherBug.com (:weather_bug) [requires key]
87
+ * WeatherBug.com (:weather_bug) [requires key + [barometer-weather_bug gem](https://github.com/attack/barometer-weather_bug)]]
88
88
  * NOAA (:noaa)
89
89
  * Forecast.io (:forecast_io) [requires key + [barometer-forecast_io gem](https://github.com/attack/barometer-forecast_io)]
90
90
 
@@ -223,4 +223,4 @@ Thank you to these developers who have contributed. No contribution is too small
223
223
 
224
224
  ## Copyright
225
225
 
226
- Copyright (c) 2009-2013 Mark G. See LICENSE for details.
226
+ Copyright (c) 2009-2014 Mark Gangl. See LICENSE for details.
@@ -5,8 +5,8 @@ require 'barometer/version'
5
5
  Gem::Specification.new do |s|
6
6
  s.name = 'barometer'
7
7
  s.version = Barometer::VERSION
8
- s.authors = ['Mark G']
9
- s.email = ['barometer@attackcorp.com']
8
+ s.authors = ['Mark Gangl']
9
+ s.email = ['mark@attackcorp.com']
10
10
  s.description = 'A multi API consuming weather forecasting superstar.'
11
11
  s.summary = s.description
12
12
  s.homepage = 'http://github.com/attack/barometer'
@@ -18,19 +18,16 @@ Gem::Specification.new do |s|
18
18
 
19
19
  s.rdoc_options = ['--charset=UTF-8']
20
20
 
21
+ s.platform = Gem::Platform::RUBY
22
+ s.required_ruby_version = '>= 1.9.0'
23
+
21
24
  s.add_dependency 'httpclient'
22
25
  s.add_dependency 'tzinfo', '>= 0.3.14'
23
26
  s.add_dependency 'nokogiri'
24
27
  s.add_dependency 'addressable'
25
- s.add_dependency 'yajl-ruby'
26
28
  s.add_dependency 'nori'
27
- s.add_dependency 'multi_json', '~> 1.0'
28
29
  s.add_dependency 'virtus', '>= 1.0.0'
30
+ s.add_dependency 'choc_mool'
29
31
 
30
- s.add_development_dependency 'rspec', '>= 2.11'
31
- s.add_development_dependency 'webmock'
32
- s.add_development_dependency 'rake'
33
- s.add_development_dependency 'pry'
34
- s.add_development_dependency 'vcr'
35
- s.add_development_dependency 'barometer-support'
32
+ s.add_development_dependency 'bundler'
36
33
  end
@@ -1,11 +1,10 @@
1
- require 'yajl'
1
+ require 'json' unless defined?(JSON)
2
2
 
3
3
  module Barometer
4
4
  module Utils
5
5
  module JsonReader
6
6
  def self.parse(json, *nodes_to_remove)
7
- json_reader = Yajl::Parser.new
8
- output = json_reader.parse(json)
7
+ output = JSON.parse(json)
9
8
 
10
9
  nodes_to_remove.each do |node|
11
10
  output = output.fetch(node, output)
@@ -1,100 +1,19 @@
1
+ require 'delegate'
2
+ require 'choc_mool'
3
+
1
4
  module Barometer
2
5
  module Utils
3
- class Payload
4
- attr_reader :hash, :regex, :query
6
+ class Payload < SimpleDelegator
7
+ attr_reader :query
5
8
 
6
9
  def initialize(hash, query=nil)
7
- @hash = hash
8
10
  @query = query
9
- end
10
-
11
- def using(regex)
12
- @regex = regex
13
- self
14
- end
15
-
16
- def fetch(*paths)
17
- if hash
18
- result = fetch_value_or_attribute(paths)
19
- else
20
- result = nil
21
- end
22
-
23
- result = _apply_regex(result)
24
- result = _cleanup(result)
25
- result = _convert_alternate_nil_values(result)
26
-
27
- result
28
- end
29
-
30
- def each(*paths, &block)
31
- path = fetch(*paths)
32
- if path
33
- path.each do |result|
34
- result_payload = Barometer::Utils::Payload.new(result)
35
- block.call(result_payload)
36
- end
37
- end
38
- end
39
-
40
- def each_with_index(*paths, &block)
41
- fetch(*paths).each_with_index do |result, index|
42
- result_payload = Barometer::Utils::Payload.new(result)
43
- block.call(result_payload, index)
44
- end
45
- end
46
-
47
- def fetch_each(*paths, &block)
48
- each(*paths, &block)
49
- end
50
-
51
- def fetch_each_with_index(*paths, &block)
52
- each_with_index(*paths, &block)
11
+ super( ChocMool.new(hash) )
53
12
  end
54
13
 
55
14
  def units
56
15
  query.units if query
57
16
  end
58
-
59
- private
60
-
61
- def fetch_value_or_attribute(paths)
62
- result = paths.inject(hash) do |result, path|
63
- fetch_value(result, path) || fetch_attribute(result, path) || break
64
- end
65
- end
66
-
67
- def fetch_value(result, path)
68
- if result.respond_to? :fetch
69
- result.fetch(path, nil)
70
- end
71
- end
72
-
73
- def fetch_attribute(result, path)
74
- if path.to_s.start_with?('@') && result.respond_to?(:attributes)
75
- result.attributes.fetch(path.slice(1..-1))
76
- end
77
- end
78
-
79
- def _apply_regex(result)
80
- if @regex && @regex.is_a?(Regexp) && matched = result.to_s.match(@regex)
81
- result = matched[1] if matched[1]
82
- end
83
- @regex = nil
84
- result
85
- end
86
-
87
- def _cleanup(result)
88
- result.respond_to?(:strip) ? result.strip : result
89
- end
90
-
91
- def _convert_alternate_nil_values(result)
92
- if result == "NA"
93
- nil
94
- else
95
- result
96
- end
97
- end
98
17
  end
99
18
  end
100
19
  end
@@ -49,6 +49,7 @@ CET : 1
49
49
  CHADT : 13.75
50
50
  CHAST : 12.75
51
51
  CHST : 10
52
+ CIT : 8
52
53
  CKT : -10
53
54
  CLST : -3
54
55
  CLT : -4
@@ -1,3 +1,3 @@
1
1
  module Barometer
2
- VERSION = '0.9.4'
2
+ VERSION = '0.9.5'
3
3
  end
@@ -36,5 +36,4 @@ end
36
36
 
37
37
  require_relative 'weather_services/wunderground_v1'
38
38
  require_relative 'weather_services/yahoo'
39
- require_relative 'weather_services/weather_bug'
40
39
  require_relative 'weather_services/noaa'
@@ -19,6 +19,12 @@ describe Barometer do
19
19
  end
20
20
 
21
21
  describe ".timeout" do
22
+ around do |example|
23
+ cached_timeout = Barometer.timeout
24
+ example.run
25
+ Barometer.timeout = cached_timeout
26
+ end
27
+
22
28
  it "has a default value" do
23
29
  expect( Barometer.timeout ).to eq 15
24
30
  end
@@ -10,21 +10,10 @@ require 'barometer/support'
10
10
 
11
11
  require_relative '../lib/barometer'
12
12
 
13
- WEATHERBUG_CODE = Barometer::Support::KeyFileParser.find(:weather_bug, :code) || 'weatherbug'
14
- FORECAST_IO_APIKEY = Barometer::Support::KeyFileParser.find(:forecast_io, :apikey) || 'forecastio'
15
- downcased_weatherbug_code = WEATHERBUG_CODE.to_s
16
- downcased_weatherbug_code[0] = WEATHERBUG_CODE.to_s[0..0].downcase
17
-
18
13
  VCR.configure do |config|
19
14
  config.cassette_library_dir = 'spec/cassettes'
20
15
  config.hook_into :webmock
21
16
  config.default_cassette_options = { record: :none, serialize_with: :json }
22
-
23
- config.filter_sensitive_data('WEATHERBUG_CODE') { WEATHERBUG_CODE.to_s }
24
- # weather bug uses api as host name. this is downcased when the request it made
25
- config.filter_sensitive_data('WEATHERBUG_CODE') { downcased_weatherbug_code }
26
- config.filter_sensitive_data('FORECAST_IO_APIKEY') { FORECAST_IO_APIKEY.to_s }
27
-
28
17
  config.configure_rspec_metadata!
29
18
  end
30
19
 
@@ -1,168 +1,35 @@
1
1
  require_relative '../spec_helper'
2
2
 
3
- describe Barometer::Utils::Payload do
4
- describe "#fetch" do
5
- it "returns the value for the key provided" do
6
- hash = {one: 1}
7
- parser = Barometer::Utils::Payload.new(hash)
8
- parser.fetch(:one).should == 1
9
- end
10
-
11
- it "returns nil when the key cannot be found" do
12
- hash = {}
13
- parser = Barometer::Utils::Payload.new(hash)
14
- parser.fetch(:one).should be_nil
15
- end
16
-
17
- it "traverses multiple levels to get the value" do
18
- hash = {one: {two: {three: 3}}}
19
- parser = Barometer::Utils::Payload.new(hash)
20
- parser.fetch(:one, :two, :three).should == 3
21
- end
22
-
23
- it "returns nil when any level cannot be found" do
24
- hash = {one: {two: {three: {four: 4}}}}
25
- parser = Barometer::Utils::Payload.new(hash)
26
- parser.fetch(:one, :too, :three).should be_nil
27
- end
28
-
29
- it "returns nil when the starting value is nil" do
30
- hash = nil
31
- parser = Barometer::Utils::Payload.new(hash)
32
- parser.fetch(:one).should be_nil
33
- end
34
-
35
- it "returns a stripped result" do
36
- hash = {one: " one "}
37
- parser = Barometer::Utils::Payload.new(hash)
38
- parser.fetch(:one).should == "one"
39
- end
40
-
41
- it "returns nil when the value is NA" do
42
- hash = {one: "NA"}
43
- parser = Barometer::Utils::Payload.new(hash)
44
- parser.fetch(:one).should be_nil
45
- end
46
-
47
- context "when the data is accessed via an attribute" do
48
- it "returns the value of the key" do
49
- hash = {one: {'@two' => 2}}
50
- parser = Barometer::Utils::Payload.new(hash)
51
- parser.fetch(:one, '@two').should == 2
3
+ module Barometer::Utils
4
+ describe Payload do
5
+ describe '#fetch' do
6
+ it 'returns the value for the key provided' do
7
+ hash = {one: 1}
8
+ parser = Payload.new(hash)
9
+ expect( parser.fetch(:one) ).to eq 1
52
10
  end
53
11
 
54
- it "returns the value accessed via :attributes" do
55
- class StringWithAttributes < String
56
- attr_accessor :attributes
57
- end
58
- value_with_attributes = StringWithAttributes.new('one')
59
- value_with_attributes.attributes = {'two' => 2}
60
- hash = {one: value_with_attributes}
61
- parser = Barometer::Utils::Payload.new(hash)
62
- parser.fetch(:one, '@two').should == 2
12
+ it 'traverses multiple levels to get the value' do
13
+ hash = {one: {two: {three: 3}}}
14
+ parser = Payload.new(hash)
15
+ expect( parser.fetch(:one, :two, :three) ).to eq 3
63
16
  end
64
17
  end
65
18
 
66
- context "when the data is accessed via an index" do
67
- it "returns the value at that index" do
68
- hash = {one: [2]}
69
- parser = Barometer::Utils::Payload.new(hash)
70
- parser.fetch(:one, 0).should == 2
71
- end
72
- end
73
- end
19
+ describe '#units' do
20
+ it 'returns the query units when the query is present' do
21
+ units = double(:units)
22
+ query = double(:query, units: units)
74
23
 
75
- describe "#fetch_each" do
76
- it "returns a payload for each result found at the key" do
77
- hash = {one: [{two: 2}, {two: 2}]}
78
- parser = Barometer::Utils::Payload.new(hash)
24
+ payload = Payload.new({}, query)
79
25
 
80
- expect { |b|
81
- parser.fetch_each(:one, &b)
82
- }.to yield_successive_args(Barometer::Utils::Payload, Barometer::Utils::Payload)
83
- end
84
-
85
- it "returns a payload for each result found at the key" do
86
- hash = {one: [{two: 2}, {two: 2}]}
87
- parser = Barometer::Utils::Payload.new(hash)
88
-
89
- parser.fetch_each(:one) do |each_parser|
90
- each_parser.fetch(:two).should == 2
26
+ expect( payload.units ).to eq units
91
27
  end
92
- end
93
-
94
- it "raises an error when result is not an array" do
95
- hash = {one: 1}
96
- parser = Barometer::Utils::Payload.new(hash)
97
28
 
98
- expect {
99
- parser.fetch_each(:one){ |p| nil }
100
- }.to raise_error(NoMethodError)
101
- end
102
- end
103
-
104
- describe "#fetch_each_with_index" do
105
- it "returns a payload for each result found at the key" do
106
- hash = {one: [{two: 2}, {two: 2}]}
107
- parser = Barometer::Utils::Payload.new(hash)
108
-
109
- i = 0
110
- parser.fetch_each_with_index(:one) do |each_parser, index|
111
- each_parser.fetch(:two).should == 2
112
- index.should == i
113
- i += 1
29
+ it 'returns nil when the query is not present' do
30
+ payload = Payload.new({}, nil)
31
+ expect( payload.units ).to be_nil
114
32
  end
115
33
  end
116
-
117
- it "raises an error when result is not an array" do
118
- hash = {one: 1}
119
- parser = Barometer::Utils::Payload.new(hash)
120
-
121
- expect {
122
- parser.fetch_each_with_index(:one){ |p| nil }
123
- }.to raise_error(NoMethodError)
124
- end
125
- end
126
-
127
- describe "#using" do
128
- it "applies the regex to the fetched result" do
129
- hash = {one: 'two, three'}
130
- parser = Barometer::Utils::Payload.new(hash)
131
- parser.using(/^(.*),/).fetch(:one).should == 'two'
132
- end
133
-
134
- it "does nothing if valid regex does not exist" do
135
- hash = {one: 'two, three'}
136
- parser = Barometer::Utils::Payload.new(hash)
137
- parser.using(:invalid_regex).fetch(:one).should == 'two, three'
138
- end
139
-
140
- it "does nothing if regex does not capture proper result" do
141
- hash = {one: 'two, three'}
142
- parser = Barometer::Utils::Payload.new(hash)
143
- parser.using(/^.*,.*$/).fetch(:one).should == 'two, three'
144
- end
145
-
146
- it "forgets the regex" do
147
- hash = {one: 'two, three'}
148
- parser = Barometer::Utils::Payload.new(hash)
149
- parser.using(/^(.*),/).fetch(:one).should == 'two'
150
- parser.fetch(:one).should == 'two, three'
151
- end
152
- end
153
-
154
- describe '#units' do
155
- it 'returns the query units when the query is present' do
156
- units = double(:units)
157
- query = double(:query, units: units)
158
- payload = Barometer::Utils::Payload.new({}, query)
159
- expect( payload.units ).to eq units
160
- end
161
-
162
- it 'returns nil when the query is not present' do
163
- payload = Barometer::Utils::Payload.new({}, nil)
164
- expect( payload.units ).to be_nil
165
- end
166
34
  end
167
35
  end
168
-