Sha256: 29b575c4c4f7d36adeb5976c41bfeec5806331cecf72b14c84a62642a2e451c0
Contents?: true
Size: 1.62 KB
Versions: 3
Compression:
Stored size: 1.62 KB
Contents
require "omnicontacts/middleware/oauth2" require "rexml/document" module OmniContacts module Importer class Gmail < Middleware::OAuth2 attr_reader :auth_host, :authorize_path, :auth_token_path, :scope def initialize *args super *args @auth_host = "accounts.google.com" @authorize_path = "/o/oauth2/auth" @auth_token_path = "/o/oauth2/token" @scope = "https://www.google.com/m8/feeds" @contacts_host = "www.google.com" @contacts_path = "/m8/feeds/contacts/default/full" end 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 end private def contacts_req_params {"max-results" => "100"} end def contacts_req_headers token, token_type {"GData-Version" => "3.0", "Authorization" => "#{token_type} #{token}"} end def parse_contacts contacts_as_xml xml = REXML::Document.new(contacts_as_xml) contacts = [] xml.elements.each('//entry') do |entry| gd_email = entry.elements['gd:email'] if gd_email contact = {:email => gd_email.attributes['address']} gd_name = entry.elements['gd:name'] if gd_name gd_full_name = gd_name.elements['gd:fullName'] contact[:name] = gd_full_name.text if gd_full_name end contacts << contact end end contacts end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
omnicontacts-0.2.1 | lib/omnicontacts/importer/gmail.rb |
omnicontacts-0.2.0 | lib/omnicontacts/importer/gmail.rb |
omnicontacts-0.1.7 | lib/omnicontacts/importer/gmail.rb |