Skip to content

Commit

Permalink
Merge pull request #2 from pikesley/redis
Browse files Browse the repository at this point in the history
Caching (I think)
  • Loading branch information
Sam Pikesley committed Dec 31, 2015
2 parents 0460f6d + 9a07d83 commit 7498279
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 4 deletions.
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

0 comments on commit 7498279

Please sign in to comment.