Created
May 31, 2011 12:37
-
-
Save bradylove/1000439 to your computer and use it in GitHub Desktop.
Small model to get list of repos and create links
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
class Github | |
def initialize(username) | |
@username = username | |
end | |
def get_repos | |
base_url = "http://github.com/api/v2/json/repos/show/" | |
url = "#{base_url}#{@username}" | |
resp = Net::HTTP.get_response(URI.parse(url)) | |
data = resp.body | |
result = JSON.parse(data) | |
if result.has_key? 'Error' | |
raise "web server error" | |
end | |
return result | |
end | |
def display | |
repos = "<ul>" | |
data = get_repos["repositories"] | |
data.each do |repo| | |
link = "<li><a href='#{repo["url"].to_s}'>#{repo["name"]}</a></li>" | |
repos << link | |
end | |
repos << "</ul>" | |
return repos | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment