Use activerecord-import to re-save ServiceUser objects. We should do the same in ReceiveLocalBatch.
This commit is contained in:
parent
f4bdf17c4a
commit
55009a8381
3 changed files with 8 additions and 3 deletions
1
Gemfile
1
Gemfile
|
|
@ -5,6 +5,7 @@ gem 'mysql2', '0.2.6'
|
|||
#gem 'sqlite3'
|
||||
gem 'rails', '3.0.3'
|
||||
gem 'foreigner', '0.9.1'
|
||||
gem 'activerecord-import'
|
||||
|
||||
gem 'bundler', '>= 1.0.0'
|
||||
gem 'chef', '0.9.12', :require => false
|
||||
|
|
|
|||
|
|
@ -94,6 +94,8 @@ GEM
|
|||
activesupport (= 3.0.3)
|
||||
arel (~> 2.0.2)
|
||||
tzinfo (~> 0.3.23)
|
||||
activerecord-import (0.2.7)
|
||||
activerecord (~> 3.0.0)
|
||||
activeresource (3.0.3)
|
||||
activemodel (= 3.0.3)
|
||||
activesupport (= 3.0.3)
|
||||
|
|
@ -447,6 +449,7 @@ PLATFORMS
|
|||
|
||||
DEPENDENCIES
|
||||
SystemTimer (= 1.2.1)
|
||||
activerecord-import
|
||||
acts-as-taggable-on!
|
||||
addressable (= 2.2.4)
|
||||
aws (= 2.3.32)
|
||||
|
|
|
|||
|
|
@ -42,9 +42,10 @@ class Services::Facebook < Service
|
|||
url = "https://graph.facebook.com/me/friends?fields[]=name&fields[]=picture&access_token=#{URI.escape(self.access_token)}"
|
||||
response = Faraday.get(url)
|
||||
data = JSON.parse(response.body)['data']
|
||||
data.each{ |p|
|
||||
su = ServiceUser.find_or_initialize_by_service_id_and_uid(:service_id => self.id, :uid => p["id"])
|
||||
su.update_attributes({:name => p["name"], :photo_url => p["picture"]})
|
||||
ServiceUser.where(:service_id => self.id).delete_all
|
||||
s_users = data.map{ |p|
|
||||
ServiceUser.new(:service_id => self.id, :uid => p["id"], :photo_url => p["picture"], :name => p["name"])
|
||||
}
|
||||
ServiceUser.import(s_users)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue