From 98147ac34d52527113dde90f55f86ddab7c8588d Mon Sep 17 00:00:00 2001 From: pikesley Date: Sat, 2 Jan 2016 19:41:41 +0000 Subject: [PATCH 1/7] Hard coded but it works I can can work this out --- TODO.md | 1 - features/json.feature | 10 ++++++++++ lib/dashboard.rb | 22 ++++++++++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 features/json.feature diff --git a/TODO.md b/TODO.md index 7d5b6e8..22d72e5 100644 --- a/TODO.md +++ b/TODO.md @@ -1,4 +1,3 @@ -* Check for cache expiry (timecop!) * Give things an expiry, change colour / move them up the list when they're due * Individual URLs per dataset, maybe iframe the dashboards ala Sir Handel * Front page with high-priority things? diff --git a/features/json.feature b/features/json.feature new file mode 100644 index 0000000..159769d --- /dev/null +++ b/features/json.feature @@ -0,0 +1,10 @@ +@vcr +Feature: Get JSON + + Background: + Given I send and accept JSON + + Scenario: Get JSON for a dataset + When I send a GET request to "catface/flea-treatment" + Then the response status should be "200" + And the JSON response should have "$.title" with the text "Flea Treatment" diff --git a/lib/dashboard.rb b/lib/dashboard.rb index d9dbc6e..023bc4c 100644 --- a/lib/dashboard.rb +++ b/lib/dashboard.rb @@ -44,6 +44,28 @@ class App < Sinatra::Base end end + get '/catface/flea-treatment' do + respond_to do |wants| + headers 'Vary' => 'Accept' + + wants.json do + { + title: "Flea Treatment", + name: "flea-treatment.csv", + id: "flea-treatment", + 'date-field': "Date", + type: "latest", + url: "https://github.com/pikesley/catface/blob/master/flea-treatment.csv", + data: [ + { + Date: "2015-12-03" + } + ] + }.to_json + end + end + end + get '/snake' do respond_to do |wants| headers 'Vary' => 'Accept' From b4727b5b3917f3ef52ffc3613aa7593b95966f87 Mon Sep 17 00:00:00 2001 From: pikesley Date: Sat, 2 Jan 2016 19:55:11 +0000 Subject: [PATCH 2/7] Why is this not recording? --- features/json.feature | 1 + features/support/vcr.rb | 21 +++++++++++++++++++++ lib/dashboard.rb | 16 ++-------------- 3 files changed, 24 insertions(+), 14 deletions(-) create mode 100644 features/support/vcr.rb diff --git a/features/json.feature b/features/json.feature index 159769d..3e6a03a 100644 --- a/features/json.feature +++ b/features/json.feature @@ -8,3 +8,4 @@ Feature: Get JSON When I send a GET request to "catface/flea-treatment" Then the response status should be "200" And the JSON response should have "$.title" with the text "Flea Treatment" + And the JSON response should have "$.data[0].Date" with the text "2015-12-03" diff --git a/features/support/vcr.rb b/features/support/vcr.rb new file mode 100644 index 0000000..a639c06 --- /dev/null +++ b/features/support/vcr.rb @@ -0,0 +1,21 @@ +require 'vcr' +require 'webmock/cucumber' + +VCR.configure do |c| + c.default_cassette_options = { :record => :once } + + c.cassette_library_dir = 'features/support/vcr' + c.hook_into :webmock + c.allow_http_connections_when_no_cassette = false + + [ + 'GITHUB_CLIENT_ID', + 'GITHUB_CLIENT_SECRET' + ].each do |env_var| + c.filter_sensitive_data("<#{env_var}>") { ENV[env_var] } + end +end + +VCR.cucumber_tags do |t| + t.tag '@vcr', use_scenario_name: true +end diff --git a/lib/dashboard.rb b/lib/dashboard.rb index 023bc4c..4f0cc5a 100644 --- a/lib/dashboard.rb +++ b/lib/dashboard.rb @@ -44,24 +44,12 @@ class App < Sinatra::Base end end - get '/catface/flea-treatment' do + get '/:repo/:dataset' do respond_to do |wants| headers 'Vary' => 'Accept' wants.json do - { - title: "Flea Treatment", - name: "flea-treatment.csv", - id: "flea-treatment", - 'date-field': "Date", - type: "latest", - url: "https://github.com/pikesley/catface/blob/master/flea-treatment.csv", - data: [ - { - Date: "2015-12-03" - } - ] - }.to_json + Cleaner.sanitized_data("https://api.github.com/repos/pikesley/#{params[:repo]}/contents/#{params[:dataset]}.csv?ref=master").to_json end end end From a96ef06711b9f8ee0e2295034b2da7e72a37e5c8 Mon Sep 17 00:00:00 2001 From: pikesley Date: Sat, 2 Jan 2016 23:57:51 +0000 Subject: [PATCH 3/7] URL-per-dataset --- config/lookups.yml | 2 + features/json.feature | 2 +- lib/assets/css/application.scss | 10 ++-- lib/assets/javascripts/dashboard.js | 9 +--- lib/dashboard.rb | 13 ++++- lib/dashboard/helpers.rb | 15 ++++++ lib/views/dataset.erb | 80 +++++++++++++++++++++++++++++ 7 files changed, 117 insertions(+), 14 deletions(-) create mode 100644 lib/dashboard/helpers.rb create mode 100644 lib/views/dataset.erb diff --git a/config/lookups.yml b/config/lookups.yml index 1f63e88..032a6e6 100644 --- a/config/lookups.yml +++ b/config/lookups.yml @@ -1,10 +1,12 @@ catface: url: /catface title: Catface + repo: pikesley/catface snake-data: url: /snake title: Snake + repo: pikesley/snake-data datasets: length: diff --git a/features/json.feature b/features/json.feature index 3e6a03a..2bdf2b6 100644 --- a/features/json.feature +++ b/features/json.feature @@ -1,9 +1,9 @@ -@vcr Feature: Get JSON Background: Given I send and accept JSON + @vcr Scenario: Get JSON for a dataset When I send a GET request to "catface/flea-treatment" Then the response status should be "200" diff --git a/lib/assets/css/application.scss b/lib/assets/css/application.scss index bea1deb..aeec86e 100644 --- a/lib/assets/css/application.scss +++ b/lib/assets/css/application.scss @@ -1,22 +1,22 @@ //@import 'bootstrap'; -#numbers { +#data { text-align: center; } -#numbers h1, h2, h3, h4 { +#data h1, h2, h3, h4 { padding: 0px; margin: 0px; } -#numbers h1 { +#data h1 { font-size: 1.5em; } -#numbers h3 { +#data h3 { font-size: 1em; } -#numbers div { +#data div { padding: 5px; } diff --git a/lib/assets/javascripts/dashboard.js b/lib/assets/javascripts/dashboard.js index b79c3a3..47a4efa 100644 --- a/lib/assets/javascripts/dashboard.js +++ b/lib/assets/javascripts/dashboard.js @@ -1,8 +1,3 @@ -function cellContent(id, data) { - fixedDate = moment(data, 'YYYY-MM-DD').format('dddd Do MMMM') - subject = id.replace('-', ' ') - - content = '

Last ' + subject + ' was on

' + fixedDate + '

' - - return "
" + content + "
" +function githubLink(json) { + return 'Source' } diff --git a/lib/dashboard.rb b/lib/dashboard.rb index 4f0cc5a..2779ea2 100644 --- a/lib/dashboard.rb +++ b/lib/dashboard.rb @@ -13,6 +13,7 @@ require_relative 'dashboard/fetcher' require_relative 'dashboard/cleaner' require_relative 'dashboard/assets' +require_relative 'dashboard/helpers' require_relative 'dashboard/racks' require_relative 'dashboard/version' @@ -22,6 +23,10 @@ module Dashboard class App < Sinatra::Base set :views, 'lib/views' + helpers do + include Dashboard::Helpers + end + get '/' do @content = '

Home Dashboard

' title = 'Dashboard' @@ -49,7 +54,11 @@ class App < Sinatra::Base headers 'Vary' => 'Accept' wants.json do - Cleaner.sanitized_data("https://api.github.com/repos/pikesley/#{params[:repo]}/contents/#{params[:dataset]}.csv?ref=master").to_json + Cleaner.sanitized_data("https://api.github.com/repos/#{repo_map[params[:repo]]}/contents/#{params[:dataset]}.csv?ref=master").to_json + end + + wants.html do + erb :dataset, layout: :default end end end @@ -73,4 +82,6 @@ class App < Sinatra::Base # start the server if ruby file executed directly run! if app_file == $0 end + + end diff --git a/lib/dashboard/helpers.rb b/lib/dashboard/helpers.rb new file mode 100644 index 0000000..e57fdfd --- /dev/null +++ b/lib/dashboard/helpers.rb @@ -0,0 +1,15 @@ +module Dashboard + module Helpers + def repo_map + l = Cleaner.lookups.keys.map { |k| { Cleaner.lookups[k]['url'][1..-1] => Cleaner.lookups[k]['repo'] } } + map = {} + l.each do |m| + m.each_pair do |k, v| + map[k] = v + end + end + + map + end + end +end diff --git a/lib/views/dataset.erb b/lib/views/dataset.erb new file mode 100644 index 0000000..4bfcd05 --- /dev/null +++ b/lib/views/dataset.erb @@ -0,0 +1,80 @@ +
+
+ + From f332db7ae46b89a8ee78c1660497bd5d77636fcb Mon Sep 17 00:00:00 2001 From: pikesley Date: Sun, 3 Jan 2016 14:13:59 +0000 Subject: [PATCH 4/7] Invert lookups seems to work --- config/lookups.yml | 2 +- .../vcr/Get_JSON/Get_JSON_for_a_dataset.yml | 139 ++++++++++++++++++ lib/dashboard.rb | 24 +-- lib/dashboard/cleaner.rb | 24 ++- lib/dashboard/fetcher.rb | 2 +- lib/dashboard/helpers.rb | 11 -- spec/cleaner_spec.rb | 29 ++++ spec/fetcher_spec.rb | 4 +- 8 files changed, 194 insertions(+), 41 deletions(-) create mode 100644 features/support/vcr/Get_JSON/Get_JSON_for_a_dataset.yml diff --git a/config/lookups.yml b/config/lookups.yml index 032a6e6..f8aba72 100644 --- a/config/lookups.yml +++ b/config/lookups.yml @@ -3,7 +3,7 @@ catface: title: Catface repo: pikesley/catface -snake-data: +snake: url: /snake title: Snake repo: pikesley/snake-data diff --git a/features/support/vcr/Get_JSON/Get_JSON_for_a_dataset.yml b/features/support/vcr/Get_JSON/Get_JSON_for_a_dataset.yml new file mode 100644 index 0000000..1544739 --- /dev/null +++ b/features/support/vcr/Get_JSON/Get_JSON_for_a_dataset.yml @@ -0,0 +1,139 @@ +--- +http_interactions: +- request: + method: get + uri: https://api.github.com/repos/pikesley/catface/contents/flea-treatment.csv?client_id=&client_secret=&ref=master + body: + encoding: US-ASCII + string: '' + headers: + Accept: + - application/vnd.github.v3+json + User-Agent: + - Dashboard v0.0.1 + response: + status: + code: 200 + message: OK + headers: + Server: + - GitHub.com + Date: + - Sun, 03 Jan 2016 14:04:25 GMT + Content-Type: + - application/json; charset=utf-8 + Content-Length: + - '851' + Status: + - 200 OK + X-Ratelimit-Limit: + - '5000' + X-Ratelimit-Remaining: + - '4999' + X-Ratelimit-Reset: + - '1451833465' + Cache-Control: + - public, max-age=60, s-maxage=60 + Last-Modified: + - Mon, 28 Dec 2015 16:27:33 GMT + Etag: + - '"a408ef05c671be4ca2e7796fbb82dd17"' + Vary: + - Accept + - Accept-Encoding + X-Github-Media-Type: + - github.v3; format=json + Access-Control-Allow-Credentials: + - 'true' + Access-Control-Expose-Headers: + - ETag, Link, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, + X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval + Access-Control-Allow-Origin: + - "*" + Content-Security-Policy: + - default-src 'none' + Strict-Transport-Security: + - max-age=31536000; includeSubdomains; preload + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - deny + X-Xss-Protection: + - 1; mode=block + X-Served-By: + - a241e1a8264a6ace03db946c85b92db3 + X-Github-Request-Id: + - 5102724B:14B62:24CF0B30:56892A68 + body: + encoding: UTF-8 + string: '{"name":"flea-treatment.csv","path":"flea-treatment.csv","sha":"9f9077ece2431879f7b865ded46ce9796fc17dac","size":16,"url":"https://api.github.com/repos/pikesley/catface/contents/flea-treatment.csv?ref=master","html_url":"https://github.com/pikesley/catface/blob/master/flea-treatment.csv","git_url":"https://api.github.com/repos/pikesley/catface/git/blobs/9f9077ece2431879f7b865ded46ce9796fc17dac","download_url":"https://raw.githubusercontent.com/pikesley/catface/master/flea-treatment.csv","type":"file","content":"RGF0ZQoyMDE1LTEyLTAzCg==\n","encoding":"base64","_links":{"self":"https://api.github.com/repos/pikesley/catface/contents/flea-treatment.csv?ref=master","git":"https://api.github.com/repos/pikesley/catface/git/blobs/9f9077ece2431879f7b865ded46ce9796fc17dac","html":"https://github.com/pikesley/catface/blob/master/flea-treatment.csv"}}' + http_version: + recorded_at: Sun, 03 Jan 2016 14:04:25 GMT +- request: + method: get + uri: https://raw.githubusercontent.com/pikesley/catface/master/flea-treatment.csv?client_id=&client_secret= + body: + encoding: US-ASCII + string: '' + headers: + Accept: + - application/vnd.github.v3+json + User-Agent: + - Dashboard v0.0.1 + response: + status: + code: 200 + message: OK + headers: + Content-Security-Policy: + - default-src 'none' + X-Xss-Protection: + - 1; mode=block + X-Frame-Options: + - deny + X-Content-Type-Options: + - nosniff + Strict-Transport-Security: + - max-age=31536000 + Etag: + - '"9f9077ece2431879f7b865ded46ce9796fc17dac"' + Content-Type: + - text/plain; charset=utf-8 + Cache-Control: + - max-age=300 + X-Github-Request-Id: + - B91F131F:2F43:3D64B861:56892A69 + Content-Length: + - '16' + Accept-Ranges: + - bytes + Date: + - Sun, 03 Jan 2016 14:04:25 GMT + Via: + - 1.1 varnish + Connection: + - keep-alive + X-Served-By: + - cache-lhr6320-LHR + X-Cache: + - MISS + X-Cache-Hits: + - '0' + Vary: + - Authorization,Accept-Encoding + Access-Control-Allow-Origin: + - "*" + X-Fastly-Request-Id: + - 5963432931122acf0c74f12428c7120bee69b89b + Expires: + - Sun, 03 Jan 2016 14:09:25 GMT + Source-Age: + - '0' + body: + encoding: UTF-8 + string: | + Date + 2015-12-03 + http_version: + recorded_at: Sun, 03 Jan 2016 14:04:25 GMT +recorded_with: VCR 3.0.1 diff --git a/lib/dashboard.rb b/lib/dashboard.rb index 2779ea2..a11377e 100644 --- a/lib/dashboard.rb +++ b/lib/dashboard.rb @@ -33,17 +33,19 @@ class App < Sinatra::Base erb :index, layout: :default end - get '/catface' do + get '/:repo' do respond_to do |wants| headers 'Vary' => 'Accept' + repo = repo_map[params[:repo]] + wants.html do @title = 'Catface' erb :grid, layout: :default end wants.json do - urls = Fetcher.list_CSVs('pikesley/catface') + urls = Fetcher.list_CSVs(repo_map[params[:repo]]) urls.map { |url| Cleaner.sanitized_data url }.to_json end end @@ -54,7 +56,7 @@ class App < Sinatra::Base headers 'Vary' => 'Accept' wants.json do - Cleaner.sanitized_data("https://api.github.com/repos/#{repo_map[params[:repo]]}/contents/#{params[:dataset]}.csv?ref=master").to_json + Cleaner.sanitized_data("https://api.github.com/repos/#{Cleaner.lookups[params[:repo]]['repo']}/contents/#{params[:dataset]}.csv?ref=master").to_json end wants.html do @@ -63,22 +65,6 @@ class App < Sinatra::Base end end - get '/snake' do - respond_to do |wants| - headers 'Vary' => 'Accept' - - wants.html do - @title = 'Snake' - erb :grid, layout: :default - end - - wants.json do - urls = Fetcher.list_CSVs('pikesley/snake-data') - urls.map { |url| Cleaner.sanitized_data url }.to_json - end - end - end - # start the server if ruby file executed directly run! if app_file == $0 end diff --git a/lib/dashboard/cleaner.rb b/lib/dashboard/cleaner.rb index 3a6e218..b4f471e 100644 --- a/lib/dashboard/cleaner.rb +++ b/lib/dashboard/cleaner.rb @@ -1,7 +1,17 @@ module Dashboard class Cleaner - def self.lookups - YAML.load_file 'config/lookups.yml' + def self.lookups inverted = false + y = YAML.load_file 'config/lookups.yml' + + if inverted + x = {} + y.keys.each do |k| + x[y[k]['repo']] = y[k] + end + return x + end + + y end def self.jsonise csv @@ -22,15 +32,15 @@ def self.jsonise csv def self.sanitized_data url j = {} + l = lookups(invert = true) d = Fetcher.assemble_data url - j['title'] = titleise(d) j['name'] = d['name'] j['id'] = trim d['name'] - j['date-field'] = lookups.dig(d['repo'], 'datasets', trim(d['name']), 'date-field') || 'Date' - j['type'] = lookups.dig(d['repo'], 'datasets', trim(d['name']), 'type') || 'latest' + j['date-field'] = l.dig(d['repo'], 'datasets', trim(d['name']), 'date-field') || 'Date' + j['type'] = l.dig(d['repo'], 'datasets', trim(d['name']), 'type') || 'latest' j['url'] = d['_links']['html'] - sf = lookups.dig(d['repo'], 'datasets', trim(d['name']), 'special-fields') + sf = l.dig(d['repo'], 'datasets', trim(d['name']), 'special-fields') j['special_fields'] = sf if sf j['data'] = jsonise d['data'] @@ -43,7 +53,7 @@ def self.trim string def self.titleise data trimmed = trim data['name'] - lookups.dig(data['repo'], trimmed, 'title') || trimmed.split('-').map { |w| w[0].upcase + w[1..-1] }.join(' ').singularize + lookups(true).dig(data['repo'], trimmed, 'title') || trimmed.split('-').map { |w| w[0].upcase + w[1..-1] }.join(' ').singularize end end end diff --git a/lib/dashboard/fetcher.rb b/lib/dashboard/fetcher.rb index 8be098f..e9c6e6a 100644 --- a/lib/dashboard/fetcher.rb +++ b/lib/dashboard/fetcher.rb @@ -32,7 +32,7 @@ def self.get url, ttl = 3600 end def self.extract_repo url - url.match(/https:\/\/api.github.com\/repos\/[^\/]*\/([^\/]*)\/contents.*/)[1] + url.match(/https:\/\/api.github.com\/repos\/([^\/]*\/[^\/]*)\/contents.*/)[1] end def self.fetch_CSV url diff --git a/lib/dashboard/helpers.rb b/lib/dashboard/helpers.rb index e57fdfd..5862959 100644 --- a/lib/dashboard/helpers.rb +++ b/lib/dashboard/helpers.rb @@ -1,15 +1,4 @@ module Dashboard module Helpers - def repo_map - l = Cleaner.lookups.keys.map { |k| { Cleaner.lookups[k]['url'][1..-1] => Cleaner.lookups[k]['repo'] } } - map = {} - l.each do |m| - m.each_pair do |k, v| - map[k] = v - end - end - - map - end end end diff --git a/spec/cleaner_spec.rb b/spec/cleaner_spec.rb index eaf41af..f6372b0 100644 --- a/spec/cleaner_spec.rb +++ b/spec/cleaner_spec.rb @@ -4,7 +4,36 @@ module Dashboard it 'titleises an item' do expect(described_class.titleise({'name' => 'vivarium-cleans.csv'})).to eq 'Vivarium Clean' end + + it 'inverts the lookups' do + expect(described_class.lookups(inverted = true)).to include ( + { + 'pikesley/snake-data' => { + 'url' => '/snake', + 'title' => 'Snake', + 'repo' => 'pikesley/snake-data', + 'datasets' => { + 'length' => { + 'type' => 'graph' + }, + 'weight' => { + 'type' => 'graph' + }, + 'sheds' => { + 'date-field' => 'Shed completed' + }, + 'feeds' => { + 'special-fields' => [ + 'Eaten', 'Food' + ] + } + } + } + } + ) + end end + it 'turns a CSV into a JSON-ish hash', :vcr do csv = Fetcher.fetch_CSV 'https://raw.githubusercontent.com/pikesley/snake-data/master/length.csv' expect(described_class.jsonise csv).to eq ( diff --git a/spec/fetcher_spec.rb b/spec/fetcher_spec.rb index 4cf5356..c896ee2 100644 --- a/spec/fetcher_spec.rb +++ b/spec/fetcher_spec.rb @@ -57,7 +57,7 @@ module Dashboard { 'name' => 'worm-treatment.csv', 'path' => 'worm-treatment.csv', - 'repo' => 'catface', + 'repo' => 'pikesley/catface', 'sha' => 'd230ca31f494a00dd2efbdf8f64273f991c388a6', 'size' => 16, 'url' => 'https://api.github.com/repos/pikesley/catface/contents/worm-treatment.csv?ref=master', @@ -99,7 +99,7 @@ module Dashboard it 'extracts a repo name' do expect(described_class.extract_repo 'https://api.github.com/repos/pikesley/catface/contents/flea-treatment.csv?ref=master').to eq ( - 'catface' + 'pikesley/catface' ) end end From 0989cdbe88632ccdde81f5414c7af84a4e8effa3 Mon Sep 17 00:00:00 2001 From: pikesley Date: Sun, 3 Jan 2016 14:52:31 +0000 Subject: [PATCH 5/7] JSON per-repo --- features/catface.feature | 1 - features/json.feature | 7 ++++++- features/support/vcr.rb | 1 - lib/dashboard.rb | 15 +++++++++++---- 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/features/catface.feature b/features/catface.feature index aee0078..7d1f498 100644 --- a/features/catface.feature +++ b/features/catface.feature @@ -4,4 +4,3 @@ Feature: Get Catface data When I send a GET request to "/catface" Then the response status should be "200" And the XML response should have "//title" with the text "Catface" - And the XML response should have "//div[@id = 'numbers']" diff --git a/features/json.feature b/features/json.feature index 2bdf2b6..fe0d769 100644 --- a/features/json.feature +++ b/features/json.feature @@ -1,11 +1,16 @@ +@vcr Feature: Get JSON Background: Given I send and accept JSON - @vcr Scenario: Get JSON for a dataset When I send a GET request to "catface/flea-treatment" Then the response status should be "200" And the JSON response should have "$.title" with the text "Flea Treatment" And the JSON response should have "$.data[0].Date" with the text "2015-12-03" + + Scenario: Get JSON for a repo + When I send a GET request to "snake" + Then the response status should be "200" + And the JSON response should have "$[0]name" with the text "feeds" diff --git a/features/support/vcr.rb b/features/support/vcr.rb index a639c06..475c1cf 100644 --- a/features/support/vcr.rb +++ b/features/support/vcr.rb @@ -3,7 +3,6 @@ VCR.configure do |c| c.default_cassette_options = { :record => :once } - c.cassette_library_dir = 'features/support/vcr' c.hook_into :webmock c.allow_http_connections_when_no_cassette = false diff --git a/lib/dashboard.rb b/lib/dashboard.rb index a11377e..bed9ebe 100644 --- a/lib/dashboard.rb +++ b/lib/dashboard.rb @@ -37,7 +37,6 @@ class App < Sinatra::Base respond_to do |wants| headers 'Vary' => 'Accept' - repo = repo_map[params[:repo]] wants.html do @title = 'Catface' @@ -45,8 +44,15 @@ class App < Sinatra::Base end wants.json do - urls = Fetcher.list_CSVs(repo_map[params[:repo]]) - urls.map { |url| Cleaner.sanitized_data url }.to_json + urls = Fetcher.list_CSVs Cleaner.lookups[params[:repo]]['repo'] + urls.map { |url| + Cleaner.sanitized_data url + }.map { |dataset| + { + name: dataset['id'], + url: "#{request.scheme}://#{request.env['HTTP_HOST']}/#{params[:repo]}/#{dataset['id']}" + } + }.to_json end end end @@ -56,7 +62,8 @@ class App < Sinatra::Base headers 'Vary' => 'Accept' wants.json do - Cleaner.sanitized_data("https://api.github.com/repos/#{Cleaner.lookups[params[:repo]]['repo']}/contents/#{params[:dataset]}.csv?ref=master").to_json + url = "https://api.github.com/repos/#{Cleaner.lookups[params[:repo]]['repo']}/contents/#{params[:dataset]}.csv?ref=master" + Cleaner.sanitized_data(url).to_json end wants.html do From 8b23654a9f14b2ee404d5c7074e13103fdbadea4 Mon Sep 17 00:00:00 2001 From: pikesley Date: Sun, 3 Jan 2016 15:38:48 +0000 Subject: [PATCH 6/7] Tidy up --- features/json.feature | 10 +- features/step_definitions/dashboard_steps.rb | 7 + .../vcr/Get_JSON/Get_JSON_for_a_repo.yml | 870 ++++++++++++++++++ lib/dashboard.rb | 9 +- lib/dashboard/cleaner.rb | 2 +- lib/dashboard/racks.rb | 5 +- spec/cleaner_spec.rb | 4 +- 7 files changed, 896 insertions(+), 11 deletions(-) create mode 100644 features/support/vcr/Get_JSON/Get_JSON_for_a_repo.yml diff --git a/features/json.feature b/features/json.feature index fe0d769..f091c66 100644 --- a/features/json.feature +++ b/features/json.feature @@ -4,13 +4,13 @@ Feature: Get JSON Background: Given I send and accept JSON + Scenario: Get JSON for a repo + When I send a GET request to "snake" + Then the response status should be "200" + And the JSON response should have "$[0]name" with the text "feeds" + Scenario: Get JSON for a dataset When I send a GET request to "catface/flea-treatment" Then the response status should be "200" And the JSON response should have "$.title" with the text "Flea Treatment" And the JSON response should have "$.data[0].Date" with the text "2015-12-03" - - Scenario: Get JSON for a repo - When I send a GET request to "snake" - Then the response status should be "200" - And the JSON response should have "$[0]name" with the text "feeds" diff --git a/features/step_definitions/dashboard_steps.rb b/features/step_definitions/dashboard_steps.rb index e69de29..c6385cf 100644 --- a/features/step_definitions/dashboard_steps.rb +++ b/features/step_definitions/dashboard_steps.rb @@ -0,0 +1,7 @@ +Given /^I accept CSV$/ do + add_headers( + { + 'Accept' => 'text/csv' + } + ) +end diff --git a/features/support/vcr/Get_JSON/Get_JSON_for_a_repo.yml b/features/support/vcr/Get_JSON/Get_JSON_for_a_repo.yml new file mode 100644 index 0000000..73d3e29 --- /dev/null +++ b/features/support/vcr/Get_JSON/Get_JSON_for_a_repo.yml @@ -0,0 +1,870 @@ +--- +http_interactions: +- request: + method: get + uri: https://api.github.com/repos/pikesley/snake-data/contents?client_id=&client_secret= + body: + encoding: US-ASCII + string: '' + headers: + Accept: + - application/vnd.github.v3+json + User-Agent: + - Dashboard v0.0.1 + response: + status: + code: 200 + message: OK + headers: + Server: + - GitHub.com + Date: + - Sun, 03 Jan 2016 15:22:39 GMT + Content-Type: + - application/json; charset=utf-8 + Content-Length: + - '4598' + Status: + - 200 OK + X-Ratelimit-Limit: + - '5000' + X-Ratelimit-Remaining: + - '4999' + X-Ratelimit-Reset: + - '1451838159' + Cache-Control: + - public, max-age=60, s-maxage=60 + Last-Modified: + - Thu, 23 Jul 2015 18:42:48 GMT + Etag: + - '"d37de446dca0d03c8a6fb9d79e759685"' + Vary: + - Accept + - Accept-Encoding + X-Github-Media-Type: + - github.v3; format=json + Access-Control-Allow-Credentials: + - 'true' + Access-Control-Expose-Headers: + - ETag, Link, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, + X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval + Access-Control-Allow-Origin: + - "*" + Content-Security-Policy: + - default-src 'none' + Strict-Transport-Security: + - max-age=31536000; includeSubdomains; preload + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - deny + X-Xss-Protection: + - 1; mode=block + X-Served-By: + - 7b641bda7ec2ca7cd9df72d2578baf75 + X-Github-Request-Id: + - 5102724B:134F3:21A35995:56893CBF + body: + encoding: UTF-8 + string: '[{"name":"README.md","path":"README.md","sha":"56fa2a57da9f365c2260e3479938f59774535aa9","size":379,"url":"https://api.github.com/repos/pikesley/snake-data/contents/README.md?ref=master","html_url":"https://github.com/pikesley/snake-data/blob/master/README.md","git_url":"https://api.github.com/repos/pikesley/snake-data/git/blobs/56fa2a57da9f365c2260e3479938f59774535aa9","download_url":"https://raw.githubusercontent.com/pikesley/snake-data/master/README.md","type":"file","_links":{"self":"https://api.github.com/repos/pikesley/snake-data/contents/README.md?ref=master","git":"https://api.github.com/repos/pikesley/snake-data/git/blobs/56fa2a57da9f365c2260e3479938f59774535aa9","html":"https://github.com/pikesley/snake-data/blob/master/README.md"}},{"name":"feeds.csv","path":"feeds.csv","sha":"22faa82d87ed66d62483dfd9ec8db3e43875b77e","size":1379,"url":"https://api.github.com/repos/pikesley/snake-data/contents/feeds.csv?ref=master","html_url":"https://github.com/pikesley/snake-data/blob/master/feeds.csv","git_url":"https://api.github.com/repos/pikesley/snake-data/git/blobs/22faa82d87ed66d62483dfd9ec8db3e43875b77e","download_url":"https://raw.githubusercontent.com/pikesley/snake-data/master/feeds.csv","type":"file","_links":{"self":"https://api.github.com/repos/pikesley/snake-data/contents/feeds.csv?ref=master","git":"https://api.github.com/repos/pikesley/snake-data/git/blobs/22faa82d87ed66d62483dfd9ec8db3e43875b77e","html":"https://github.com/pikesley/snake-data/blob/master/feeds.csv"}},{"name":"length.csv","path":"length.csv","sha":"8d81d82abac88d3ef7ce74de0199a985af3df0d9","size":129,"url":"https://api.github.com/repos/pikesley/snake-data/contents/length.csv?ref=master","html_url":"https://github.com/pikesley/snake-data/blob/master/length.csv","git_url":"https://api.github.com/repos/pikesley/snake-data/git/blobs/8d81d82abac88d3ef7ce74de0199a985af3df0d9","download_url":"https://raw.githubusercontent.com/pikesley/snake-data/master/length.csv","type":"file","_links":{"self":"https://api.github.com/repos/pikesley/snake-data/contents/length.csv?ref=master","git":"https://api.github.com/repos/pikesley/snake-data/git/blobs/8d81d82abac88d3ef7ce74de0199a985af3df0d9","html":"https://github.com/pikesley/snake-data/blob/master/length.csv"}},{"name":"sheds.csv","path":"sheds.csv","sha":"ee119ef5c5591ab85412cdfa1edf64b9aadfdbd0","size":348,"url":"https://api.github.com/repos/pikesley/snake-data/contents/sheds.csv?ref=master","html_url":"https://github.com/pikesley/snake-data/blob/master/sheds.csv","git_url":"https://api.github.com/repos/pikesley/snake-data/git/blobs/ee119ef5c5591ab85412cdfa1edf64b9aadfdbd0","download_url":"https://raw.githubusercontent.com/pikesley/snake-data/master/sheds.csv","type":"file","_links":{"self":"https://api.github.com/repos/pikesley/snake-data/contents/sheds.csv?ref=master","git":"https://api.github.com/repos/pikesley/snake-data/git/blobs/ee119ef5c5591ab85412cdfa1edf64b9aadfdbd0","html":"https://github.com/pikesley/snake-data/blob/master/sheds.csv"}},{"name":"vivarium-cleans.csv","path":"vivarium-cleans.csv","sha":"cfa874c2b739ff8f361d81c21c0393f58235ede9","size":213,"url":"https://api.github.com/repos/pikesley/snake-data/contents/vivarium-cleans.csv?ref=master","html_url":"https://github.com/pikesley/snake-data/blob/master/vivarium-cleans.csv","git_url":"https://api.github.com/repos/pikesley/snake-data/git/blobs/cfa874c2b739ff8f361d81c21c0393f58235ede9","download_url":"https://raw.githubusercontent.com/pikesley/snake-data/master/vivarium-cleans.csv","type":"file","_links":{"self":"https://api.github.com/repos/pikesley/snake-data/contents/vivarium-cleans.csv?ref=master","git":"https://api.github.com/repos/pikesley/snake-data/git/blobs/cfa874c2b739ff8f361d81c21c0393f58235ede9","html":"https://github.com/pikesley/snake-data/blob/master/vivarium-cleans.csv"}},{"name":"weight.csv","path":"weight.csv","sha":"b0b418cf878fec4006d7cef5c60725a83f6a1f4d","size":506,"url":"https://api.github.com/repos/pikesley/snake-data/contents/weight.csv?ref=master","html_url":"https://github.com/pikesley/snake-data/blob/master/weight.csv","git_url":"https://api.github.com/repos/pikesley/snake-data/git/blobs/b0b418cf878fec4006d7cef5c60725a83f6a1f4d","download_url":"https://raw.githubusercontent.com/pikesley/snake-data/master/weight.csv","type":"file","_links":{"self":"https://api.github.com/repos/pikesley/snake-data/contents/weight.csv?ref=master","git":"https://api.github.com/repos/pikesley/snake-data/git/blobs/b0b418cf878fec4006d7cef5c60725a83f6a1f4d","html":"https://github.com/pikesley/snake-data/blob/master/weight.csv"}}]' + http_version: + recorded_at: Sun, 03 Jan 2016 15:22:39 GMT +- request: + method: get + uri: https://api.github.com/repos/pikesley/snake-data/contents/feeds.csv?client_id=&client_secret=&ref=master + body: + encoding: US-ASCII + string: '' + headers: + Accept: + - application/vnd.github.v3+json + User-Agent: + - Dashboard v0.0.1 + response: + status: + code: 200 + message: OK + headers: + Server: + - GitHub.com + Date: + - Sun, 03 Jan 2016 15:22:40 GMT + Content-Type: + - application/json; charset=utf-8 + Content-Length: + - '2687' + Status: + - 200 OK + X-Ratelimit-Limit: + - '5000' + X-Ratelimit-Remaining: + - '4998' + X-Ratelimit-Reset: + - '1451838159' + Cache-Control: + - public, max-age=60, s-maxage=60 + Last-Modified: + - Sat, 02 Jan 2016 13:29:48 GMT + Etag: + - '"87db99e13db3e24bd40be0bd0fc66dcc"' + Vary: + - Accept + - Accept-Encoding + X-Github-Media-Type: + - github.v3; format=json + Access-Control-Allow-Credentials: + - 'true' + Access-Control-Expose-Headers: + - ETag, Link, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, + X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval + Access-Control-Allow-Origin: + - "*" + Content-Security-Policy: + - default-src 'none' + Strict-Transport-Security: + - max-age=31536000; includeSubdomains; preload + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - deny + X-Xss-Protection: + - 1; mode=block + X-Served-By: + - 76d9828c7e4f1d910f7ba069e90ce976 + X-Github-Request-Id: + - 5102724B:134F0:DE6D9C3:56893CBF + body: + encoding: UTF-8 + string: '{"name":"feeds.csv","path":"feeds.csv","sha":"22faa82d87ed66d62483dfd9ec8db3e43875b77e","size":1379,"url":"https://api.github.com/repos/pikesley/snake-data/contents/feeds.csv?ref=master","html_url":"https://github.com/pikesley/snake-data/blob/master/feeds.csv","git_url":"https://api.github.com/repos/pikesley/snake-data/git/blobs/22faa82d87ed66d62483dfd9ec8db3e43875b77e","download_url":"https://raw.githubusercontent.com/pikesley/snake-data/master/feeds.csv","type":"file","content":"RGF0ZSxGb29kLE9mZmVyZWQsRWF0ZW4KMjAxNC0wOS0yOCxQaW5reSwxLDEK\nMjAxNC0xMC0wMixQaW5reSwyLDIKMjAxNC0xMC0wNixQaW5reSwyLDEKMjAx\nNC0xMC0xMixQaW5reSwyLDAKMjAxNC0xMC0xOSxQaW5reSwyLDIKMjAxNC0x\nMC0yNixQaW5reSwzLDMKMjAxNC0xMS0wMixGdXp6eSwxLDEKMjAxNC0xMS0w\nOSxGdXp6eSwxLDEKMjAxNC0xMS0xNixGdXp6eSwxLDEKMjAxNC0xMS0yMyxG\ndXp6eSwxLDEKMjAxNC0xMi0wNyxGdXp6eSwxLDEKMjAxNC0xMi0xNCxGdXp6\neSwxLDEKMjAxNS0wMS0wMSxGdXp6eSwxLDEKMjAxNS0wMS0xMSxGdXp6eSwx\nLDEKMjAxNS0wMS0xOCxGdXp6eSwyLDIKMjAxNS0wMS0yNSxGdXp6eSwxLDEK\nMjAxNS0wMi0wMSxGdXp6eSwxLDAKMjAxNS0wMi0wOCxGdXp6eSwyLDIKMjAx\nNS0wMi0xNSxGdXp6eSwxLDEKMjAxNS0wMi0yMixGdXp6eSwyLDIKMjAxNS0w\nMy0wMSxGdXp6eSwxLDAKMjAxNS0wMy0wOCxGdXp6eSwyLDIKMjAxNS0wMy0x\nNixGdXp6eSwxLDEKMjAxNS0wMy0yMixGdXp6eSwyLDIKMjAxNS0wMy0yOSxG\ndXp6eSwyLDIKMjAxNS0wNC0wNSxIb3BwZXIsMSwxCjIwMTUtMDQtMTIsSG9w\ncGVyLDEsMQoyMDE1LTA0LTE5LEhvcHBlciwxLDEKMjAxNS0wNC0yNixIb3Bw\nZXIsMSwxCjIwMTUtMDUtMTAsSG9wcGVyLDEsMQoyMDE1LTA1LTE3LEhvcHBl\nciwxLDEKMjAxNS0wNS0yNCxIb3BwZXIsMSwxCjIwMTUtMDUtMzEsSG9wcGVy\nLDEsMQoyMDE1LTA2LTA3LEhvcHBlciwxLDEKMjAxNS0wNi0xNCxIb3BwZXIs\nMSwxCjIwMTUtMDYtMjEsSG9wcGVyLDEsMQoyMDE1LTA3LTA1LFdlYW5lZCBN\nb3VzZSwxLDEKMjAxNS0wNy0xMixXZWFuZWQgTW91c2UsMSwxCjIwMTUtMDct\nMTksV2VhbmVkIE1vdXNlLDEsMQoyMDE1LTA3LTI2LFdlYW5lZCBNb3VzZSwx\nLDEKMjAxNS0wOC0wMixXZWFuZWQgTW91c2UsMSwxCjIwMTUtMDgtMDksV2Vh\nbmVkIE1vdXNlLDEsMQoyMDE1LTA4LTE2LFdlYW5lZCBNb3VzZSwxLDEKMjAx\nNS0wOC0yMyxXZWFuZWQgTW91c2UsMSwxCjIwMTUtMDgtMzAsV2VhbmVkIE1v\ndXNlLDEsMQoyMDE1LTA5LTA2LFdlYW5lZCBNb3VzZSwxLDEKMjAxNS0xMC0w\nNCxXZWFuZWQgTW91c2UsMSwxCjIwMTUtMTAtMTEsV2VhbmVkIE1vdXNlLDEs\nMQoyMDE1LTEwLTE4LFdlYW5lZCBNb3VzZSwxLDEKMjAxNS0xMC0yNSxXZWFu\nZWQgTW91c2UsMSwxCjIwMTUtMTEtMDEsV2VhbmVkIE1vdXNlLDEsMQoyMDE1\nLTExLTExLFdlYW5lZCBNb3VzZSwxLDEKMjAxNS0xMS0yMixXZWFuZWQgTW91\nc2UsMSwxCjIwMTUtMTEtMjksV2VhbmVkIE1vdXNlLDEsMQoyMDE1LTEyLTA2\nLFdlYW5lZCBNb3VzZSwxLDEKMjAxNS0xMi0xMyxXZWFuZWQgTW91c2UsMSwx\nCjIwMTUtMTItMjMsV2VhbmVkIE1vdXNlLDEsMQo=\n","encoding":"base64","_links":{"self":"https://api.github.com/repos/pikesley/snake-data/contents/feeds.csv?ref=master","git":"https://api.github.com/repos/pikesley/snake-data/git/blobs/22faa82d87ed66d62483dfd9ec8db3e43875b77e","html":"https://github.com/pikesley/snake-data/blob/master/feeds.csv"}}' + http_version: + recorded_at: Sun, 03 Jan 2016 15:22:40 GMT +- request: + method: get + uri: https://raw.githubusercontent.com/pikesley/snake-data/master/feeds.csv?client_id=&client_secret= + body: + encoding: US-ASCII + string: '' + headers: + Accept: + - application/vnd.github.v3+json + User-Agent: + - Dashboard v0.0.1 + response: + status: + code: 200 + message: OK + headers: + Content-Security-Policy: + - default-src 'none' + X-Xss-Protection: + - 1; mode=block + X-Frame-Options: + - deny + X-Content-Type-Options: + - nosniff + Strict-Transport-Security: + - max-age=31536000 + Etag: + - '"22faa82d87ed66d62483dfd9ec8db3e43875b77e"' + Content-Type: + - text/plain; charset=utf-8 + Cache-Control: + - max-age=300 + X-Github-Request-Id: + - B91F1322:2F44:445C8713:56893CC0 + Content-Length: + - '1379' + Accept-Ranges: + - bytes + Date: + - Sun, 03 Jan 2016 15:22:40 GMT + Via: + - 1.1 varnish + Connection: + - keep-alive + X-Served-By: + - cache-lhr6320-LHR + X-Cache: + - MISS + X-Cache-Hits: + - '0' + Vary: + - Authorization,Accept-Encoding + Access-Control-Allow-Origin: + - "*" + X-Fastly-Request-Id: + - cc6c61b8f8e50592be8dd6738dfa5e305acc7548 + Expires: + - Sun, 03 Jan 2016 15:27:40 GMT + Source-Age: + - '0' + body: + encoding: UTF-8 + string: | + Date,Food,Offered,Eaten + 2014-09-28,Pinky,1,1 + 2014-10-02,Pinky,2,2 + 2014-10-06,Pinky,2,1 + 2014-10-12,Pinky,2,0 + 2014-10-19,Pinky,2,2 + 2014-10-26,Pinky,3,3 + 2014-11-02,Fuzzy,1,1 + 2014-11-09,Fuzzy,1,1 + 2014-11-16,Fuzzy,1,1 + 2014-11-23,Fuzzy,1,1 + 2014-12-07,Fuzzy,1,1 + 2014-12-14,Fuzzy,1,1 + 2015-01-01,Fuzzy,1,1 + 2015-01-11,Fuzzy,1,1 + 2015-01-18,Fuzzy,2,2 + 2015-01-25,Fuzzy,1,1 + 2015-02-01,Fuzzy,1,0 + 2015-02-08,Fuzzy,2,2 + 2015-02-15,Fuzzy,1,1 + 2015-02-22,Fuzzy,2,2 + 2015-03-01,Fuzzy,1,0 + 2015-03-08,Fuzzy,2,2 + 2015-03-16,Fuzzy,1,1 + 2015-03-22,Fuzzy,2,2 + 2015-03-29,Fuzzy,2,2 + 2015-04-05,Hopper,1,1 + 2015-04-12,Hopper,1,1 + 2015-04-19,Hopper,1,1 + 2015-04-26,Hopper,1,1 + 2015-05-10,Hopper,1,1 + 2015-05-17,Hopper,1,1 + 2015-05-24,Hopper,1,1 + 2015-05-31,Hopper,1,1 + 2015-06-07,Hopper,1,1 + 2015-06-14,Hopper,1,1 + 2015-06-21,Hopper,1,1 + 2015-07-05,Weaned Mouse,1,1 + 2015-07-12,Weaned Mouse,1,1 + 2015-07-19,Weaned Mouse,1,1 + 2015-07-26,Weaned Mouse,1,1 + 2015-08-02,Weaned Mouse,1,1 + 2015-08-09,Weaned Mouse,1,1 + 2015-08-16,Weaned Mouse,1,1 + 2015-08-23,Weaned Mouse,1,1 + 2015-08-30,Weaned Mouse,1,1 + 2015-09-06,Weaned Mouse,1,1 + 2015-10-04,Weaned Mouse,1,1 + 2015-10-11,Weaned Mouse,1,1 + 2015-10-18,Weaned Mouse,1,1 + 2015-10-25,Weaned Mouse,1,1 + 2015-11-01,Weaned Mouse,1,1 + 2015-11-11,Weaned Mouse,1,1 + 2015-11-22,Weaned Mouse,1,1 + 2015-11-29,Weaned Mouse,1,1 + 2015-12-06,Weaned Mouse,1,1 + 2015-12-13,Weaned Mouse,1,1 + 2015-12-23,Weaned Mouse,1,1 + http_version: + recorded_at: Sun, 03 Jan 2016 15:22:40 GMT +- request: + method: get + uri: https://api.github.com/repos/pikesley/snake-data/contents/length.csv?client_id=&client_secret=&ref=master + body: + encoding: US-ASCII + string: '' + headers: + Accept: + - application/vnd.github.v3+json + User-Agent: + - Dashboard v0.0.1 + response: + status: + code: 200 + message: OK + headers: + Server: + - GitHub.com + Date: + - Sun, 03 Jan 2016 15:22:41 GMT + Content-Type: + - application/json; charset=utf-8 + Content-Length: + - '969' + Status: + - 200 OK + X-Ratelimit-Limit: + - '5000' + X-Ratelimit-Remaining: + - '4997' + X-Ratelimit-Reset: + - '1451838159' + Cache-Control: + - public, max-age=60, s-maxage=60 + Last-Modified: + - Sat, 02 Jan 2016 13:29:48 GMT + Etag: + - '"fe5e67566d60252dcce1fc2df6f5d7a1"' + Vary: + - Accept + - Accept-Encoding + X-Github-Media-Type: + - github.v3; format=json + Access-Control-Allow-Credentials: + - 'true' + Access-Control-Expose-Headers: + - ETag, Link, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, + X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval + Access-Control-Allow-Origin: + - "*" + Content-Security-Policy: + - default-src 'none' + Strict-Transport-Security: + - max-age=31536000; includeSubdomains; preload + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - deny + X-Xss-Protection: + - 1; mode=block + X-Served-By: + - cee4c0729c8e9147e7abcb45b9d69689 + X-Github-Request-Id: + - 5102724B:134F5:1C824CC8:56893CC0 + body: + encoding: UTF-8 + string: '{"name":"length.csv","path":"length.csv","sha":"8d81d82abac88d3ef7ce74de0199a985af3df0d9","size":129,"url":"https://api.github.com/repos/pikesley/snake-data/contents/length.csv?ref=master","html_url":"https://github.com/pikesley/snake-data/blob/master/length.csv","git_url":"https://api.github.com/repos/pikesley/snake-data/git/blobs/8d81d82abac88d3ef7ce74de0199a985af3df0d9","download_url":"https://raw.githubusercontent.com/pikesley/snake-data/master/length.csv","type":"file","content":"RGF0ZSxMZW5ndGggaW4gbQoyMDE0LTA5LTMwLDAuNDUKMjAxNC0xMC0wOSww\nLjUwCjIwMTQtMTAtMTgsMC41MAoyMDE0LTEyLTEyLDAuNTUKMjAxNS0wMS0x\nMSwwLjYwCjIwMTUtMDEtMjgsMC42NQoyMDE1LTA4LTI3LDAuOTUK\n","encoding":"base64","_links":{"self":"https://api.github.com/repos/pikesley/snake-data/contents/length.csv?ref=master","git":"https://api.github.com/repos/pikesley/snake-data/git/blobs/8d81d82abac88d3ef7ce74de0199a985af3df0d9","html":"https://github.com/pikesley/snake-data/blob/master/length.csv"}}' + http_version: + recorded_at: Sun, 03 Jan 2016 15:22:41 GMT +- request: + method: get + uri: https://raw.githubusercontent.com/pikesley/snake-data/master/length.csv?client_id=&client_secret= + body: + encoding: US-ASCII + string: '' + headers: + Accept: + - application/vnd.github.v3+json + User-Agent: + - Dashboard v0.0.1 + response: + status: + code: 200 + message: OK + headers: + Content-Security-Policy: + - default-src 'none' + X-Xss-Protection: + - 1; mode=block + X-Frame-Options: + - deny + X-Content-Type-Options: + - nosniff + Strict-Transport-Security: + - max-age=31536000 + Etag: + - '"8d81d82abac88d3ef7ce74de0199a985af3df0d9"' + Content-Type: + - text/plain; charset=utf-8 + Cache-Control: + - max-age=300 + X-Github-Request-Id: + - B91F1320:2F42:33FAAF58:56893CC0 + Content-Length: + - '129' + Accept-Ranges: + - bytes + Date: + - Sun, 03 Jan 2016 15:22:41 GMT + Via: + - 1.1 varnish + Connection: + - keep-alive + X-Served-By: + - cache-lhr6328-LHR + X-Cache: + - MISS + X-Cache-Hits: + - '0' + Vary: + - Authorization,Accept-Encoding + Access-Control-Allow-Origin: + - "*" + X-Fastly-Request-Id: + - 3d97e9a8f0297bcc61c3349286a5f679741eedef + Expires: + - Sun, 03 Jan 2016 15:27:41 GMT + Source-Age: + - '0' + body: + encoding: UTF-8 + string: | + 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 + http_version: + recorded_at: Sun, 03 Jan 2016 15:22:41 GMT +- request: + method: get + uri: https://api.github.com/repos/pikesley/snake-data/contents/sheds.csv?client_id=&client_secret=&ref=master + body: + encoding: US-ASCII + string: '' + headers: + Accept: + - application/vnd.github.v3+json + User-Agent: + - Dashboard v0.0.1 + response: + status: + code: 200 + message: OK + headers: + Server: + - GitHub.com + Date: + - Sun, 03 Jan 2016 15:22:41 GMT + Content-Type: + - application/json; charset=utf-8 + Content-Length: + - '1264' + Status: + - 200 OK + X-Ratelimit-Limit: + - '5000' + X-Ratelimit-Remaining: + - '4996' + X-Ratelimit-Reset: + - '1451838159' + Cache-Control: + - public, max-age=60, s-maxage=60 + Last-Modified: + - Sat, 02 Jan 2016 13:29:48 GMT + Etag: + - '"2464347220382b60c962228f3c53fd30"' + Vary: + - Accept + - Accept-Encoding + X-Github-Media-Type: + - github.v3; format=json + Access-Control-Allow-Credentials: + - 'true' + Access-Control-Expose-Headers: + - ETag, Link, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, + X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval + Access-Control-Allow-Origin: + - "*" + Content-Security-Policy: + - default-src 'none' + Strict-Transport-Security: + - max-age=31536000; includeSubdomains; preload + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - deny + X-Xss-Protection: + - 1; mode=block + X-Served-By: + - 2811da37fbdda4367181b328b22b2499 + X-Github-Request-Id: + - 5102724B:134F0:DE6DA4B:56893CC1 + body: + encoding: UTF-8 + string: '{"name":"sheds.csv","path":"sheds.csv","sha":"ee119ef5c5591ab85412cdfa1edf64b9aadfdbd0","size":348,"url":"https://api.github.com/repos/pikesley/snake-data/contents/sheds.csv?ref=master","html_url":"https://github.com/pikesley/snake-data/blob/master/sheds.csv","git_url":"https://api.github.com/repos/pikesley/snake-data/git/blobs/ee119ef5c5591ab85412cdfa1edf64b9aadfdbd0","download_url":"https://raw.githubusercontent.com/pikesley/snake-data/master/sheds.csv","type":"file","content":"U2VyaWFsLEJsdWUgcGhhc2Ugb2JzZXJ2ZWQsU2hlZCBjb21wbGV0ZWQKMSwy\nMDE0LTEwLTEzLDIwMTQtMTAtMTcKMiwyMDE0LTExLTE2LDIwMTQtMTEtMjIK\nMywyMDE0LTEyLTIzLDIwMTQtMTItMzEKNCwyMDE1LTAxLTMxLDIwMTUtMDIt\nMDUKNSwyMDE1LTAzLTAxLDIwMTUtMDMtMDYKNiwyMDE1LTA0LTA3LDIwMTUt\nMDQtMTIKNywyMDE1LTA1LTAyLDIwMTUtMDUtMDcKOCwsMjAxNS0wNi0wNQo5\nLDIwMTUtMDctMDgsMjAxNS0wNy0xMgoxMCwyMDE1LTA4LTEyLDIwMTUtMDgt\nMTUKMTEsMjAxNS0wOS0xMiwyMDE1LTA5LTE5CjEyLDIwMTUtMTEtMDEsMjAx\nNS0xMS0xMAoxMywyMDE1LTEyLTEzLDIwMTUtMTItMjMK\n","encoding":"base64","_links":{"self":"https://api.github.com/repos/pikesley/snake-data/contents/sheds.csv?ref=master","git":"https://api.github.com/repos/pikesley/snake-data/git/blobs/ee119ef5c5591ab85412cdfa1edf64b9aadfdbd0","html":"https://github.com/pikesley/snake-data/blob/master/sheds.csv"}}' + http_version: + recorded_at: Sun, 03 Jan 2016 15:22:41 GMT +- request: + method: get + uri: https://raw.githubusercontent.com/pikesley/snake-data/master/sheds.csv?client_id=&client_secret= + body: + encoding: US-ASCII + string: '' + headers: + Accept: + - application/vnd.github.v3+json + User-Agent: + - Dashboard v0.0.1 + response: + status: + code: 200 + message: OK + headers: + Content-Security-Policy: + - default-src 'none' + X-Xss-Protection: + - 1; mode=block + X-Frame-Options: + - deny + X-Content-Type-Options: + - nosniff + Strict-Transport-Security: + - max-age=31536000 + Etag: + - '"ee119ef5c5591ab85412cdfa1edf64b9aadfdbd0"' + Content-Type: + - text/plain; charset=utf-8 + Cache-Control: + - max-age=300 + X-Github-Request-Id: + - B91F1317:2F40:1D426397:56893CC1 + Content-Length: + - '348' + Accept-Ranges: + - bytes + Date: + - Sun, 03 Jan 2016 15:22:42 GMT + Via: + - 1.1 varnish + Connection: + - keep-alive + X-Served-By: + - cache-lhr6334-LHR + X-Cache: + - MISS + X-Cache-Hits: + - '0' + Vary: + - Authorization,Accept-Encoding + Access-Control-Allow-Origin: + - "*" + X-Fastly-Request-Id: + - 853bb4a0ea83140e53fb2b34f4f33a9d18ffcac4 + Expires: + - Sun, 03 Jan 2016 15:27:42 GMT + Source-Age: + - '0' + body: + encoding: UTF-8 + string: | + Serial,Blue phase observed,Shed completed + 1,2014-10-13,2014-10-17 + 2,2014-11-16,2014-11-22 + 3,2014-12-23,2014-12-31 + 4,2015-01-31,2015-02-05 + 5,2015-03-01,2015-03-06 + 6,2015-04-07,2015-04-12 + 7,2015-05-02,2015-05-07 + 8,,2015-06-05 + 9,2015-07-08,2015-07-12 + 10,2015-08-12,2015-08-15 + 11,2015-09-12,2015-09-19 + 12,2015-11-01,2015-11-10 + 13,2015-12-13,2015-12-23 + http_version: + recorded_at: Sun, 03 Jan 2016 15:22:42 GMT +- request: + method: get + uri: https://api.github.com/repos/pikesley/snake-data/contents/vivarium-cleans.csv?client_id=&client_secret=&ref=master + body: + encoding: US-ASCII + string: '' + headers: + Accept: + - application/vnd.github.v3+json + User-Agent: + - Dashboard v0.0.1 + response: + status: + code: 200 + message: OK + headers: + Server: + - GitHub.com + Date: + - Sun, 03 Jan 2016 15:22:42 GMT + Content-Type: + - application/json; charset=utf-8 + Content-Length: + - '1148' + Status: + - 200 OK + X-Ratelimit-Limit: + - '5000' + X-Ratelimit-Remaining: + - '4995' + X-Ratelimit-Reset: + - '1451838159' + Cache-Control: + - public, max-age=60, s-maxage=60 + Last-Modified: + - Sat, 02 Jan 2016 13:29:48 GMT + Etag: + - '"182e2943ddc8a012ab4d1fec77a70417"' + Vary: + - Accept + - Accept-Encoding + X-Github-Media-Type: + - github.v3; format=json + Access-Control-Allow-Credentials: + - 'true' + Access-Control-Expose-Headers: + - ETag, Link, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, + X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval + Access-Control-Allow-Origin: + - "*" + Content-Security-Policy: + - default-src 'none' + Strict-Transport-Security: + - max-age=31536000; includeSubdomains; preload + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - deny + X-Xss-Protection: + - 1; mode=block + X-Served-By: + - 4c8b2d4732c413f4b9aefe394bd65569 + X-Github-Request-Id: + - 5102724B:134F5:1C824E4F:56893CC2 + body: + encoding: UTF-8 + string: '{"name":"vivarium-cleans.csv","path":"vivarium-cleans.csv","sha":"cfa874c2b739ff8f361d81c21c0393f58235ede9","size":213,"url":"https://api.github.com/repos/pikesley/snake-data/contents/vivarium-cleans.csv?ref=master","html_url":"https://github.com/pikesley/snake-data/blob/master/vivarium-cleans.csv","git_url":"https://api.github.com/repos/pikesley/snake-data/git/blobs/cfa874c2b739ff8f361d81c21c0393f58235ede9","download_url":"https://raw.githubusercontent.com/pikesley/snake-data/master/vivarium-cleans.csv","type":"file","content":"U2VyaWFsLERhdGUKMSwyMDE0LTEwLTI1CjIsMjAxNC0xMS0yMwozLDIwMTQt\nMTItMjEKNCwyMDE1LTAxLTE4CjUsMjAxNS0wMi0xNAo2LDIwMTUtMDMtMjEK\nNywyMDE1LTA0LTE4CjgsMjAxNS0wNS0yNAo5LDIwMTUtMDYtMTcKMTAsMjAx\nNS0wNy0xOAoxMSwyMDE1LTA4LTE1CjEyLDIwMTUtMDktMTIKMTMsMjAxNS0x\nMC0xOAoxNCwyMDE1LTExLTIxCjE1LDIwMTYtMDEtMDIK\n","encoding":"base64","_links":{"self":"https://api.github.com/repos/pikesley/snake-data/contents/vivarium-cleans.csv?ref=master","git":"https://api.github.com/repos/pikesley/snake-data/git/blobs/cfa874c2b739ff8f361d81c21c0393f58235ede9","html":"https://github.com/pikesley/snake-data/blob/master/vivarium-cleans.csv"}}' + http_version: + recorded_at: Sun, 03 Jan 2016 15:22:42 GMT +- request: + method: get + uri: https://raw.githubusercontent.com/pikesley/snake-data/master/vivarium-cleans.csv?client_id=&client_secret= + body: + encoding: US-ASCII + string: '' + headers: + Accept: + - application/vnd.github.v3+json + User-Agent: + - Dashboard v0.0.1 + response: + status: + code: 200 + message: OK + headers: + Content-Security-Policy: + - default-src 'none' + X-Xss-Protection: + - 1; mode=block + X-Frame-Options: + - deny + X-Content-Type-Options: + - nosniff + Strict-Transport-Security: + - max-age=31536000 + Etag: + - '"cfa874c2b739ff8f361d81c21c0393f58235ede9"' + Content-Type: + - text/plain; charset=utf-8 + Cache-Control: + - max-age=300 + X-Github-Request-Id: + - B91F1315:2F42:33FAB232:56893CC2 + Content-Length: + - '213' + Accept-Ranges: + - bytes + Date: + - Sun, 03 Jan 2016 15:22:42 GMT + Via: + - 1.1 varnish + Connection: + - keep-alive + X-Served-By: + - cache-lhr6330-LHR + X-Cache: + - MISS + X-Cache-Hits: + - '0' + Vary: + - Authorization,Accept-Encoding + Access-Control-Allow-Origin: + - "*" + X-Fastly-Request-Id: + - 8a316b1137e2a93289e0deea138b517e7b26aa65 + Expires: + - Sun, 03 Jan 2016 15:27:42 GMT + Source-Age: + - '0' + body: + encoding: UTF-8 + string: | + Serial,Date + 1,2014-10-25 + 2,2014-11-23 + 3,2014-12-21 + 4,2015-01-18 + 5,2015-02-14 + 6,2015-03-21 + 7,2015-04-18 + 8,2015-05-24 + 9,2015-06-17 + 10,2015-07-18 + 11,2015-08-15 + 12,2015-09-12 + 13,2015-10-18 + 14,2015-11-21 + 15,2016-01-02 + http_version: + recorded_at: Sun, 03 Jan 2016 15:22:42 GMT +- request: + method: get + uri: https://api.github.com/repos/pikesley/snake-data/contents/weight.csv?client_id=&client_secret=&ref=master + body: + encoding: US-ASCII + string: '' + headers: + Accept: + - application/vnd.github.v3+json + User-Agent: + - Dashboard v0.0.1 + response: + status: + code: 200 + message: OK + headers: + Server: + - GitHub.com + Date: + - Sun, 03 Jan 2016 15:22:43 GMT + Content-Type: + - application/json; charset=utf-8 + Content-Length: + - '1491' + Status: + - 200 OK + X-Ratelimit-Limit: + - '5000' + X-Ratelimit-Remaining: + - '4994' + X-Ratelimit-Reset: + - '1451838159' + Cache-Control: + - public, max-age=60, s-maxage=60 + Last-Modified: + - Sat, 02 Jan 2016 13:29:48 GMT + Etag: + - '"faf828886944f90438aa51e8831f8c63"' + Vary: + - Accept + - Accept-Encoding + X-Github-Media-Type: + - github.v3; format=json + Access-Control-Allow-Credentials: + - 'true' + Access-Control-Expose-Headers: + - ETag, Link, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, + X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval + Access-Control-Allow-Origin: + - "*" + Content-Security-Policy: + - default-src 'none' + Strict-Transport-Security: + - max-age=31536000; includeSubdomains; preload + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - deny + X-Xss-Protection: + - 1; mode=block + X-Served-By: + - e724c57ebb9961c772a91e2dd7421c8d + X-Github-Request-Id: + - 5102724B:134F4:26ECBED9:56893CC2 + body: + encoding: UTF-8 + string: '{"name":"weight.csv","path":"weight.csv","sha":"b0b418cf878fec4006d7cef5c60725a83f6a1f4d","size":506,"url":"https://api.github.com/repos/pikesley/snake-data/contents/weight.csv?ref=master","html_url":"https://github.com/pikesley/snake-data/blob/master/weight.csv","git_url":"https://api.github.com/repos/pikesley/snake-data/git/blobs/b0b418cf878fec4006d7cef5c60725a83f6a1f4d","download_url":"https://raw.githubusercontent.com/pikesley/snake-data/master/weight.csv","type":"file","content":"RGF0ZSxNYXNzIGluIGcKMjAxNC0xMC0yMywxOC4zCjIwMTQtMTAtMzEsMTkK\nMjAxNC0xMS0wNSwyMgoyMDE0LTExLTExLDIyLjgKMjAxNC0xMi0wMiwyNAoy\nMDE0LTEyLTA5LDI4LjUKMjAxNC0xMi0xNiwyOAoyMDE0LTEyLTIzLDM0LjIK\nMjAxNS0wMS0wNCwzMi4zCjIwMTUtMDEtMTMsMzUuMwoyMDE1LTAxLTIwLDQw\nLjQKMjAxNS0wMS0yOCwzNi40CjIwMTUtMDItMDgsMzMuNwoyMDE1LTAyLTEx\nLDQxLjMKMjAxNS0wMi0xOCw0My4yCjIwMTUtMDItMjUsNDkuMgoyMDE1LTAz\nLTEwLDU0LjcKMjAxNS0wMy0xMiw1MC42CjIwMTUtMDMtMTksNTMuMwoyMDE1\nLTAzLTI0LDYzLjMKMjAxNS0wNC0wMiw2NS42CjIwMTUtMDQtMTYsODQKMjAx\nNS0wNC0yMyw4NS4xCjIwMTUtMDUtMTQsMTAzLjMKMjAxNS0wNS0xNyw5Ny44\nCjIwMTUtMDUtMjYsMTE4LjcKMjAxNS0wNi0xMCwxMzYuNwoyMDE1LTA3LTAx\nLDE1NAoyMDE1LTA3LTE0LDE3Ni44CjIwMTUtMDgtMTksMjA1LjAKMjAxNi0w\nMS0wMiwzMTEuMQo=\n","encoding":"base64","_links":{"self":"https://api.github.com/repos/pikesley/snake-data/contents/weight.csv?ref=master","git":"https://api.github.com/repos/pikesley/snake-data/git/blobs/b0b418cf878fec4006d7cef5c60725a83f6a1f4d","html":"https://github.com/pikesley/snake-data/blob/master/weight.csv"}}' + http_version: + recorded_at: Sun, 03 Jan 2016 15:22:43 GMT +- request: + method: get + uri: https://raw.githubusercontent.com/pikesley/snake-data/master/weight.csv?client_id=&client_secret= + body: + encoding: US-ASCII + string: '' + headers: + Accept: + - application/vnd.github.v3+json + User-Agent: + - Dashboard v0.0.1 + response: + status: + code: 200 + message: OK + headers: + Content-Security-Policy: + - default-src 'none' + X-Xss-Protection: + - 1; mode=block + X-Frame-Options: + - deny + X-Content-Type-Options: + - nosniff + Strict-Transport-Security: + - max-age=31536000 + Etag: + - '"b0b418cf878fec4006d7cef5c60725a83f6a1f4d"' + Content-Type: + - text/plain; charset=utf-8 + Cache-Control: + - max-age=300 + X-Github-Request-Id: + - B91F1320:2F43:3D852B28:56893CC3 + Content-Length: + - '506' + Accept-Ranges: + - bytes + Date: + - Sun, 03 Jan 2016 15:22:43 GMT + Via: + - 1.1 varnish + Connection: + - keep-alive + X-Served-By: + - cache-lhr6320-LHR + X-Cache: + - MISS + X-Cache-Hits: + - '0' + Vary: + - Authorization,Accept-Encoding + Access-Control-Allow-Origin: + - "*" + X-Fastly-Request-Id: + - 2bc6081712639ff44250e286e090ea83e9787405 + Expires: + - Sun, 03 Jan 2016 15:27:43 GMT + Source-Age: + - '0' + body: + encoding: UTF-8 + string: | + Date,Mass in g + 2014-10-23,18.3 + 2014-10-31,19 + 2014-11-05,22 + 2014-11-11,22.8 + 2014-12-02,24 + 2014-12-09,28.5 + 2014-12-16,28 + 2014-12-23,34.2 + 2015-01-04,32.3 + 2015-01-13,35.3 + 2015-01-20,40.4 + 2015-01-28,36.4 + 2015-02-08,33.7 + 2015-02-11,41.3 + 2015-02-18,43.2 + 2015-02-25,49.2 + 2015-03-10,54.7 + 2015-03-12,50.6 + 2015-03-19,53.3 + 2015-03-24,63.3 + 2015-04-02,65.6 + 2015-04-16,84 + 2015-04-23,85.1 + 2015-05-14,103.3 + 2015-05-17,97.8 + 2015-05-26,118.7 + 2015-06-10,136.7 + 2015-07-01,154 + 2015-07-14,176.8 + 2015-08-19,205.0 + 2016-01-02,311.1 + http_version: + recorded_at: Sun, 03 Jan 2016 15:22:43 GMT +recorded_with: VCR 3.0.1 diff --git a/lib/dashboard.rb b/lib/dashboard.rb index bed9ebe..4d21b22 100644 --- a/lib/dashboard.rb +++ b/lib/dashboard.rb @@ -37,7 +37,6 @@ class App < Sinatra::Base respond_to do |wants| headers 'Vary' => 'Accept' - wants.html do @title = 'Catface' erb :grid, layout: :default @@ -50,7 +49,7 @@ class App < Sinatra::Base }.map { |dataset| { name: dataset['id'], - url: "#{request.scheme}://#{request.env['HTTP_HOST']}/#{params[:repo]}/#{dataset['id']}" + url: "#{request.scheme}://#{request.env['HTTP_HOST']}/#{params[:repo]}/#{dataset['id']}.json" } }.to_json end @@ -66,6 +65,12 @@ class App < Sinatra::Base Cleaner.sanitized_data(url).to_json end + wants.csv do + puts "WTF" + require "pry" ; binding.pry + + end + wants.html do erb :dataset, layout: :default end diff --git a/lib/dashboard/cleaner.rb b/lib/dashboard/cleaner.rb index b4f471e..bf5258d 100644 --- a/lib/dashboard/cleaner.rb +++ b/lib/dashboard/cleaner.rb @@ -39,7 +39,7 @@ def self.sanitized_data url j['id'] = trim d['name'] j['date-field'] = l.dig(d['repo'], 'datasets', trim(d['name']), 'date-field') || 'Date' j['type'] = l.dig(d['repo'], 'datasets', trim(d['name']), 'type') || 'latest' - j['url'] = d['_links']['html'] + j['source-url'] = d['_links']['html'] sf = l.dig(d['repo'], 'datasets', trim(d['name']), 'special-fields') j['special_fields'] = sf if sf j['data'] = jsonise d['data'] diff --git a/lib/dashboard/racks.rb b/lib/dashboard/racks.rb index feb48b4..6bfbd48 100644 --- a/lib/dashboard/racks.rb +++ b/lib/dashboard/racks.rb @@ -5,7 +5,10 @@ class App < Sinatra::Base conneg.set :fallback, :html conneg.ignore('/css/') conneg.ignore('/js/') - conneg.provide([:html, :json]) + conneg.provide [ + :html, + :json + ] end before do diff --git a/spec/cleaner_spec.rb b/spec/cleaner_spec.rb index f6372b0..2c7c807 100644 --- a/spec/cleaner_spec.rb +++ b/spec/cleaner_spec.rb @@ -77,7 +77,7 @@ module Dashboard 'name' => 'length.csv', 'id' => 'length', 'type' => 'graph', - 'url' => 'https://github.com/pikesley/snake-data/blob/master/length.csv', + 'source-url' => 'https://github.com/pikesley/snake-data/blob/master/length.csv', 'data' => [ { 'Date' => '2014-09-30', @@ -120,7 +120,7 @@ module Dashboard 'name' => 'flea-treatment.csv', 'id' => 'flea-treatment', 'type' => 'latest', - 'url' => 'https://github.com/pikesley/catface/blob/master/flea-treatment.csv', + 'source-url' => 'https://github.com/pikesley/catface/blob/master/flea-treatment.csv', 'data' => [ { 'Date' => '2015-12-03' From 41223f67b7049613c68e9dbe43905f1465cbe4b5 Mon Sep 17 00:00:00 2001 From: pikesley Date: Sun, 3 Jan 2016 17:05:17 +0000 Subject: [PATCH 7/7] Woop! --- features/json.feature | 1 + lib/dashboard.rb | 11 +++++++---- lib/views/dashboard.erb | 24 ++++++++++++++++++++++++ lib/views/dataset.erb | 3 +-- lib/views/default.erb | 28 +--------------------------- lib/views/includes/header.erb | 27 +++++++++++++++++++++++++++ lib/views/simple.erb | 11 +++++++++++ 7 files changed, 72 insertions(+), 33 deletions(-) create mode 100644 lib/views/dashboard.erb create mode 100644 lib/views/includes/header.erb create mode 100644 lib/views/simple.erb diff --git a/features/json.feature b/features/json.feature index f091c66..2c27956 100644 --- a/features/json.feature +++ b/features/json.feature @@ -8,6 +8,7 @@ Feature: Get JSON When I send a GET request to "snake" Then the response status should be "200" And the JSON response should have "$[0]name" with the text "feeds" + And the JSON response should have "$[1]type" with the text "graph" Scenario: Get JSON for a dataset When I send a GET request to "catface/flea-treatment" diff --git a/lib/dashboard.rb b/lib/dashboard.rb index 4d21b22..1e72212 100644 --- a/lib/dashboard.rb +++ b/lib/dashboard.rb @@ -38,8 +38,9 @@ class App < Sinatra::Base headers 'Vary' => 'Accept' wants.html do - @title = 'Catface' - erb :grid, layout: :default + @title = Cleaner.lookups[params[:repo]]['title'] + erb :dashboard, layout: :default + # erb :grid, layout: :default end wants.json do @@ -49,7 +50,8 @@ class App < Sinatra::Base }.map { |dataset| { name: dataset['id'], - url: "#{request.scheme}://#{request.env['HTTP_HOST']}/#{params[:repo]}/#{dataset['id']}.json" + url: "#{request.scheme}://#{request.env['HTTP_HOST']}/#{params[:repo]}/#{dataset['id']}", + type: dataset['type'] } }.to_json end @@ -59,6 +61,7 @@ class App < Sinatra::Base get '/:repo/:dataset' do respond_to do |wants| headers 'Vary' => 'Accept' + @layout = params.fetch('layout', 'default') wants.json do url = "https://api.github.com/repos/#{Cleaner.lookups[params[:repo]]['repo']}/contents/#{params[:dataset]}.csv?ref=master" @@ -72,7 +75,7 @@ class App < Sinatra::Base end wants.html do - erb :dataset, layout: :default + erb :dataset, layout: @layout.to_sym end end end diff --git a/lib/views/dashboard.erb b/lib/views/dashboard.erb new file mode 100644 index 0000000..a036f63 --- /dev/null +++ b/lib/views/dashboard.erb @@ -0,0 +1,24 @@ +

<%= @title %> dashboard

+
+ +
+
+ + diff --git a/lib/views/dataset.erb b/lib/views/dataset.erb index 4bfcd05..426b475 100644 --- a/lib/views/dataset.erb +++ b/lib/views/dataset.erb @@ -1,5 +1,4 @@ -
-
+
- - - - - - - - - - - - - - <%= @title %> + <%= erb :'includes/header' %> diff --git a/lib/views/includes/header.erb b/lib/views/includes/header.erb new file mode 100644 index 0000000..da128cd --- /dev/null +++ b/lib/views/includes/header.erb @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + +<%= @title %> diff --git a/lib/views/simple.erb b/lib/views/simple.erb new file mode 100644 index 0000000..368e704 --- /dev/null +++ b/lib/views/simple.erb @@ -0,0 +1,11 @@ + + + + <%= erb :'includes/header' %> + + + + + <%= yield %> + +