From 12ab1a288597b546d60e82649efb11705c5bc1fd Mon Sep 17 00:00:00 2001 From: Mikhail Mandronov Date: Thu, 27 Oct 2016 23:32:04 +0600 Subject: [PATCH 1/3] fetch etag for photo of contact and detect has_photo --- lib/google_contacts_api/contact.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/google_contacts_api/contact.rb b/lib/google_contacts_api/contact.rb index 6dcb673..c85fd4e 100644 --- a/lib/google_contacts_api/contact.rb +++ b/lib/google_contacts_api/contact.rb @@ -38,6 +38,14 @@ def photo_link _link ? _link.href : nil end + def photo_etag + photo_link_entry.try(:[], 'gd$etag') + end + + 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 From 558afd11abe25725d693e0aec3c83faa9c2a7878 Mon Sep 17 00:00:00 2001 From: Mikhail Mandronov Date: Thu, 27 Oct 2016 23:35:25 +0600 Subject: [PATCH 2/3] description of has_photo? --- lib/google_contacts_api/contact.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/google_contacts_api/contact.rb b/lib/google_contacts_api/contact.rb index c85fd4e..f5a5fb6 100644 --- a/lib/google_contacts_api/contact.rb +++ b/lib/google_contacts_api/contact.rb @@ -42,6 +42,10 @@ 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 From 14f77c83d48fc69807ba0ba42e6fe22217947f78 Mon Sep 17 00:00:00 2001 From: Mikhail Mandronov Date: Thu, 27 Oct 2016 23:52:18 +0600 Subject: [PATCH 3/3] add photo_etag, has_photo? --- spec/lib/google_contacts_api/contact_spec.rb | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/spec/lib/google_contacts_api/contact_spec.rb b/spec/lib/google_contacts_api/contact_spec.rb index 05318da..4609726 100644 --- a/spec/lib/google_contacts_api/contact_spec.rb +++ b/spec/lib/google_contacts_api/contact_spec.rb @@ -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") @@ -129,7 +141,7 @@ @partly_empty = GoogleContactsApi::Contact.new( 'gd$name' => {}, - 'gContact$relation' => [] + 'gContact$relation' => [] ) @contact_v3 = GoogleContactsApi::Contact.new(