Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Caching (I think) #2

Merged
merged 3 commits into from
Dec 31, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
language: ruby
cache: bundler
rvm:
- 2.3.0
- 2.3.0
services:
- redis-server
deploy:
provider: heroku
app: sam-and-kitty-dashboard
Expand Down
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ gem 'httparty'
gem 'dotenv'
gem 'rack-conneg'
gem 'actionpack', '~> 4'
gem 'redis'

group :test do
gem 'cucumber'
Expand Down
2 changes: 2 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ GEM
rb-fsevent (0.9.6)
rb-inotify (0.9.5)
ffi (>= 0.5.0)
redis (3.2.2)
rest-client (1.8.0)
http-cookie (>= 1.0.2, < 2.0)
mime-types (>= 1.16, < 3.0)
Expand Down Expand Up @@ -221,6 +222,7 @@ DEPENDENCIES
puma
rack-conneg
rake
redis
rspec
sass
sinatra
Expand Down
19 changes: 19 additions & 0 deletions app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "sam-and-kitty-dashboard",
"scripts": {
},
"env": {
"GITHUB_CLIENT_ID": {
"required": true
},
"GITHUB_CLIENT_SECRET": {
"required": true
},
"REDIS_URL": {
"required": true
}
},
"addons": [
"heroku-redis"
]
}
1 change: 1 addition & 0 deletions lib/dashboard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
require 'csv'
require 'dotenv'
require 'json'
require 'redis'
require 'active_support/inflector'

require_relative 'dashboard/fetcher'
Expand Down
15 changes: 12 additions & 3 deletions lib/dashboard/fetcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,15 @@ def self.query
end

def self.get url
HTTParty.get url, headers: headers, query: query
redis = Redis.new
if redis.get url
return Marshal.load(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 All @@ -28,11 +36,12 @@ def self.fetch_CSV url
end

def self.fetch_metadata url
JSON.parse get(url).body
JSON.parse(get(url))
end

def self.assemble_data url
m = fetch_metadata url

m['data'] = fetch_CSV m['download_url']
m['repo'] = extract_repo m['url']

Expand All @@ -41,7 +50,7 @@ def self.assemble_data url

def self.list_CSVs repo
url = ['https://api.github.com/repos', repo, 'contents'].join '/'
get(url).select { |i| i['name'].match /\.csv$/ }.map { |c| c['url'] }
JSON.parse(get(url)).select { |i| i['name'].match /\.csv$/ }.map { |c| c['url'] }
end

def self.fetch_CSVs repo
Expand Down