Permalink
Browse files

Get contributions count from Octocoder

The previous approach isn't available in v3 of the API
  • Loading branch information...
1 parent f9f5c94 commit bbe69a3746da09fe80093f6a90b8b586e3cc3d2c @andyw8 andyw8 committed Jul 2, 2012
Showing with 10 additions and 2 deletions.
  1. +3 −1 app.rb
  2. +7 −1 lib/Repo.rb
View
@@ -150,13 +150,15 @@ def get_high_scores(user, repo)
repository_contributors = JSON.parse(contributors)
contributors_array = Array.new
repository_contributors.each do |repository_contributor|
+
user_hash = Hash.new
user_hash[:login] = repository_contributor['login']
user_hash[:name] = repository_contributor['name']
user_hash[:email] = repository_contributor['email']
user_hash[:gravatar_id] = repository_contributor['gravatar_id']
user_hash[:location] = repository_contributor['location']
- user_hash[:contributions] = repository_contributor['contributions'].to_i
+
+ user_hash[:contributions] = stored_repo.contributions(user_hash[:login])
contributors_array << user_hash
end
return contributors_array
View
@@ -40,7 +40,7 @@ def self.create_from_username_and_repo(username, repo)
repo_data_response = get_json_response(repo_data_url)
repo_data = JSON.parse(repo_data_response.body)
- repo.owner = repo_data['owner']
+ repo.owner = repo_data['owner']['login']
repo.name = repo_data['name']
repo.url = repo_data['url']
repo.homepage = repo_data['homepage']
@@ -67,6 +67,12 @@ def self.get_json_response(url)
def self.get_repo_data_url(username, repo)
return REPO_BASE_URL + username + '/' + repo
end
+
+ def contributions(contributor)
+ uri = "http://octocoder.heroku.com/#{owner}/#{name}/#{contributor}"
+ response = RestClient.get(uri)
+ JSON.parse(response)['count']
+ end
end
DataMapper.auto_upgrade!

0 comments on commit bbe69a3

Please sign in to comment.