Skip to content

Instantly share code, notes, and snippets.

@alea12
Created June 27, 2017 07:59
Show Gist options
  • Save alea12/90cc92ce3ea4e98f037678a625e8da4f to your computer and use it in GitHub Desktop.
Save alea12/90cc92ce3ea4e98f037678a625e8da4f to your computer and use it in GitHub Desktop.
class SocialProfile < ApplicationRecord
belongs_to :user
store :other
validates_uniqueness_of :uid, scope: :provider
def set_values(omniauth)
return if provider.to_s != omniauth['provider'].to_s || uid != omniauth['uid']
credentials = omniauth['credentials']
info = omniauth['info']
self.access_token = credentials['token']
self.access_secret = credentials['secret']
self.credentials = credentials.to_json
self.email = info['email']
self.name = info['name']
self.nickname = info['nickname']
self.description = info['description']
self.image_url = info['image']
if provider.to_s == 'google'
self.nickname ||= info['email'].sub(/(.+)@gmail.com/, '\1')
end
self.set_values_by_raw_info(omniauth['extra']['raw_info'])
end
def set_values_by_raw_info(raw_info)
if provider.to_s == 'google'
self.url = raw_info['link']
end
self.raw_info = raw_info.to_json
self.save!
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment