Permalink
Browse files

rake github:data:update

  • Loading branch information...
szemek committed Nov 9, 2012
1 parent 2af8d85 commit 82b27e66ca6154e891b58a5ec5a9452279e4dbb0
Showing with 22 additions and 1 deletion.
  1. +5 −1 extras/github_data.rb
  2. +17 −0 lib/tasks/github.rake
View
@@ -27,7 +27,7 @@ def fetch!
end
end
- def as_json(options = {})
+ def to_hash(options = {})
hash = {}
hash['gravatar'] = @gravatar
@@ -38,6 +38,10 @@ def as_json(options = {})
hash
end
+ def as_json(options = {})
+ self.to_hash
+ end
+
private
def repository_url
"https://api.github.com/repos/#{@username}/#{@repository}"
View
@@ -0,0 +1,17 @@
+namespace :github do
+ namespace :data do
+ desc "Update projects with Github data"
+ task :update => :environment do
+ Project.all.each do |project|
+ data = GithubData.new(project.username, project.repo)
+ data.fetch!
+ attributes = data.to_hash.reject{|k,v| v.nil?}
+
+ if attributes.present?
+ project.update_attributes(attributes)
+ puts "Project: #{project.id} has been updated."
+ end
+ end
+ end
+ end
+end

0 comments on commit 82b27e6

Please sign in to comment.