Created
January 31, 2012 04:53
-
-
Save taiansu/1708909 to your computer and use it in GitHub Desktop.
GetUserCollabraotrsRedesign
This file contains 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 "httparty" | |
class GitRepos | |
include HTTParty | |
base_uri "https://api.github.com" | |
headers 'Accept' => 'application/json' | |
format :json | |
def get_repos_by_user(user) | |
repos = self.class.get("/users/#{user}/repos") | |
end | |
#might call this by asynchronous or currency way. | |
def get_collaborators_by_repo(user, repo_name) | |
collaborators = self.class.get("/repos/#{user}/#{repo_name}/collaborators") | |
end | |
def list_collaborators_by_user(user, &block) | |
repo_hash = { } | |
#get all the repos via http | |
repos = get_repos_by_user(user) | |
#launch http get for each repo | |
repos.each do |repo| | |
puts "#{repo["name"]} => \n" | |
collaborators = get_collaborators_by_repo(user, repo["name"]) | |
#store collaborators into hash for return | |
repo_hash[repo["name"]] = collaborators | |
#display each result | |
if block_given? | |
block.call(collaborators) | |
end | |
end | |
return repo_hash | |
end | |
end | |
#Run! | |
if __FILE__ == $0 | |
git_repos = GitRepos.new | |
git_repos.list_collaborators_by_user("datamapper"){ |collaborators| | |
collaborators.each{ |collaborator| puts " #{collaborator["login"]}," } | |
puts #link break | |
} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment