Created
January 31, 2012 16:02
-
-
Save scpike/1711315 to your computer and use it in GitHub Desktop.
Create checkin from foursquare push
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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