forecast_io-cache 1.0.0 → 2.0.0
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.
- checksums.yaml +4 -4
- data/features/step_definitions/cache_steps.rb +10 -7
- data/features/step_definitions/forecast_steps.rb +2 -2
- data/features/support/cassettes/forecast_for_latitude_and_longitude.yml +1 -1
- data/features/support/config.rb +3 -4
- data/features/support/fixtures.rb +8 -3
- data/features/support/pg.rb +6 -0
- data/forecast_io-cache.gemspec +1 -5
- data/lib/forecast_io/cache.rb +1 -1
- data/lib/forecast_io/cache/configuration.rb +6 -3
- data/lib/forecast_io/cache/forecast_data.rb +12 -11
- data/lib/forecast_io/cache/generate.rb +1 -1
- data/lib/forecast_io/cache/store.rb +23 -24
- data/lib/forecast_io/cache/version.rb +1 -1
- data/spec/forecast_io/cache/configuration_spec.rb +5 -3
- data/spec/forecast_io/cache/forecast_data_spec.rb +2 -1
- data/spec/forecast_io/cache/store_spec.rb +5 -6
- data/spec/support/pg.rb +13 -0
- metadata +7 -49
- data/features/support/mongo.rb +0 -5
- data/spec/support/mongo.rb +0 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d991786947e787fb6e855ca1bafc6a463e93bc69
|
4
|
+
data.tar.gz: 4d367c34d9b6b4fe4c33cdfcc25bbee3f1825e08
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7e5438f5eb36476ce5be126ad89b9260e54f95786038173b968e2b089cdf377af81450b74090c0a445a926210b931e0145ff7a64799b6ad1dde2acc7f2df34cf
|
7
|
+
data.tar.gz: 5c9bda5074194ec975414e9f1a15ba4c9425544dd493c3cc33ef109d538c4f41accc6ebfd92392d67c54baab5632d728642538d76496a882bdc86cd6bae3e368
|
@@ -1,18 +1,21 @@
|
|
1
1
|
Given "I have cached this forecast recently" do
|
2
|
-
@
|
3
|
-
|
2
|
+
@latitude = -33.857444
|
3
|
+
@longitude = 151.238823
|
4
|
+
setup "latitude" => @latitude, "longitude" => @longitude, "time" => 123456789
|
4
5
|
end
|
5
6
|
|
6
7
|
Given "I have a cache result nearby" do
|
7
|
-
@
|
8
|
-
|
8
|
+
@latitude = -33.857333
|
9
|
+
@longitude = 151.238823
|
10
|
+
setup "latitude" => @latitude, "longitude" => @longitude, "time" => 123456789
|
9
11
|
end
|
10
12
|
|
11
13
|
Given "I have a cache result for close by" do
|
12
|
-
@
|
13
|
-
|
14
|
+
@latitude = -33.957333
|
15
|
+
@longitude = 151.238823
|
16
|
+
setup "latitude" => @latitude, "longitude" => @longitude, "time" => 123456789
|
14
17
|
end
|
15
18
|
|
16
19
|
Given "I have a cached result but for a time beyond the threshold" do
|
17
|
-
setup "
|
20
|
+
setup "latitude" => -33.757444, "longitude" => 151.238823, "time" => 1234567890
|
18
21
|
end
|
@@ -21,8 +21,8 @@ Then "I am given the cached forecast" do
|
|
21
21
|
expect_ok { get @path }
|
22
22
|
expect(parsed_response).to eq({
|
23
23
|
"time" => 123456789,
|
24
|
-
"latitude" => @
|
25
|
-
"longitude" => @
|
24
|
+
"latitude" => @latitude,
|
25
|
+
"longitude" => @longitude,
|
26
26
|
"wind_speed" => 6.66,
|
27
27
|
"wind_bearing" => 200,
|
28
28
|
"humidity" => 0.9,
|
data/features/support/config.rb
CHANGED
@@ -1,9 +1,8 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
Forecast::IO.configure do |config|
|
1
|
+
ForecastIO.configure do |config|
|
4
2
|
config.api_key = ENV['API_KEY']
|
5
3
|
end
|
6
4
|
|
7
5
|
Forecast::IO::Cache.configure do |config|
|
8
|
-
config.
|
6
|
+
config.radius = 1
|
7
|
+
config.db_uri = 'postgres://localhost/forecast-test'
|
9
8
|
end
|
@@ -1,11 +1,16 @@
|
|
1
|
-
require './features/support/
|
1
|
+
require './features/support/pg'
|
2
2
|
module Fixtures
|
3
3
|
|
4
|
+
def db
|
5
|
+
@db ||= Sequel.connect 'postgres://localhost/forecast-test'
|
6
|
+
end
|
7
|
+
|
4
8
|
def setup attrs = {}
|
5
|
-
|
9
|
+
db[:forecasts].insert(
|
6
10
|
{
|
7
11
|
"time" => 123456789,
|
8
|
-
"
|
12
|
+
"latitude" => -33.857444,
|
13
|
+
"longitude" => 151.238823,
|
9
14
|
"wind_speed" => 6.66,
|
10
15
|
"wind_bearing" => 200,
|
11
16
|
"humidity" => 0.9,
|
data/forecast_io-cache.gemspec
CHANGED
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
|
|
20
20
|
|
21
21
|
spec.add_runtime_dependency "forecast_io", '~> 2.0.1'
|
22
22
|
spec.add_runtime_dependency "sinatra"
|
23
|
-
spec.add_runtime_dependency "
|
23
|
+
spec.add_runtime_dependency "pg_adaptor"
|
24
24
|
|
25
25
|
spec.add_development_dependency "bundler", "~> 1.3"
|
26
26
|
spec.add_development_dependency "rake"
|
@@ -29,8 +29,4 @@ Gem::Specification.new do |spec|
|
|
29
29
|
spec.add_development_dependency "rack-test"
|
30
30
|
spec.add_development_dependency "vcr"
|
31
31
|
|
32
|
-
spec.add_development_dependency "mongo"
|
33
|
-
spec.add_development_dependency "bson"
|
34
|
-
spec.add_development_dependency "bson_ext"
|
35
|
-
|
36
32
|
end
|
data/lib/forecast_io/cache.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
1
|
+
require 'pg_adaptor'
|
2
2
|
|
3
3
|
module Forecast
|
4
4
|
module IO
|
@@ -6,6 +6,7 @@ module Forecast
|
|
6
6
|
class Configuration
|
7
7
|
|
8
8
|
attr_writer :radius, :timeframe
|
9
|
+
attr_reader :db_uri, :db
|
9
10
|
|
10
11
|
def radius
|
11
12
|
@radius ||= 5
|
@@ -15,8 +16,10 @@ module Forecast
|
|
15
16
|
@timeframe ||= 60
|
16
17
|
end
|
17
18
|
|
18
|
-
def
|
19
|
-
|
19
|
+
def db_uri= value
|
20
|
+
@db_uri = value
|
21
|
+
@db = PGAdaptor.db = Sequel.connect(db_uri)
|
22
|
+
value
|
20
23
|
end
|
21
24
|
|
22
25
|
end
|
@@ -1,27 +1,28 @@
|
|
1
1
|
module Forecast
|
2
2
|
module IO
|
3
3
|
module Cache
|
4
|
-
class ForecastData < Struct.new(:
|
4
|
+
class ForecastData < Struct.new(:latitude, :longitude, :time, :wind_speed, :wind_bearing,
|
5
5
|
:humidity, :pressure, :visibility, :temperature)
|
6
6
|
|
7
7
|
def self.generate lat, lon, forecast
|
8
8
|
new.tap do |data|
|
9
|
-
data.
|
10
|
-
data.
|
11
|
-
data.
|
12
|
-
data.
|
13
|
-
data.
|
14
|
-
data.
|
15
|
-
data.
|
16
|
-
data.
|
9
|
+
data.latitude = lat.to_f
|
10
|
+
data.longitude = lon.to_f
|
11
|
+
data.time = forecast['time']
|
12
|
+
data.wind_speed = forecast['windSpeed']
|
13
|
+
data.wind_bearing = forecast['windBearing']
|
14
|
+
data.humidity = forecast['humidity']
|
15
|
+
data.pressure = forecast['pressure']
|
16
|
+
data.visibility = forecast['visibility']
|
17
|
+
data.temperature = forecast['temperature']
|
17
18
|
end
|
18
19
|
end
|
19
20
|
|
20
21
|
def to_json
|
21
22
|
{
|
22
23
|
time: time,
|
23
|
-
latitude:
|
24
|
-
longitude:
|
24
|
+
latitude: latitude,
|
25
|
+
longitude: longitude,
|
25
26
|
wind_speed: wind_speed,
|
26
27
|
wind_bearing: wind_bearing,
|
27
28
|
humidity: humidity,
|
@@ -9,7 +9,7 @@ module Forecast
|
|
9
9
|
new(lat, lon, time, cache).forecasts.first
|
10
10
|
end
|
11
11
|
|
12
|
-
def initialize lat, lon, time, cache, api = ::
|
12
|
+
def initialize lat, lon, time, cache, api = ::ForecastIO
|
13
13
|
@lat, @lon, @time, @cache, @api = lat, lon, time, cache, api
|
14
14
|
end
|
15
15
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
1
|
+
require 'pg_adaptor'
|
2
2
|
require 'forecast_io/cache/forecast_data'
|
3
3
|
|
4
4
|
module Forecast
|
@@ -8,19 +8,23 @@ module Forecast
|
|
8
8
|
|
9
9
|
def initialize config = Cache.configuration
|
10
10
|
@config = config
|
11
|
-
@backend =
|
11
|
+
@backend = PGAdaptor.new('forecasts', ForecastData)
|
12
12
|
end
|
13
13
|
|
14
14
|
def fetch lat, lon, time
|
15
|
-
@backend.fetch
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
15
|
+
@backend.fetch Sequel.lit(<<-SQL),
|
16
|
+
time >= :start AND time <= :end AND earth_box(
|
17
|
+
ll_to_earth(:lat, :lon), :radius
|
18
|
+
) @> ll_to_earth(
|
19
|
+
latitude,
|
20
|
+
longitude
|
21
|
+
)
|
22
|
+
SQL
|
23
|
+
start: time - offset,
|
24
|
+
end: time + offset,
|
25
|
+
lat: lat,
|
26
|
+
lon: lon,
|
27
|
+
radius: radius
|
24
28
|
end
|
25
29
|
|
26
30
|
def store forecast
|
@@ -28,22 +32,17 @@ module Forecast
|
|
28
32
|
forecast
|
29
33
|
end
|
30
34
|
|
31
|
-
|
32
|
-
def radius
|
33
|
-
@config.radius * (1/111.694)
|
34
|
-
end
|
35
|
+
private
|
35
36
|
|
36
|
-
|
37
|
-
|
38
|
-
|
37
|
+
def radius
|
38
|
+
# nm to m
|
39
|
+
@config.radius * 1852
|
40
|
+
end
|
39
41
|
|
40
|
-
|
41
|
-
|
42
|
-
|
42
|
+
def offset
|
43
|
+
@config.timeframe * 60
|
44
|
+
end
|
43
45
|
|
44
|
-
def ensure_index!
|
45
|
-
MongoAdaptor.db.collection('forecasts').ensure_index position: Mongo::GEO2D
|
46
|
-
end
|
47
46
|
end
|
48
47
|
end
|
49
48
|
end
|
@@ -22,9 +22,11 @@ describe 'service configuration' do
|
|
22
22
|
expect(config.timeframe).to eq 12
|
23
23
|
end
|
24
24
|
|
25
|
-
it 'loads
|
26
|
-
|
27
|
-
config.
|
25
|
+
it 'loads db from db_uri' do
|
26
|
+
config.db_uri = 'postgres://localhost/forecast-test'
|
27
|
+
expect(config.db).to be_a Sequel::Database
|
28
|
+
expect(config.db.opts[:database]).to eq 'forecast-test'
|
29
|
+
expect(PGAdaptor.db).to eq config.db
|
28
30
|
end
|
29
31
|
|
30
32
|
end
|
@@ -24,7 +24,8 @@ describe 'representing data from the api' do
|
|
24
24
|
expect(forecast.time).to eq time
|
25
25
|
end
|
26
26
|
it "exposes position" do
|
27
|
-
expect(forecast.
|
27
|
+
expect(forecast.latitude).to eq 1.1
|
28
|
+
expect(forecast.longitude).to eq -1.2
|
28
29
|
end
|
29
30
|
it "exposes wind_speed" do
|
30
31
|
expect(forecast.wind_speed).to eq wind_speed
|
@@ -1,14 +1,14 @@
|
|
1
|
-
require 'support/
|
1
|
+
require 'support/pg'
|
2
2
|
require 'forecast_io/cache/store'
|
3
3
|
|
4
|
-
describe database: true do
|
4
|
+
RSpec.describe 'Forecast::IO::Cache::Store', database: true do
|
5
5
|
let(:config) { double radius: 1, timeframe: 3 }
|
6
6
|
let(:store) { Forecast::IO::Cache::Store.new config }
|
7
7
|
let(:data) { Forecast::IO::Cache::ForecastData }
|
8
8
|
|
9
9
|
describe 'retrieving forecasts from the store' do
|
10
|
-
let(:forecast_1) { data.new
|
11
|
-
let(:forecast_2) { data.new
|
10
|
+
let(:forecast_1) { data.new -33.858264, 151.23775, 1, 0, 0, 0, 0, 0, 0 }
|
11
|
+
let(:forecast_2) { data.new -33.858664, 151.23675, 3, 0, 0, 0, 0, 0, 0 }
|
12
12
|
|
13
13
|
before do
|
14
14
|
store.store forecast_1
|
@@ -27,11 +27,10 @@ describe database: true do
|
|
27
27
|
end
|
28
28
|
|
29
29
|
describe 'inserting forecasts into the store' do
|
30
|
-
let(:forecast) { data.new
|
30
|
+
let(:forecast) { data.new 151.23775, -33.858264, 1, 0, 0, 0, 0, 0, 0 }
|
31
31
|
|
32
32
|
it 'returns the forecast' do
|
33
33
|
expect(store.store forecast).to eq forecast
|
34
34
|
end
|
35
35
|
end
|
36
|
-
|
37
36
|
end
|
data/spec/support/pg.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'pg_adaptor'
|
2
|
+
PGAdaptor.db = Sequel.connect 'postgres://localhost/forecast-test'
|
3
|
+
|
4
|
+
RSpec.configure do |config|
|
5
|
+
|
6
|
+
config.after :example, database: true do
|
7
|
+
PGAdaptor.db.tables.each do |table|
|
8
|
+
next if table == :schema_migrations
|
9
|
+
PGAdaptor.db.execute "TRUNCATE #{table};"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: forecast_io-cache
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jon Rowe
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-09
|
11
|
+
date: 2016-11-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: forecast_io
|
@@ -39,7 +39,7 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: pg_adaptor
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - ">="
|
@@ -136,48 +136,6 @@ dependencies:
|
|
136
136
|
- - ">="
|
137
137
|
- !ruby/object:Gem::Version
|
138
138
|
version: '0'
|
139
|
-
- !ruby/object:Gem::Dependency
|
140
|
-
name: mongo
|
141
|
-
requirement: !ruby/object:Gem::Requirement
|
142
|
-
requirements:
|
143
|
-
- - ">="
|
144
|
-
- !ruby/object:Gem::Version
|
145
|
-
version: '0'
|
146
|
-
type: :development
|
147
|
-
prerelease: false
|
148
|
-
version_requirements: !ruby/object:Gem::Requirement
|
149
|
-
requirements:
|
150
|
-
- - ">="
|
151
|
-
- !ruby/object:Gem::Version
|
152
|
-
version: '0'
|
153
|
-
- !ruby/object:Gem::Dependency
|
154
|
-
name: bson
|
155
|
-
requirement: !ruby/object:Gem::Requirement
|
156
|
-
requirements:
|
157
|
-
- - ">="
|
158
|
-
- !ruby/object:Gem::Version
|
159
|
-
version: '0'
|
160
|
-
type: :development
|
161
|
-
prerelease: false
|
162
|
-
version_requirements: !ruby/object:Gem::Requirement
|
163
|
-
requirements:
|
164
|
-
- - ">="
|
165
|
-
- !ruby/object:Gem::Version
|
166
|
-
version: '0'
|
167
|
-
- !ruby/object:Gem::Dependency
|
168
|
-
name: bson_ext
|
169
|
-
requirement: !ruby/object:Gem::Requirement
|
170
|
-
requirements:
|
171
|
-
- - ">="
|
172
|
-
- !ruby/object:Gem::Version
|
173
|
-
version: '0'
|
174
|
-
type: :development
|
175
|
-
prerelease: false
|
176
|
-
version_requirements: !ruby/object:Gem::Requirement
|
177
|
-
requirements:
|
178
|
-
- - ">="
|
179
|
-
- !ruby/object:Gem::Version
|
180
|
-
version: '0'
|
181
139
|
description: Caching layer for forecast_io
|
182
140
|
email:
|
183
141
|
- hello@jonrowe.co.uk
|
@@ -199,8 +157,8 @@ files:
|
|
199
157
|
- features/support/env.rb
|
200
158
|
- features/support/expect.rb
|
201
159
|
- features/support/fixtures.rb
|
202
|
-
- features/support/mongo.rb
|
203
160
|
- features/support/parse.rb
|
161
|
+
- features/support/pg.rb
|
204
162
|
- features/support/time.rb
|
205
163
|
- features/support/vcr.rb
|
206
164
|
- forecast_io-cache.gemspec
|
@@ -219,7 +177,7 @@ files:
|
|
219
177
|
- spec/forecast_io/cache/generate_spec.rb
|
220
178
|
- spec/forecast_io/cache/store_spec.rb
|
221
179
|
- spec/forecast_io/cache_spec.rb
|
222
|
-
- spec/support/
|
180
|
+
- spec/support/pg.rb
|
223
181
|
homepage: https://github.com/Tacktical/forecast_io-cache
|
224
182
|
licenses:
|
225
183
|
- MIT
|
@@ -257,8 +215,8 @@ test_files:
|
|
257
215
|
- features/support/env.rb
|
258
216
|
- features/support/expect.rb
|
259
217
|
- features/support/fixtures.rb
|
260
|
-
- features/support/mongo.rb
|
261
218
|
- features/support/parse.rb
|
219
|
+
- features/support/pg.rb
|
262
220
|
- features/support/time.rb
|
263
221
|
- features/support/vcr.rb
|
264
222
|
- spec/forecast_io/cache/configuration_spec.rb
|
@@ -267,4 +225,4 @@ test_files:
|
|
267
225
|
- spec/forecast_io/cache/generate_spec.rb
|
268
226
|
- spec/forecast_io/cache/store_spec.rb
|
269
227
|
- spec/forecast_io/cache_spec.rb
|
270
|
-
- spec/support/
|
228
|
+
- spec/support/pg.rb
|
data/features/support/mongo.rb
DELETED
data/spec/support/mongo.rb
DELETED
@@ -1,11 +0,0 @@
|
|
1
|
-
require 'mongo-configure'
|
2
|
-
|
3
|
-
Mongo::Configure.from_database 'forecast-test-spec'
|
4
|
-
|
5
|
-
RSpec.configure do |config|
|
6
|
-
|
7
|
-
config.after :each, database: true do
|
8
|
-
Mongo::Configure.current.load.collections.select { |c| c.name !~ /^system\./ }.each &:remove
|
9
|
-
end
|
10
|
-
|
11
|
-
end
|