Class: Bitsa::GmailContactsLoader

Inherits:
Object
  • Object
show all
Defined in:
lib/bitsa/gmail_contacts_loader.rb

Overview

Loads Contacts from Gmail into a ContactsCache object.

Instance Method Summary collapse

Constructor Details

#initialize(user, pw, fetch_size = 25) ⇒ GmailContactsLoader

Ctor specifying the Gmail (or Google Apps) user name and password and optionally the number of records to retrieve in each chunk.



30
31
32
33
34
# File 'lib/bitsa/gmail_contacts_loader.rb', line 30

def initialize(user, pw, fetch_size = 25)
  @user = user
  @pw = pw
  @fetch_size = fetch_size
end

Instance Method Details

#update_cache(cache) ⇒ Object

Refresh the passsed ContactsCache with the latest contact changes/deletions from Gmail.



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/bitsa/gmail_contacts_loader.rb', line 38

def update_cache(cache)
  client = GData::Client::Contacts.new
  client.clientlogin(@user, @pw)

  idx = 1
  until load_chunk(client, idx, cache) < @fetch_size
    idx += @fetch_size
  end
  cache.source_last_modified = DateTime.now.to_s
  cache.save
end