Skip to content

Instantly share code, notes, and snippets.

@azkaoru
Last active May 22, 2017 20:24
Show Gist options
  • Save azkaoru/23e04d2ccd6e344e6cdce525d4b3c8ac to your computer and use it in GitHub Desktop.
Save azkaoru/23e04d2ccd6e344e6cdce525d4b3c8ac to your computer and use it in GitHub Desktop.
source 'https://rubygems.org'
gem 'sinatra'
gem 'octokit'
GEM
remote: https://rubygems.org/
specs:
addressable (2.5.1)
public_suffix (~> 2.0, >= 2.0.2)
faraday (0.12.1)
multipart-post (>= 1.2, < 3)
multipart-post (2.0.0)
octokit (4.7.0)
sawyer (~> 0.8.0, >= 0.5.3)
public_suffix (2.0.5)
rack (1.6.8)
rack-protection (1.5.3)
rack
sawyer (0.8.1)
addressable (>= 2.3.5, < 2.6)
faraday (~> 0.8, < 1.0)
sinatra (1.4.8)
rack (~> 1.5)
rack-protection (~> 1.4)
tilt (>= 1.3, < 3)
tilt (2.0.7)
PLATFORMS
x64-mingw32
DEPENDENCIES
octokit
sinatra
BUNDLED WITH
1.15.0
require 'sinatra'
require 'octokit'
set :bind, '0.0.0.0'
set :views, "."
helpers do
def h(text)
Rack::Utils.escape_html(text)
end
end
get '/:username' do |username|
gists = Octokit.gists username, :per_page => 5
tuples = []
gists.each do |g|
g[:files].fields.each do |f|
data = g[:files][f].rels[:raw].get.data
tuples << [ f, data ]
end
end
erb :index, locals: { :tuples => tuples, username: username }
end
get '/' do
"Try adding a GitHub username to the URL..."
end
get "/favicon.ico" do
end
<html>
<body>
<h2>User <%= username %>'s last five gists</h2>
<% tuples.each do |t| %>
<div>
<span><b><%= t[0] %></b>:</span>
<span><%= h t[1] %></span>
</div>
<% end %>
</body>
</html>
<body>
usr has <%= count %> public gists
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment