Last active
August 29, 2015 14:10
-
-
Save ZucchiniZe/55bdbf4ed218798e60f5 to your computer and use it in GitHub Desktop.
Uses GitHub API to show repos
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'sinatra' | |
| require 'json' | |
| require 'rest_client' | |
| get '/' do | |
| "/username replace username with any github user" | |
| end | |
| get '/:username' do | |
| api_result = RestClient.get "https://api.github.com/users/#{params['username']}/repos", {:accept => "application/vnd.github.v3+json"} | |
| json = JSON.parse(api_result) | |
| erb :index, :locals => {json: json, name: params['username']} | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| source 'http://rubygems.org' | |
| gem 'rubygems-update' | |
| gem 'bundler' | |
| gem 'sinatra' | |
| gem 'rest-open-uri' | |
| gem 'json' | |
| gem 'rest_client' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <html> | |
| <head> | |
| <title>GitHub repos</title> | |
| <style media="screen"> | |
| .fork { | |
| color: blue; | |
| } | |
| .red { | |
| color: red; | |
| } | |
| </style> | |
| </head> | |
| <body> | |
| <table> | |
| <th>Repos for<%= name %></th> | |
| <tr> | |
| <th>Repo Name</th> | |
| <th>Stars</th> | |
| <th>Watchers</th> | |
| <th>Forks</th> | |
| <th>Language</th> | |
| </tr> | |
| <% for repo in json %><tr<% if repo['fork'] == true %> class="fork"<% end %>> | |
| <td> | |
| <a href="<%= repo['html_url'] %>"><%= repo['name'] %></a> | |
| </td> | |
| <td<% if repo['stargazers_count'] != 0 %> class="red"<% end %>><%= repo['stargazers_count'] %></td> | |
| <td<% if repo['watchers_count'] != 0 %> class="red"<% end %>><%= repo['watchers_count'] %></td> | |
| <td<% if repo['forks'] != 0 %> class="red"<% end %>><%= repo['forks'] %></td> | |
| <td><%= repo['language'] %></td> | |
| </tr> | |
| <% end %> | |
| </table> | |
| <hr noshade> | |
| Powered by the<a href = 'https://developer.github.com/v3' target="_new">GitHub API</a> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment