Module: Sinatra::Hellhound::TwitterHelpers

Defined in:
lib/hellhound.rb

Instance Method Summary collapse

Instance Method Details

#create_or_retrieve_twitter_user(&block) ⇒ Object

Retrieve the user from the database or create a new one if it doesn’t exists.

If you want to store the user in memcached them you need to return the user at the end of the block

I.e

create_or_retrive_user do |user_data|      #    
  user = User.find :twitter_id => user_data["id"].to_s
  User.create :twitter_id => user_data["id"].to_s unless user
  user
end


78
79
80
81
82
83
84
# File 'lib/hellhound.rb', line 78

def create_or_retrieve_twitter_user(&block)
  user_data = get_credentials        
  session[:user] = user_data["id"].to_s
  user = yield user_data
  
  CACHE.set "user-#{session[:user]}", user if options.hellhound_cache
end

#get_credentialsObject

Returns a Hash with the user data.



89
90
91
# File 'lib/hellhound.rb', line 89

def get_credentials
  user_data = JSON.parse(get_access_token.get('/account/verify_credentials.json').body)
end