class Tact::GoogleContacts::Syncer
Attributes
entry[R]
new_emails[R]
new_numbers[R]
Public Class Methods
new(entry)
click to toggle source
# File lib/tact/google_client.rb, line 79 def initialize(entry) @entry = entry @new_numbers = [] @new_emails = [] end
Public Instance Methods
add_new_emails(contact)
click to toggle source
# File lib/tact/google_client.rb, line 112 def add_new_emails(contact) contact.emails << new_emails end
add_new_phone_numbers(contact)
click to toggle source
# File lib/tact/google_client.rb, line 108 def add_new_phone_numbers(contact) contact.phone_numbers << new_numbers end
find_contact()
click to toggle source
# File lib/tact/google_client.rb, line 94 def find_contact Contact.find_by( first_name: entry.first_name.upcase, last_name: (entry.last_name || "").upcase ) end
get_new_emails(contact)
click to toggle source
# File lib/tact/google_client.rb, line 124 def get_new_emails(contact) entry.emails.each do |email| if !contact.emails.any? { |e| e.address == email.address } new_emails << email end end if entry.emails end
get_new_phone_numbers(contact)
click to toggle source
# File lib/tact/google_client.rb, line 116 def get_new_phone_numbers(contact) entry.phone_numbers.each do |number| if !contact.phone_numbers.any? { |n| n.number == number.number } new_numbers << number end end if entry.phone_numbers end
merge_properties(contact)
click to toggle source
# File lib/tact/google_client.rb, line 101 def merge_properties(contact) get_new_phone_numbers(contact) get_new_emails(contact) add_new_phone_numbers(contact) add_new_emails(contact) end
sync()
click to toggle source
# File lib/tact/google_client.rb, line 85 def sync contact = find_contact || Contact.new( first_name: entry.first_name.upcase, last_name: (entry.last_name || "").upcase ) merge_properties(contact) contact.save end