Class: GoogleContactsApi::Contact

Inherits:
Result
  • Object
show all
Defined in:
lib/google_contacts_api/contact.rb

Instance Attribute Summary

Attributes inherited from Result

#api

Instance Method Summary collapse

Methods inherited from Result

#categories, #content, #deleted?, #etag, #id, #initialize, #inspect, #title, #updated

Constructor Details

This class inherits a constructor from GoogleContactsApi::Result

Instance Method Details

Returns alternative, possibly off-Google home page link



19
20
21
22
# File 'lib/google_contacts_api/contact.rb', line 19

def alternate_link
  _link = self["link"].find { |l| l.rel == "alternate" }
  _link ? _link.href : nil
end

Returns link to edit the contact



56
57
58
59
# File 'lib/google_contacts_api/contact.rb', line 56

def edit_link
  _link = self["link"].find { |l| l.rel == "edit" }
  _link ? _link.href : nil
end

Returns link to add/replace the photo



50
51
52
53
# File 'lib/google_contacts_api/contact.rb', line 50

def edit_photo_link
  _link = self["link"].find { |l| l.rel == "http://schemas.google.com/contacts/2008/rel#edit_photo" }
  _link ? _link.href : nil
end

#emailsObject

Returns all email addresses for the contact



67
68
69
# File 'lib/google_contacts_api/contact.rb', line 67

def emails
  self["gd$email"] ? self["gd$email"].map { |e| e.address } : []
end

#imsObject

Returns all instant messaging addresses for the contact. Doesn’t yet distinguish protocols



83
84
85
# File 'lib/google_contacts_api/contact.rb', line 83

def ims
  self["gd$im"] ? self["gd$im"].map { |i| i.address } : []
end

Returns the array of links, as link is an array for Hashie.



8
9
10
# File 'lib/google_contacts_api/contact.rb', line 8

def links
  self["link"].map { |l| l.href }
end

#phone_numbersObject

Returns all phone numbers for the contact



62
63
64
# File 'lib/google_contacts_api/contact.rb', line 62

def phone_numbers
  self["gd$phoneNumber"] ? self["gd$phoneNumber"].map { |e| e['$t'] } : []
end

#photoObject

Returns binary data for the photo. You can probably use it in a data-uri. This is in PNG format.



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/google_contacts_api/contact.rb', line 33

def photo
  return nil unless @api && photo_link
  response = @api.oauth.get(photo_link)
  
  case GoogleContactsApi::Api.parse_response_code(response)
  # maybe return a placeholder instead of nil
  when 400; return nil
  when 401; return nil
  when 403; return nil
  when 404; return nil
  when 400...500; return nil
  when 500...600; return nil
  else; return response.body
  end
end

Returns link for photo (still need authentication to get the photo data, though)



26
27
28
29
# File 'lib/google_contacts_api/contact.rb', line 26

def photo_link
  _link = self["link"].find { |l| l.rel == "http://schemas.google.com/contacts/2008/rel#photo" }
  _link ? _link.href : nil
end

#primary_emailObject

Returns primary email for the contact



72
73
74
75
76
77
78
79
# File 'lib/google_contacts_api/contact.rb', line 72

def primary_email
  if self["gd$email"]
     = self["gd$email"].find { |e| e.primary == "true" }
     ? .address : nil
  else
    nil # no emails at all
  end
end

Returns link to get this contact



13
14
15
16
# File 'lib/google_contacts_api/contact.rb', line 13

def self_link
  _link = self["link"].find { |l| l.rel == "self" }
  _link ? _link.href : nil
end