Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions lib/google_contacts_api/contact.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,18 @@ def photo_link
_link ? _link.href : nil
end

def photo_etag
photo_link_entry.try(:[], 'gd$etag')
end

#
# If a contact does not have a photo, then the photo link element has no gd:etag attribute.
# https://developers.google.com/google-apps/contacts/v3/#retrieving_a_contacts_photo
#
def has_photo?
photo_etag != nil
end

# Returns binary data for the photo. You can probably
# use it in a data-uri. This is in PNG format.
def photo
Expand Down
14 changes: 13 additions & 1 deletion spec/lib/google_contacts_api/contact_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@
end
end

describe "#photo_etag" do
it "returns correct photo_etag" do
expect(subject.photo_etag).to eq("\"dxt2DAEZfCp7ImA-AV4zRxBoPG4UK3owXBM.\"")
end
end

describe "#has_photo?" do
it "returns true" do
expect(subject.has_photo?).to eq(true)
end
end

describe "#edit_link" do
it "returns correct edit_link" do
expect(subject.edit_link).to eq("https://www.google.com/m8/feeds/contacts/example%40gmail.com/full/0")
Expand Down Expand Up @@ -129,7 +141,7 @@

@partly_empty = GoogleContactsApi::Contact.new(
'gd$name' => {},
'gContact$relation' => []
'gContact$relation' => []
)

@contact_v3 = GoogleContactsApi::Contact.new(
Expand Down