Skip to content

Instantly share code, notes, and snippets.

@bryanl
Created September 27, 2011 15:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bryanl/1245433 to your computer and use it in GitHub Desktop.
Save bryanl/1245433 to your computer and use it in GitHub Desktop.
class TwitterReverseAuthController < ApplicationController
def api_key_exchange
credential_args = [:screen_name, :token, :secret].map{|x| params[x]}
user_credentials = UserCredentials.new(*credential_args)
if user_credentials.valid?
user = user_credentials.user
token = params[:token]
device = Device.find_or_create_by_token!(:token => user_credentials.token,
:description => params[:description],
:user_id => @user.id)
render :json => { :api_key => device.api_key }
else
render :json => { :error => user_credentials.first_error}, :status => :unprocessable_entity }
end
end
end
class UserCredentials
def initialize(screen_name, token, secret)
# ...
end
def valid?
# ...
end
def first_error
# ...
end
end
@akahn
Copy link

akahn commented Sep 27, 2011

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment