Skip to content

Commit

Permalink
Use activerecord-import to re-save ServiceUser objects. We should do …
Browse files Browse the repository at this point in the history
…the same in ReceiveLocalBatch.
  • Loading branch information
Raphael Sofaer committed Jul 13, 2011
1 parent f4bdf17 commit 55009a8
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions Gemfile
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions Gemfile.lock
Expand Up @@ -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)
Expand Down Expand Up @@ -447,6 +449,7 @@ PLATFORMS

DEPENDENCIES
SystemTimer (= 1.2.1)
activerecord-import
acts-as-taggable-on!
addressable (= 2.2.4)
aws (= 2.3.32)
Expand Down
7 changes: 4 additions & 3 deletions app/models/services/facebook.rb
Expand Up @@ -42,9 +42,10 @@ def save_friends
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

0 comments on commit 55009a8

Please sign in to comment.