Module: TwitterAuth::OauthUser::ClassMethods

Defined in:
app/models/twitter_auth/oauth_user.rb

Instance Method Summary collapse

Instance Method Details

#create_from_twitter_hash_and_token(user_info, access_token) ⇒ Object



33
34
35
36
37
38
39
# File 'app/models/twitter_auth/oauth_user.rb', line 33

def create_from_twitter_hash_and_token(, access_token)
  user = User.new_from_twitter_hash()
  user.access_token = access_token.token
  user.access_secret = access_token.secret
  user.save
  user
end

#identify_or_create_from_access_token(token, secret = nil) ⇒ Object

Raises:

  • (ArgumentError)


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/models/twitter_auth/oauth_user.rb', line 13

def identify_or_create_from_access_token(token, secret=nil)
  raise ArgumentError, 'Must authenticate with an OAuth::AccessToken or the string access token and secret.' unless (token && secret) || token.is_a?(OAuth::AccessToken)
  
  token = OAuth::AccessToken.new(TwitterAuth.consumer, token, secret) unless token.is_a?(OAuth::AccessToken)
  
  response = token.get(TwitterAuth.path_prefix + '/account/verify_credentials.json')
   = handle_response(response)
  
  if user = User.find_by_twitter_id(['id'].to_s)
    user. = ['screen_name']
    user.assign_twitter_attributes()
    user.access_token = token.token
    user.access_secret = token.secret
    user.save
    user
  else
    User.create_from_twitter_hash_and_token(, token) 
  end
end