Skip to content

Instantly share code, notes, and snippets.

@jlogsdon
Forked from andrewwho/userimages.rake
Created June 21, 2012 18:10
Show Gist options
  • Save jlogsdon/2967486 to your computer and use it in GitHub Desktop.
Save jlogsdon/2967486 to your computer and use it in GitHub Desktop.
hurray
class User < ActiveRecord::Base
def fetch_facebook_image
return false if authentications.blank?
auth = authentications.find_by_provider('facebook')
self.remote_image_url = "https://graph.facebook.com/"+auth.uid+"/picture?type=large"
self.save
end
end
namespace :images do
desc "populating user.image"
task :pull => :environment do
print "This task will pull FB images into user.image if user has fb authentications. Confirm? [y/n]: "
answer = $stdin.gets.chomp()
if answer == 'y'
# User.all.each do |u|
u = User.find(50)
begin
if u.fetch_facebook_image
puts "#{u.username}'s image has been fetched!"
else
puts "#{u.username} is not authenticated."
end
rescue => e
puts "There was an error updating #{u.username}: #{e.message}"
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment