Class: GoogleAppsApi::Contacts::Api

Inherits:
BaseApi
  • Object
show all
Defined in:
lib/google_apps_api/contacts.rb

Instance Attribute Summary collapse

Attributes inherited from BaseApi

#domain

Instance Method Summary collapse

Methods inherited from BaseApi

#entity

Constructor Details

#initialize(*args) ⇒ Api

Returns a new instance of Api.



8
9
10
# File 'lib/google_apps_api/contacts.rb', line 8

def initialize(*args)  
  super(:contacts, *args)
end

Instance Attribute Details

#tokenObject (readonly)

Returns the value of attribute token.



6
7
8
# File 'lib/google_apps_api/contacts.rb', line 6

def token
  @token
end

Instance Method Details

#create_contact(contact, *args) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/google_apps_api/contacts.rb', line 23

def create_contact(contact, *args)
  
  req = <<-DESCXML
  <atom:entry xmlns:atom='http://www.w3.org/2005/Atom'
      xmlns:gd='http://schemas.google.com/g/2005'>
    <atom:category scheme='http://schemas.google.com/g/2005#kind'
      term='http://schemas.google.com/contact/2008#contact' />
    <atom:title type='text'>#{contact.name}</atom:title>
  DESCXML
  
  contact.emails.each_pair do |loc, email|
    req += <<-DESCXML
    <gd:email rel='http://schemas.google.com/g/2005##{loc}'
      primary='#{contact.primary_email == loc ? 'true' : 'false'}'
      address='#{email}' displayName='#{contact.name}' />
    DESCXML
  end
  
  req += "</atom:entry>"
  
  options = args.extract_options!.merge(:body => req.strip)
  
  request(:create_contact, options)
  
end

#remove_contact(contact, *args) ⇒ Object



17
18
19
20
21
# File 'lib/google_apps_api/contacts.rb', line 17

def remove_contact(contact, *args)
  options = args.extract_options!.merge(:contact => contact.id_escaped, :merge_headers => {"If-Match" => "*"})
  
  request(:remove_contact, options)
end

#retrieve_all_contacts(*args) ⇒ Object



12
13
14
15
# File 'lib/google_apps_api/contacts.rb', line 12

def retrieve_all_contacts(*args)
  options = args.extract_options!
  request(:retrieve_all_contacts, options)
end