Skip to content

Instantly share code, notes, and snippets.

@engelfrost
Created May 11, 2011 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save engelfrost/966509 to your computer and use it in GitHub Desktop.
Save engelfrost/966509 to your computer and use it in GitHub Desktop.
Job for fetching Facebook checkins though Fb_Graph
class FacebookJob
def initialize
# DebugMailer.email('initialize').deliver
end
def perform
# DebugMailer.email('facebook').deliver
begin
# DebugMailer.email('beginning').deliver
fb_auths = Authentication.where(:provider => 'facebook')
fb_auths.each do |auth|
# raise auth.token.to_s
checkins = FbGraph::User.new('me', :access_token => URI.encode(auth.token)).checkins
# checkins = fb_user.checkins
if checkins != nil
# DebugMailer.email('harvesting checkins').deliver
checkins.each do |checkin|
fb_venue = FacebookVenue.where(:service_venue_id => checkin.place.identifier).first
# fb_venues_found << checkin.place.identifier #debug
if fb_venue != nil #do we monitor this location?
# Only insert new checkins:
unless FacebookCheckin.where(:service_checkin_id => checkin.identifier).first
# DebugMailer.email('A new one!').deliver
message = !checkin.message ? "" : checkin.message
sl_checkin = Checkin.new(:user => auth.user, :venue => fb_venue.venue, :datetime => checkin.created_time)
sl_checkin.save!
fb_checkin = FacebookCheckin.new(:checkin => sl_checkin, :service_checkin_id => checkin.identifier, :message => message)
fb_checkin.save!
end
end
end
end
end
rescue
DebugMailer.email('something went wrong in facebook_job').deliver
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment