#!/usr/bin/ruby module GoogleAppsApi #:nodoc: module Contacts class Api < GoogleAppsApi::BaseApi attr_reader :token def initialize(*args) super(:contacts, *args) end def retrieve_all_contacts(*args) options = args.extract_options! request(:retrieve_all_contacts, options) end def remove_contact(contact, *args) options = args.extract_options!.merge(:contact => contact.id_escaped, :merge_headers => {"If-Match" => "*"}) request(:remove_contact, options) end def create_contact(contact, *args) req = <<-DESCXML #{contact.name} DESCXML contact.emails.each_pair do |loc, email| req += <<-DESCXML DESCXML end req += "" options = args.extract_options!.merge(:body => req.strip) request(:create_contact, options) end end end class ContactEntity < Entity attr_reader :name, :emails, :primary_email def initialize(*args) @emails = {} options = args.extract_options! if (_xml = options[:xml]) xml = _xml.at_css("entry") || _xml @kind = "contact" @id = xml.at_css("id").content.gsub(/^.+\/base\//,"") @domain = xml.at_css("id").content.gsub(/^.+\/contacts\/([^\/]+)\/.+$/,"\\1") @name = xml.at_css("title").content else if args.first.kind_of?(String) super(:contact => args.first) else @name = options.delete(:name) @emails = options.delete(:emails) || {} super(options.merge(:kind => "contact")) end end end def ==(other) super(other) end end end