Açıklama Yok

authorization.rb 1.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. # == Schema Information
  2. #
  3. # Table name: authorizations
  4. #
  5. # id :integer not null, primary key
  6. # provider :string
  7. # uid :string
  8. # token :string
  9. # user_id :integer
  10. # created_at :datetime
  11. # updated_at :datetime
  12. # secret :string
  13. #
  14. # Indexes
  15. #
  16. # index_authorizations_on_user_id (user_id)
  17. #
  18. class Authorization < ActiveRecord::Base
  19. belongs_to :user
  20. validates_presence_of :user_id, :uid, :provider
  21. validates_uniqueness_of :uid, scope: :provider
  22. scope :facebook, lambda { find_by(provider: 'facebook') }
  23. # after_create :fetch_details
  24. def fetch_details
  25. self.send("fetch_details_from_#{self.provider.downcase}")
  26. end
  27. def fetch_details_from_facebook
  28. graph = Koala::Facebook::API.new(self.token)
  29. profile = graph.get_object("me")
  30. user = self.user
  31. user.update_attributes(first_name: profile['first_name'], last_name: profile['last_name'],
  32. address: profile["location"]["name"])
  33. user.save
  34. end
  35. def fetch_details_from_linkedin
  36. end
  37. def fetch_details_from_google_oauth2
  38. end
  39. def fetch_details_from_github
  40. end
  41. end