Module: TwitterAuth::BasicUser::ClassMethods
- Defined in:
- app/models/twitter_auth/basic_user.rb
Instance Method Summary collapse
- #authenticate(login, password) ⇒ Object
- #identify_or_create_from_twitter_hash_and_password(twitter_hash, password) ⇒ Object
- #verify_credentials(login, password) ⇒ Object
Instance Method Details
#authenticate(login, password) ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'app/models/twitter_auth/basic_user.rb', line 28 def authenticate(login, password) if twitter_hash = verify_credentials(login, password) user = identify_or_create_from_twitter_hash_and_password(twitter_hash, password) user else nil end end |
#identify_or_create_from_twitter_hash_and_password(twitter_hash, password) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'app/models/twitter_auth/basic_user.rb', line 37 def identify_or_create_from_twitter_hash_and_password(twitter_hash, password) if user = User.find_by_twitter_id(twitter_hash['id'].to_s) user.login = twitter_hash['screen_name'] user.assign_twitter_attributes(twitter_hash) user.password = password user.save user else user = User.new_from_twitter_hash(twitter_hash) user.password = password user.save user end end |
#verify_credentials(login, password) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'app/models/twitter_auth/basic_user.rb', line 14 def verify_credentials(login, password) response = TwitterAuth.net.start { |http| request = Net::HTTP::Get.new('/account/verify_credentials.json') request.basic_auth login, password http.request(request) } if response.code == '200' JSON.parse(response.body) else false end end |