Skip to content

Instantly share code, notes, and snippets.

@orafaelfragoso
Created August 1, 2014 03:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save orafaelfragoso/786bd743c70ec03d3c97 to your computer and use it in GitHub Desktop.
Save orafaelfragoso/786bd743c70ec03d3c97 to your computer and use it in GitHub Desktop.
class Member < ActiveRecord::Base
has_many :identities
def self.create_with_omniauth(info)
# create(first_name: info[:first_name], last_name: info[:last_name], email: info[:email], gender: info[:gender], birthday: info[:birthday], nickname: info[:nickname], profile_picture: info[:profile_picture], location: info[:location])
member = find_or_initialize_by_email(info[:email]) do |i|
i.first_name = info[:first_name]
i.last_name = info[:last_name]
i.email = info[:email]
i.gender = info[:gender]
i.birthday = info[:birthday]
i.nickname = info[:nickname]
i.profile_picture = info[:profile_picture]
i.location = info[:location]
end
member.save!
member # return member after save it
end
def self.filter_auth_hash(auth)
# Facebook Filter
if auth.provider == "facebook"
{
:first_name => auth.info.first_name,
:last_name => auth.info.last_name,
:email => auth.info.email,
:nickname => auth.info.nickname,
:gender => auth.extra.raw_info.gender,
:birthday => parse_facebook_birthday(auth.extra.raw_info.birthday),
:profile_picture => auth.info.image,
:location => auth.info.location
}
end
if auth.provider == "linkedin"
{
:first_name => auth.extra.raw_info.firstName,
:last_name => auth.extra.raw_info.lastName,
:email => auth.extra.raw_info.emailAddress,
:nickname => auth.extra.raw_info.publicProfileUrl.split("/").last,
:gender => nil,
:birthday => nil,
:profile_picture => auth.extra.raw_info.pictureUrl,
:location => auth.extra.raw_info.location.name
}
end
end
def self.parse_facebook_birthday(birthday)
require 'date'
b = Date.strptime(birthday, '%m/%d/%Y')
b.year.to_s + '-' + b.month.to_s + '-' + b.day.to_s
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment