Created
August 1, 2014 03:45
-
-
Save orafaelfragoso/786bd743c70ec03d3c97 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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