Class: GoogleContactsApi::Contact
- Defined in:
- lib/google_contacts_api/contact.rb
Instance Attribute Summary
Attributes inherited from Result
Instance Method Summary collapse
-
#alternate_link ⇒ Object
Returns alternative, possibly off-Google home page link.
-
#edit_link ⇒ Object
Returns link to edit the contact.
-
#edit_photo_link ⇒ Object
Returns link to add/replace the photo.
-
#emails ⇒ Object
Returns all email addresses for the contact.
-
#ims ⇒ Object
Returns all instant messaging addresses for the contact.
-
#links ⇒ Object
Returns the array of links, as link is an array for Hashie.
-
#photo ⇒ Object
Returns binary data for the photo.
-
#photo_link ⇒ Object
Returns link for photo (still need authentication to get the photo data, though).
-
#primary_email ⇒ Object
Returns primary email for the contact.
-
#self_link ⇒ Object
Returns link to get this contact.
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
#alternate_link ⇒ Object
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 |
#edit_link ⇒ Object
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 |
#edit_photo_link ⇒ Object
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 |
#emails ⇒ Object
Returns all email addresses for the contact
62 63 64 |
# File 'lib/google_contacts_api/contact.rb', line 62 def emails self["gd$email"] ? self["gd$email"].map { |e| e.address } : [] end |
#ims ⇒ Object
Returns all instant messaging addresses for the contact. Doesn’t yet distinguish protocols
78 79 80 |
# File 'lib/google_contacts_api/contact.rb', line 78 def ims self["gd$im"] ? self["gd$im"].map { |i| i.address } : [] end |
#links ⇒ Object
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 |
#photo ⇒ Object
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 response.code # 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 |
#photo_link ⇒ Object
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_email ⇒ Object
Returns primary email for the contact
67 68 69 70 71 72 73 74 |
# File 'lib/google_contacts_api/contact.rb', line 67 def primary_email if self["gd$email"] _email = self["gd$email"].find { |e| e.primary == "true" } _email ? _email.address : nil else nil # no emails at all end end |
#self_link ⇒ Object
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 |