actually displaying the facebook results(first time connection), updating attributes instead of discarding the changes

This commit is contained in:
Ilyaaaaaaaaaaaaa Zhitomirskiy 2011-07-11 16:52:14 -07:00
parent 58e844eb1f
commit f6bf17897d

View file

@ -23,6 +23,7 @@ class Services::Facebook < Service
Rails.logger.debug("event=friend_finder type=facebook sender_id=#{self.user_id}") Rails.logger.debug("event=friend_finder type=facebook sender_id=#{self.user_id}")
if self.service_users.blank? if self.service_users.blank?
self.save_friends self.save_friends
self.service_users.reload
else else
Resque.enqueue(Job::UpdateServiceUsers, self.id) Resque.enqueue(Job::UpdateServiceUsers, self.id)
end end
@ -42,8 +43,8 @@ class Services::Facebook < Service
response = Faraday.get(url) response = Faraday.get(url)
data = JSON.parse(response.body)['data'] data = JSON.parse(response.body)['data']
data.each{ |p| data.each{ |p|
ServiceUser.find_or_create_by_service_id_and_uid(:service_id => self.id, :name => p["name"], su = ServiceUser.find_or_initialize_by_service_id_and_uid(:service_id => self.id, :uid => p["id"])
:uid => p["id"], :photo_url => p["picture"]) su.update_attributes({:name => p["name"], :photo_url => p["picture"]})
} }
end end
end end