Skip to content

Commit

Permalink
add Authorization class for Ruby example
Browse files Browse the repository at this point in the history
  • Loading branch information
elanper committed Dec 27, 2015
1 parent 575874c commit b3c6f79
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions examples/server/ruby/app/models/authorization.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# == Schema Information
#
# Table name: authorizations
#
# id :integer not null, primary key
# provider :string
# uid :string
# token :string
# user_id :integer
# created_at :datetime
# updated_at :datetime
# secret :string
#
# Indexes
#
# index_authorizations_on_user_id (user_id)
#

class Authorization < ActiveRecord::Base
belongs_to :user
validates_presence_of :user_id, :uid, :provider
validates_uniqueness_of :uid, scope: :provider

scope :facebook, lambda { find_by(provider: 'facebook') }
# after_create :fetch_details

def fetch_details
self.send("fetch_details_from_#{self.provider.downcase}")
end

def fetch_details_from_facebook
graph = Koala::Facebook::API.new(self.token)
profile = graph.get_object("me")
user = self.user
user.update_attributes(first_name: profile['first_name'], last_name: profile['last_name'],
address: profile["location"]["name"])

user.save
end

def fetch_details_from_linkedin
end

def fetch_details_from_google_oauth2
end

def fetch_details_from_github
end

end

0 comments on commit b3c6f79

Please sign in to comment.