Skip to content

Instantly share code, notes, and snippets.

@scpike
Created January 31, 2012 16:02
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 scpike/1711315 to your computer and use it in GitHub Desktop.
Save scpike/1711315 to your computer and use it in GitHub Desktop.
Create checkin from foursquare push
def foursquare_push
# params[:checkin] is a foursquare-provided JSON object
checkin_hash = ActiveSupport::JSON.decode(params[:checkin])
# Look up the user based on foursquare ID
user = User.find_by_foursquare_id(checkin_hash["user"]["id"])
if user
# Create a new checkin, set its parameters from the hash
# foursquare sent us. Check for dups
c = Checkin.find_by_checkin_id(checkin_hash["id"])
c = Checkin.new( :user => user, :action => user.action ) unless c
c.set_checkin_data checkin_hash
c.save
c.process_checkin
end
# Tell foursquare thanks!
# Foursquare is pushing us data for a user we don't know about
render :text => "success"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment