Skip to content

Commit

Permalink
Merge 87ab66f into cd3fc53
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam Pikesley committed Jan 2, 2016
2 parents cd3fc53 + 87ab66f commit 5ac3249
Show file tree
Hide file tree
Showing 11 changed files with 285 additions and 18 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ group :test do
gem 'guard-cucumber'
gem 'guard-rspec'
gem 'pry'
gem 'timecop'
gem 'vcr'
gem 'webmock'
gem 'cucumber-api-steps', require: false
Expand Down
9 changes: 6 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ GEM
thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1)
addressable (2.4.0)
autoprefixer-rails (6.2.2)
autoprefixer-rails (6.2.3)
execjs
json
bootstrap-sass (3.3.6)
Expand Down Expand Up @@ -107,9 +107,10 @@ GEM
rb-inotify (>= 0.9)
loofah (2.0.3)
nokogiri (>= 1.5.9)
lumberjack (1.0.9)
lumberjack (1.0.10)
method_source (0.8.2)
mime-types (2.99)
mime-types-data (3.2015.1120)
mini_portile2 (2.0.0)
minitest (5.8.3)
multi_json (1.11.2)
Expand Down Expand Up @@ -144,7 +145,7 @@ GEM
rails-html-sanitizer (1.0.2)
loofah (~> 2.0)
rake (10.4.2)
rb-fsevent (0.9.6)
rb-fsevent (0.9.7)
rb-inotify (0.9.5)
ffi (>= 0.5.0)
redis (3.2.2)
Expand Down Expand Up @@ -188,6 +189,7 @@ GEM
thor (0.19.1)
thread_safe (0.3.5)
tilt (1.4.1)
timecop (0.8.0)
tins (1.6.0)
tzinfo (1.2.2)
thread_safe (~> 0.1)
Expand Down Expand Up @@ -228,6 +230,7 @@ DEPENDENCIES
sinatra
sinatra-assetpack
tilt (~> 1)
timecop
vcr
webmock

Expand Down
1 change: 1 addition & 0 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
* Individual URLs per dataset, maybe iframe the dashboards ala Sir Handel
* Front page with high-priority things?
* Github URLs back to the datas
* License the data
22 changes: 13 additions & 9 deletions lib/dashboard/fetcher.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
module Dashboard
class Fetcher
@@redis = Redis.new
REDIS = Redis.new

def self.redis
REDIS
end

def self.headers
{
Expand All @@ -16,15 +20,15 @@ def self.query
}
end

def self.get url
if @@redis.get url
return Marshal.load(@@redis.get url)
def self.get url, ttl = 3600
begin
Marshal.load(self.redis.get url)
rescue TypeError
h = HTTParty.get url, headers: headers, query: query
self.redis.set url, Marshal.dump(h.body)
self.redis.expire url, ttl
Marshal.load(self.redis.get url)
end

h = HTTParty.get url, headers: headers, query: query
@@redis.set url, Marshal.dump(h.body)
@@redis.expire url, 3600
return Marshal.load(@@redis.get url)
end

def self.extract_repo url
Expand Down
7 changes: 6 additions & 1 deletion lib/views/grid.erb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
]

var layout = {
title: json['title'],
title: json['title'] + ' (' + githubLink(json) + ')',
xaxis: {
tickformat: "%b %Y"
},
Expand Down Expand Up @@ -69,11 +69,16 @@
}
content += '<h2>' + fixedDate + '</h2>'
content += '<h3>(' + age + ')</h3>'
content += githubLink(json)
content += '<hr />'

return cellContent(json['id'], content)
}

function githubLink(json) {
return '<a href="' + json['url'] + '">Source</a>'
}

function cellContent(id, content) {
return "<div class='col-md-4' id='#" + id + "'>" + content + "</div>"
}
Expand Down
37 changes: 37 additions & 0 deletions spec/caching_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
module Dashboard
describe Fetcher do
before :each do
Redis.new.flushall
end

after :all do
Redis.new.flushall
end

it 'stores a value in Redis', :vcr do
url = 'https://raw.githubusercontent.com/pikesley/snake-data/master/length.csv'
described_class.get(url)
expect(Marshal.load(Redis.new.get(url))).to eq(
"""\
Date,Length in m
2014-09-30,0.45
2014-10-09,0.50
2014-10-18,0.50
2014-12-12,0.55
2015-01-11,0.60
2015-01-28,0.65
2015-08-27,0.95
"""
)
end

it 'expires a value after the timeout', :vcr do
url = 'https://api.github.com/repos/pikesley/catface/contents/flea-treatment.csv?ref=master'
described_class.get(url, 1)
expect(Redis.new.get url).to_not be nil
expect(Redis.new.ttl url).to eq 1
sleep 1
expect(Redis.new.get url).to be nil
end
end
end
5 changes: 0 additions & 5 deletions spec/javascripts/dashboardSpec.js
Original file line number Diff line number Diff line change
@@ -1,5 +0,0 @@
describe('ago', function() {
it('knows a thing was a month ago', function() {
Timecop.install()
})
})
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require 'coveralls'
Coveralls.wear_merged!
require 'timecop'

require 'dashboard'
require_relative 'support/vcr_setup'
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

76 changes: 76 additions & 0 deletions spec/support/vcr/Dashboard_Fetcher/stores_a_value_in_Redis.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5ac3249

Please sign in to comment.