Permalink
Browse files

include profile pictures for returned contacts

  • Loading branch information...
1 parent 8cb0a75 commit 006169fd2d40c40f42298b5371eaec47f109d5c6 @sailing committed Aug 9, 2012
Showing with 17 additions and 2 deletions.
  1. +17 −2 lib/omnicontacts/importer/gmail.rb
@@ -20,7 +20,7 @@ def initialize *args
def fetch_contacts_using_access_token access_token, token_type
contacts_response = https_get(@contacts_host, @contacts_path, contacts_req_params, contacts_req_headers(access_token, token_type))
- parse_contacts contacts_response
+ parse_contacts contacts_response, access_token, token_type
end
private
@@ -33,9 +33,11 @@ def contacts_req_headers token, token_type
{"GData-Version" => "3.0", "Authorization" => "#{token_type} #{token}"}
end
- def parse_contacts contacts_as_xml
+ def parse_contacts contacts_as_xml, access_token, token_type
xml = REXML::Document.new(contacts_as_xml)
contacts = []
+ contacts << {:access_token => access_token}
+
xml.elements.each('//entry') do |entry|
gd_email = entry.elements['gd:email']
if gd_email
@@ -45,6 +47,19 @@ def parse_contacts contacts_as_xml
gd_full_name = gd_name.elements['gd:fullName']
contact[:name] = gd_full_name.text if gd_full_name
end
+
+ gd_avatar = entry.elements['link[@type="image/*"]']
+ contact[:avatar_url] = gd_avatar ? gd_avatar.attribute('href').to_s : nil
+
+ ### Use the below if you want to return the avatar file itself.
+ # if gd_avatar
+ # avatar_url_parsed = URI.parse(gd_avatar.attribute('href').to_s)
+ # avatar_host = avatar_url_parsed.host
+ # avatar_path = avatar_url_parsed.path
+ # avatar_response = https_get(avatar_host, avatar_path, contacts_req_params, contacts_req_headers(access_token, token_type))
+ # contact[:avatar] = avatar_response.body if avatar_response.status_code == 200
+ # end
+
contacts << contact
end
end

0 comments on commit 006169f

Please sign in to comment.