Skip to content

Instantly share code, notes, and snippets.

@vjwilson
Last active June 11, 2016 22:15
Show Gist options
  • Save vjwilson/b9a6d0759cebe9e148c59bad388414bb to your computer and use it in GitHub Desktop.
Save vjwilson/b9a6d0759cebe9e148c59bad388414bb to your computer and use it in GitHub Desktop.
Sinatra app for working with Github Gist API
source 'https://rubygems.org'
gem 'sinatra'
gem 'octokit'
GEM
remote: https://rubygems.org/
specs:
addressable (2.4.0)
faraday (0.9.2)
multipart-post (>= 1.2, < 3)
multipart-post (2.0.0)
octokit (4.3.0)
sawyer (~> 0.7.0, >= 0.5.3)
rack (1.6.4)
rack-protection (1.5.3)
rack
sawyer (0.7.0)
addressable (>= 2.3.5, < 2.5)
faraday (~> 0.8, < 0.10)
sinatra (1.4.7)
rack (~> 1.5)
rack-protection (~> 1.4)
tilt (>= 1.3, < 3)
tilt (2.0.5)
PLATFORMS
ruby
DEPENDENCIES
octokit
sinatra
BUNDLED WITH
1.11.2
require 'sinatra'
require 'octokit'
set :views, '.'
get '/hi' do
'Hello world!'
end
get '/:username' do |username|
user = Octokit.user username
count = user.public_gists
gists = Octokit.gists username, :per_page => 5
erb :index, locals: { :count => count, :gists => gists, username: username }
end
<html>
<body>
<h1><%= username %>
<p>User has <%= count %> public gists</p>
<h2>User <%= username %>'s last five gists</h2>
<% gists.each do |g| %>
<% g[:files].fields.each do |f| %>
<h3><%= f %></h3>
<pre>
<%= g[:files][f.to_sym].rels[:raw].get.data %>
</pre>
<% end %>
<% end %>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment