Skip to content

Instantly share code, notes, and snippets.

@barek2k2
Created June 5, 2013 14:20
Show Gist options
  • Save barek2k2/5714213 to your computer and use it in GitHub Desktop.
Save barek2k2/5714213 to your computer and use it in GitHub Desktop.
def self.update_profile(user)
begin
social_media_info = user.social_media_info
if social_media_info.present?
social_media_info = JSON.parse(social_media_info.information)
raw_info = social_media_info['extra']['raw_info']
social_media_info = social_media_info['info']
if raw_info['gender'] == 'male'
sex = 'm'
elsif raw_info['gender'] == 'female'
sex = 'f'
else
sex = raw_info['gender']
end
if user.is?(:member)
user_profile = user.user_profile
user_profile.update_attributes({:name => social_media_info['name'], :image_url => social_media_info['image'],
:facebook_url => raw_info['link'],
:sex => sex, :birth_date => raw_info['birthday'].present? ? Date.strptime(raw_info['birthday'], "%m/%d/%Y") : nil})
elsif user.is?(:doctor)
doctor_profile = user.doctor_profile
doctor_profile.update_attributes({:name => social_media_info['name'], :image_url => social_media_info['image'],
:facebook_url => raw_info['link'],
})
end
end
rescue
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment