giannichiappetta-contacts 1.0.15 → 1.0.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README CHANGED
@@ -38,6 +38,10 @@ See the examples/ directory.
38
38
 
39
39
  * Britt Selvitelle from Twitter (mailto:anotherbritt@gmail.com) - http://twitter.com
40
40
  * Tony Targonski from GigPark (mailto:tony@gigpark.com) - http://gigpark.com
41
+ * Waheed Barghouthi from Watwet (mailto:waheed.barghouthi@gmail.com) - http://watwet.com ----
42
+
43
+
44
+
41
45
 
42
46
  This library is released under the terms of the BSD.
43
47
 
data/lib/contacts/base.rb CHANGED
@@ -8,7 +8,7 @@ require "thread"
8
8
 
9
9
  class Contacts
10
10
  TYPES = {}
11
- VERSION = "1.0.12"
11
+ VERSION = "1.0.13"
12
12
 
13
13
  class Base
14
14
  def initialize(login, password)
@@ -1,4 +1,14 @@
1
- require "json/add/rails"
1
+ begin
2
+ # If the json gem is available, use it
3
+ require "json/add/rails"
4
+ rescue MissingSourceFile
5
+ # Otherwise wrap the ActiveSupport JSON implementation for our simple use case
6
+ class JSON
7
+ def self.parse(i)
8
+ ActiveSupport::JSON.decode(i)
9
+ end
10
+ end
11
+ end
2
12
 
3
13
  class Contacts
4
14
  class Gmail < Base
@@ -28,9 +38,11 @@ class Contacts
28
38
  data, resp, cookies, forward, old_url = post(LOGIN_URL, postdata, cookie, LOGIN_REFERER_URL) + [LOGIN_URL]
29
39
 
30
40
  cookies = remove_cookie("GMAIL_LOGIN", cookies)
31
-
41
+
32
42
  if data.index("Username and password do not match")
33
43
  raise AuthenticationError, "Username and password do not match"
44
+ elsif data.index("The username or password you entered is incorrect")
45
+ raise AuthenticationError, "Username and password do not match"
34
46
  elsif data.index("Required field must not be blank")
35
47
  raise AuthenticationError, "Login and password must not be blank"
36
48
  elsif data.index("errormsg_0_logincaptcha")
@@ -1,9 +1,9 @@
1
1
  class Contacts
2
2
  class Hotmail < Base
3
- URL = "http://login.live.com/login.srf?id=2"
3
+ URL = "https://login.live.com/login.srf?id=2"
4
4
  OLD_CONTACT_LIST_URL = "http://%s/cgi-bin/addresses"
5
5
  NEW_CONTACT_LIST_URL = "http://%s/mail/GetContacts.aspx"
6
- NEWEST_CONTACT_LIST_URL = "http://%s/mail/options.aspx?subsection=26"
6
+ CONTACT_LIST_URL = "http://mpeople.live.com/default.aspx?pg=0"
7
7
  COMPOSE_URL = "http://%s/cgi-bin/compose?"
8
8
  PROTOCOL_ERROR = "Hotmail has changed its protocols, please upgrade this library first. If that does not work, report this error at http://rubyforge.org/forum/?group_id=2693"
9
9
  PWDPAD = "IfYouAreReadingThisYouHaveTooMuchFreeTime"
@@ -11,7 +11,6 @@ class Contacts
11
11
 
12
12
  def real_connect
13
13
  data, resp, cookies, forward = get(URL)
14
-
15
14
  old_url = URL
16
15
  until forward.nil?
17
16
  data, resp, cookies, forward, old_url = get(forward, cookies, old_url) + [forward]
@@ -37,55 +36,16 @@ class Contacts
37
36
  end
38
37
 
39
38
  old_url = form_url
39
+
40
40
  until forward.nil?
41
41
  data, resp, cookies, forward, old_url = get(forward, cookies, old_url) + [forward]
42
42
  end
43
-
44
- =begin
45
- if data =~ %r{action="(.*?)"}
46
- forward = $1
47
- puts forward
48
- napexp = CGI.escape(data.to_s[/id="NAPExp" value="(.*?)"/][19...-1])
49
- nap = CGI.escape(data.to_s[/id="NAP" value="(.*?)"/][16...-1])
50
- anon = CGI.escape(data.to_s[/id="ANON" value="(.*?)"/][17...-1])
51
- anonexp = CGI.escape(data.to_s[/id="ANONExp" value="(.*?)"/][20...-1])
52
- t = CGI.escape(data.to_s[/id="t" value="(.*?)"/][14...-1])
53
-
54
- postdata = "NAPExp=%s&NAP=%s&ANON=%s&ANONExp=%s&t=%s" % [ napexp, nap, anon, anonexp, t ]
55
- puts postdata
56
- data, resp, cookies, forward, old_url = post(forward, postdata, cookies, old_url) + [forward]
57
- end
58
-
59
- until forward.nil?
60
- data, resp, cookies, forward, old_url = get(forward, cookies, old_url) + [forward]
61
- end
62
- =end
63
43
 
64
44
  data, resp, cookies, forward = get("http://mail.live.com/mail", cookies)
65
45
  until forward.nil?
66
46
  data, resp, cookies, forward, old_url = get(forward, cookies, old_url) + [forward]
67
47
  end
68
-
69
- # click on 'Contiune' if presented with the Hotmail Listened page
70
- # look for the Submit button with a "TakeMeToInbox" name (this should work for other languages)
71
- if (not old_url.grep(/MessageAtLogin.aspx/).first.nil?)
72
-
73
- viewState = data.split(/>\s*?</).grep(/__VIEWSTATE/).first[/value=\".+?\"/][7..-2]
74
- eventValidation = data.split(/>\s*?</).grep(/__EVENTVALIDATION/).first[/value=\".+?\"/][7..-2]
75
- continueValue = data.split(/>\s*?</).grep(/TakeMeToInbox/).first[/value=\".+?\"/][7..-2]
76
-
77
- # post back to the same url
78
- postdata = "%s=%s&%s=%s&%s=%s" % [
79
- "__VIEWSTATE", CGI.escape(viewState),
80
- "__EVENTVALIDATION", CGI.escape(eventValidation),
81
- CGI.escape("TakeMeToInbox"), CGI.escape(continueValue)
82
- ]
83
- data, resp, cookies, forward = post( old_url, postdata, cookies, old_url )
84
- until forward.nil?
85
- data, resp, cookies, forward, old_url = get(forward, cookies, old_url) + [forward]
86
- end
87
- end
88
-
48
+
89
49
  @domain = URI.parse(old_url).host
90
50
  @cookies = cookies
91
51
  rescue AuthenticationError => m
@@ -97,7 +57,6 @@ class Contacts
97
57
  end
98
58
 
99
59
  def contacts(options = {})
100
- return @contacts if @contacts
101
60
  if connected?
102
61
  url = URI.parse(contact_list_url)
103
62
  data, resp, cookies, forward = get( contact_list_url, @cookies )
@@ -105,75 +64,41 @@ class Contacts
105
64
  if resp.code_type != Net::HTTPOK
106
65
  raise ConnectionError, self.class.const_get(:PROTOCOL_ERROR)
107
66
  end
108
-
109
- # we have to click on the Export Contacts button to get the csv:
110
- # Search the content for __VIEWSTATE or __EVENTVALIDATION
111
- viewState = data.split(/>\s*?</).grep(/__VIEWSTATE/).first[/value=\".+?\"/][7..-2]
112
- eventValidation = data.split(/>\s*?</).grep(/__EVENTVALIDATION/).first[/value=\".+?\"/][7..-2]
113
- exportValue = data.split(/>\s*?</).grep(/ctl02\$ExportButton/).first[/value=\".+?\"/][7..-2]
114
- mt = cookies.split("; ").grep(/mt=/).first[3..-1]
115
67
 
116
- # post back to the same url
117
- postdata = "%s=%s&%s=%s&%s=%s&%s=%s" % [
118
- "__VIEWSTATE", CGI.escape(viewState),
119
- "__EVENTVALIDATION", CGI.escape(eventValidation),
120
- CGI.escape("ctl02$ExportButton"), CGI.escape(exportValue),
121
- "mt", CGI.escape( mt )
122
- ]
123
-
124
- url = URI.parse(contact_list_url)
125
- http = open_http(url)
126
- resp, data = http.post("#{url.path}?#{url.query}", postdata,
127
- "User-Agent" => "Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.1) Gecko/20061010 Firefox/2.0",
128
- "Accept-Encoding" => "gzip",
129
- "Cookie" => cookies,
130
- "Referer" => contact_list_url,
131
- "Content-Type" => 'application/x-www-form-urlencoded'
132
- )
133
-
134
- data = uncompress(resp, data)
135
- parse(data, options)
68
+ @contacts = []
69
+ go = true
70
+ index = 0
71
+
72
+ while(go) do
73
+ go = false
74
+ url = URI.parse(get_contact_list_url(index))
75
+ http = open_http(url)
76
+ resp, data = http.get(get_contact_list_url(index), "Cookie" => @cookies)
77
+
78
+ url_match_text_beginning = Regexp.escape("http://m.mail.live.com/?rru=compose&amp;to=")
79
+ url_match_text_end = Regexp.escape("&amp;")
80
+ @contacts = @contacts + resp.body.scan(/#{url_match_text_beginning}(.*)#{url_match_text_end}/)
81
+
82
+ go = resp.body.include?("Next page")
83
+ index += 1
84
+ end
85
+
86
+ @contacts.each do |contact|
87
+ contact = contact.to_a
88
+ contact[1] = CGI::unescape(contact[0])
89
+ contact[0] = nil
90
+ end
91
+ return @contacts
136
92
  end
137
93
  end
138
-
139
-
140
- private
141
94
 
142
- def contact_list_url
143
- NEWEST_CONTACT_LIST_URL % @domain
95
+ def get_contact_list_url(index)
96
+ "http://mpeople.live.com/default.aspx?pg=#{index}"
144
97
  end
145
98
 
146
- def follow_email(data, id, contacts_slot)
147
- compose_url = COMPOSE_URL % @domain
148
- postdata = "HrsTest=&to=#{id}&mailto=1&ref=addresses"
149
- postdata += "&curmbox=00000000-0000-0000-0000-000000000001"
150
-
151
- a = data.split(/>\s*<input\s+/i).grep(/\s+name="a"/i)
152
- return nil if a.empty?
153
-
154
- a = a[0].match(/\s+value="([a-f0-9]+)"/i) or return nil
155
- postdata += "&a=#{a[1]}"
156
-
157
- data, resp, @cookies, forward = post(compose_url, postdata, @cookies)
158
- e = data.split(/>\s*<input\s+/i).grep(/\s+name="to"/i)
159
- return nil if e.empty?
160
-
161
- e = e[0].match(/\s+value="([^"]+)"/i) or return nil
162
- @contacts[contacts_slot][1] = e[1] if e[1].match(/@/)
163
- end
164
-
165
- def parse(data, options={})
166
- data = data.split("\r\n")
167
- data = CSV.parse(data.join("\r\n").gsub('"', '').gsub(';', ','), ';')
168
- col_names = data.shift
169
-
170
- @contacts = data.delete_if{|person|person[0].nil?}.map do |person|
171
- person = person[0].split(",")
172
- next unless (idx = person.index('SMTP'))
173
- [[person[1], person[2], person[3]].delete_if{|i|i.empty?}.join(" "), person[idx - 1]] unless person[idx - 1].nil?
174
- end.compact
175
- end
99
+ private
100
+
101
+ TYPES[:hotmail] = Hotmail
102
+
176
103
  end
177
-
178
- TYPES[:hotmail] = Hotmail
179
104
  end
@@ -34,8 +34,8 @@ class Contacts
34
34
  elsif code == '200'
35
35
  @contacts = []
36
36
  doc.elements.each('//contact') do |cont|
37
- name = cont.elements['fullName'].text #rescue nil
38
- email = cont.elements['email1'].text #rescue nil
37
+ name = cont.elements['fullName'].nil? ? cont.elements['displayName'].text : cont.elements['fullName'].text
38
+ email = cont.elements['email1'].text
39
39
  @contacts << [name, email]
40
40
  end.compact
41
41
  @contacts
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: giannichiappetta-contacts
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.15
4
+ version: 1.0.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lucas Carlson
@@ -9,17 +9,18 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-01-05 00:00:00 -08:00
12
+ date: 2009-05-26 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: json
17
+ type: :runtime
17
18
  version_requirement:
18
19
  version_requirements: !ruby/object:Gem::Requirement
19
20
  requirements:
20
- - - ">"
21
+ - - ">="
21
22
  - !ruby/object:Gem::Version
22
- version: 0.0.0
23
+ version: 1.1.1
23
24
  version:
24
25
  description: A universal interface to grab contact list information from various providers including Yahoo, Gmail, Hotmail, and Plaxo.
25
26
  email: lucas@rufy.com