From 31b55aef0bfaac24dbf2daba7ab7fe8e3f22769d Mon Sep 17 00:00:00 2001 From: Raphael Sofaer Date: Fri, 12 Aug 2011 11:51:06 -0700 Subject: [PATCH] Start saving the usernames of facebook users --- app/models/services/facebook.rb | 4 ++-- .../20110812175614_add_username_to_service_users.rb | 9 +++++++++ db/schema.rb | 11 ++++++----- 3 files changed, 17 insertions(+), 7 deletions(-) create mode 100644 db/migrate/20110812175614_add_username_to_service_users.rb diff --git a/app/models/services/facebook.rb b/app/models/services/facebook.rb index 645d0dc3e..b77e68809 100644 --- a/app/models/services/facebook.rb +++ b/app/models/services/facebook.rb @@ -38,11 +38,11 @@ class Services::Facebook < Service data = JSON.parse(response.body)['data'] return unless data data.map!{ |p| - su = ServiceUser.new(:service_id => self.id, :uid => p["id"], :photo_url => p["picture"], :name => p["name"]) + su = ServiceUser.new(:service_id => self.id, :uid => p["id"], :photo_url => p["picture"], :name => p["name"], :username => p["username"]) su.attach_local_models su } - ServiceUser.import(data, :on_duplicate_key_update => [:updated_at, :contact_id, :person_id, :request_id, :invitation_id, :photo_url, :name]) + ServiceUser.import(data, :on_duplicate_key_update => [:updated_at, :contact_id, :person_id, :request_id, :invitation_id, :photo_url, :name, :username]) end private diff --git a/db/migrate/20110812175614_add_username_to_service_users.rb b/db/migrate/20110812175614_add_username_to_service_users.rb new file mode 100644 index 000000000..c2a9fc715 --- /dev/null +++ b/db/migrate/20110812175614_add_username_to_service_users.rb @@ -0,0 +1,9 @@ +class AddUsernameToServiceUsers < ActiveRecord::Migration + def self.up + add_column :service_users, :username, :string, :limit => 127 + end + + def self.down + remove_column :service_users, :username + end +end diff --git a/db/schema.rb b/db/schema.rb index b44897fee..a4ab4ab6e 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20110730173443) do +ActiveRecord::Schema.define(:version => 20110812175614) do create_table "aspect_memberships", :force => true do |t| t.integer "aspect_id", :null => false @@ -319,16 +319,17 @@ ActiveRecord::Schema.define(:version => 20110730173443) do add_index "profiles", ["person_id"], :name => "index_profiles_on_person_id" create_table "service_users", :force => true do |t| - t.string "uid", :null => false - t.string "name", :null => false - t.string "photo_url", :null => false - t.integer "service_id", :null => false + t.string "uid", :null => false + t.string "name", :null => false + t.string "photo_url", :null => false + t.integer "service_id", :null => false t.integer "person_id" t.integer "contact_id" t.integer "request_id" t.integer "invitation_id" t.datetime "created_at" t.datetime "updated_at" + t.string "username", :limit => 127 end add_index "service_users", ["service_id"], :name => "index_service_users_on_service_id"