Skip to content

Commit

Permalink
SUPER POEMS
Browse files Browse the repository at this point in the history
  • Loading branch information
ys committed Jan 31, 2014
0 parents commit d488b32
Show file tree
Hide file tree
Showing 8 changed files with 177 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.bundle
.env
16 changes: 16 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
source 'https://rubygems.org'
gem 'sinatra'
gem 'sequel'
gem 'pg'
gem 'puma'
gem 'json'
gem 'jsonpath'
gem 'faraday'
gem "dalli"
gem "rack-cache"

group :development,:test do
gem 'foreman'
gem 'dotenv'
gem 'shotgun' #auto reload sinatra app
end
49 changes: 49 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
GEM
remote: https://rubygems.org/
specs:
dalli (2.7.0)
dotenv (0.9.0)
faraday (0.9.0)
multipart-post (>= 1.2, < 3)
foreman (0.63.0)
dotenv (>= 0.7)
thor (>= 0.13.6)
json (1.8.1)
jsonpath (0.5.6)
multi_json
multi_json (1.8.4)
multipart-post (2.0.0)
pg (0.17.1)
puma (1.5.0)
rack (~> 1.2)
rack (1.4.1)
rack-cache (1.2)
rack (>= 0.4)
rack-protection (1.5.2)
rack
sequel (4.6.0)
shotgun (0.9)
rack (>= 1.0)
sinatra (1.4.4)
rack (~> 1.4)
rack-protection (~> 1.4)
tilt (~> 1.3, >= 1.3.4)
thor (0.18.1)
tilt (1.4.1)

PLATFORMS
ruby

DEPENDENCIES
dalli
dotenv
faraday
foreman
json
jsonpath
pg
puma
rack-cache
sequel
shotgun
sinatra
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: bundle exec puma -p $PORT -e $RACK_ENV -t 10:10
8 changes: 8 additions & 0 deletions config.ru
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
require './server'
if memcache_servers = ENV["MEMCACHE_SERVERS"]
use Rack::Cache,
verbose: true,
metastore: "memcached://#{memcache_servers}",
entitystore: "memcached://#{memcache_servers}"
end
run App
Binary file added public/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
40 changes: 40 additions & 0 deletions server.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
require 'rubygems'
require 'bundler/setup'
require 'sinatra'
require 'faraday'
require 'json'
require 'jsonpath'
require 'dotenv'
require 'pg'
require 'sequel'
require "dalli"
require "rack-cache"
class App < Sinatra::Base
Dotenv.load

DB = Sequel.connect(ENV['DATABASE_URL'] || 'postgres://localhost:15432/haikuburgers')
DB.create_table? :haikus do
primary_key :id
String :text
end

get '/' do
cache_control :public, max_age: 3600 * 24 * 365 # 30 mins.
haikus = DB[:haikus].map(:text)
haikus.to_json
erb :index, locals: { haikus: haikus }
end

post '/refresh' do
content_type :json
conn = Faraday.new(:url => 'http://api.meetup.com')
profiles = JSON.parse(conn.get('/2/profiles' , group_id: 5356052, key: ENV['MEETUP_API_KEY'], fields: 'join_info').body)
path = JsonPath.new('$..answers')
path.on(profiles)
DB[:haikus].delete
answers = path.on(profiles).flatten.select{ |answer| answer["question_id"] == 2859752 }.each do |answer|
DB[:haikus].insert({text: answer['answer']})
end
{ answers: answers }.to_json
end
end
61 changes: 61 additions & 0 deletions views/index.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<html>
<head>
<title>Rubyburgers poems</title>
<link rel="icon" type="image/png" href="http://rubyburgers.co/favicon.png">
<link href='http://fonts.googleapis.com/css?family=Lato' rel='stylesheet' type='text/css'>
<style>
img {
margin: 20px 0;
width: 600px;
}
p, h1 {
font-family: 'Lato', sans-serif;
}
h1 {
text-align: center;
}
blockquote {
border-left: 3px solid #de412c;
padding: 0 0 0 16px;
margin: 0 0 30px;
}
blockquote p {
font-size: 20px;
line-height: 1.55;
font-weight: normal;
margin-bottom: .4em;
}
blockquote small {
font-size: 18px;
line-height: 1.72222;
font-style: italic;
color: inherit;
}
blockquote small:before {
content: "";
}
blockquote.pull-right {
padding-right: 16px;
padding-left: 0;
border-right: 3px solid #e7e9ec;
border-left: 0;
}
blockquote.pull-right small:after {
content: "";
}
.container {
width: 600px;
margin: 0 auto;
}
</style>
</head>
<body>
<div class='container'>
<img src='http://rubyburgers.co/images/logo.png'/>
<h1>Rubyburgers poetry</h1>
<% haikus.each do |haiku| %>
<blockquote><p><%= haiku %></p></blockquote>
<% end %>
</div>
</body>
</html>

0 comments on commit d488b32

Please sign in to comment.