cardmagic / contacts

A universal interface to import email contacts from various providers including Yahoo, Gmail, Hotmail, AOL and Plaxo.
http://rubyforge.org/projects/contacts
BSD 3-Clause "New" or "Revised" License
616 stars 218 forks source link

This example code might help your users get up and running #35

Open rugyoga opened 13 years ago

rugyoga commented 13 years ago
require 'gdata'
require 'contacts'

service, login, password = ARGV[0], ARGV[1], ARGV[2]
accepted = %w(aol gmail hotmail plaxo yahoo)
if accepted.include? service
  mapped = Contacts.new(service, login, password).contacts.inject( {} ){ |xs, x| (xs[x[0]] ||= []) << x[1] unless x[1].nil?; xs}.to_a.map{ |name, emails| [name.downcase, emails.uniq.sort]}.sort
  print mapped.map{ |name, emails| "#{name}: #{emails.join(',')}" }.join( "\n" ) + "\n"
else
  print "Sorry I don't know how to access '#{service}'. It has to be one of: #{accepted.join(', ')}\n"
end