Permalink
Browse files

reach

  • Loading branch information...
Nick Kezhaya
Nick Kezhaya committed Mar 14, 2009
1 parent 91f6c5e commit 97aaa65a97e6dc29ea88473e6abd79b874684bc3
Showing with 64 additions and 0 deletions.
  1. +64 −0 reach.rb
View
@@ -0,0 +1,64 @@
+require 'rubygems'
+require 'net/http'
+require 'net/https'
+require 'hpricot'
+
+module Reach
+ VALID_EMAIL = /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i
+
+ def Reach.get_gmail_contacts(email, password)
+ return false if not email =~ VALID_EMAIL
+
+ url = 'www.google.com'
+ path = '/accounts/ClientLogin'
+
+ data = "accountType=HOSTED_OR_GOOGLE&Email=#{email}&Passwd=#{password}" +
+ "&service=cp&source=WhitePaperClip-Reach-1"
+ headers = {
+ 'Content-Type' => 'application/x-www-form-urlencoded'
+ }
+
+ http = Net::HTTP.new(url, 443)
+ http.use_ssl = true
+ resp = http.post(path, data, headers)
+
+ auth_token = resp.body.gsub(/.*\n.*\nAuth=(.*)/, '\1')
+ headers = { 'Authorization' => "GoogleLogin auth=#{auth_token}" }
+
+ path = "http://www.google.com/m8/feeds/contacts/#{email}/full?max-results=99999"
+
+ http = Net::HTTP.new(url, 80)
+ res = http.get(path, headers, nil)
+
+ results = []
+ counter = 0
+ doc = Hpricot::XML(res.body)
+ doc.search("entry").each do |entry|
+ results[counter] = [ entry.search("title").inner_html ]
+
+ entry.search("gd:email[@address]").each do |email|
+ results[counter] << email.attributes['address']
+ end
+
+ counter += 1
+ end
+
+ return results
+ end
+
+ def Reach.get_hotmail_contacts(email, password)
+ return false if not email =~ VALID_EMAIL
+
+
+ end
+
+ def Reach.get_yahoo_contacts(email, password)
+ return false if not email =~ VALID_EMAIL
+
+ end
+
+ def Reach.get_aol_contacts(email, password)
+ return false if not email =~ VALID_EMAIL
+
+ end
+end

0 comments on commit 97aaa65

Please sign in to comment.