contacts 1.0.2 → 1.0.3
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/doc/classes/Contacts.html +1 -1
- data/doc/classes/Contacts/Hotmail.html +7 -2
- data/doc/classes/Contacts/Hotmail.src/M000011.html +8 -1
- data/doc/created.rid +1 -1
- data/doc/files/lib/contacts/base_rb.html +1 -1
- data/doc/files/lib/contacts/hotmail_rb.html +1 -1
- data/lib/contacts/base.rb +1 -1
- data/lib/contacts/foo.diff +156 -0
- data/lib/contacts/hotmail.rb +47 -31
- metadata +3 -2
data/doc/classes/Contacts.html
CHANGED
@@ -137,7 +137,7 @@ Class <a href="Contacts/Yahoo.html" class="link">Contacts::Yahoo</a><br />
|
|
137
137
|
<tr class="top-aligned-row context-row">
|
138
138
|
<td class="context-item-name">VERSION</td>
|
139
139
|
<td>=</td>
|
140
|
-
<td class="context-item-value">"1.0.
|
140
|
+
<td class="context-item-value">"1.0.3"</td>
|
141
141
|
</tr>
|
142
142
|
</table>
|
143
143
|
</div>
|
@@ -111,10 +111,15 @@
|
|
111
111
|
<td class="context-item-value">"http://www.hotmail.com/"</td>
|
112
112
|
</tr>
|
113
113
|
<tr class="top-aligned-row context-row">
|
114
|
-
<td class="context-item-name">
|
114
|
+
<td class="context-item-name">OLD_CONTACT_LIST_URL</td>
|
115
115
|
<td>=</td>
|
116
116
|
<td class="context-item-value">"http://%s/cgi-bin/addresses"</td>
|
117
117
|
</tr>
|
118
|
+
<tr class="top-aligned-row context-row">
|
119
|
+
<td class="context-item-name">NEW_CONTACT_LIST_URL</td>
|
120
|
+
<td>=</td>
|
121
|
+
<td class="context-item-value">"http://%s/mail/GetContacts.aspx"</td>
|
122
|
+
</tr>
|
118
123
|
<tr class="top-aligned-row context-row">
|
119
124
|
<td class="context-item-name">COMPOSE_URL</td>
|
120
125
|
<td>=</td>
|
@@ -123,7 +128,7 @@
|
|
123
128
|
<tr class="top-aligned-row context-row">
|
124
129
|
<td class="context-item-name">PROTOCOL_ERROR</td>
|
125
130
|
<td>=</td>
|
126
|
-
<td class="context-item-value">"Hotmail has changed its protocols, please upgrade this library first. If that does not work,
|
131
|
+
<td class="context-item-value">"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"</td>
|
127
132
|
</tr>
|
128
133
|
<tr class="top-aligned-row context-row">
|
129
134
|
<td class="context-item-name">PWDPAD</td>
|
@@ -10,8 +10,10 @@
|
|
10
10
|
<link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
|
11
11
|
</head>
|
12
12
|
<body class="standalone-code">
|
13
|
-
<pre><span class="ruby-comment cmt"># File lib/contacts/hotmail.rb, line
|
13
|
+
<pre><span class="ruby-comment cmt"># File lib/contacts/hotmail.rb, line 11</span>
|
14
14
|
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">real_connect</span>
|
15
|
+
<span class="ruby-ivar">@use_new_contact_url</span> = <span class="ruby-keyword kw">false</span>
|
16
|
+
|
15
17
|
<span class="ruby-identifier">data</span>, <span class="ruby-identifier">resp</span>, <span class="ruby-identifier">cookies</span>, <span class="ruby-identifier">forward</span> = <span class="ruby-identifier">get</span>(<span class="ruby-constant">URL</span>)
|
16
18
|
<span class="ruby-identifier">data</span>, <span class="ruby-identifier">resp</span>, <span class="ruby-identifier">cookies</span>, <span class="ruby-identifier">forward</span> = <span class="ruby-identifier">get</span>(<span class="ruby-identifier">forward</span>, <span class="ruby-identifier">cookies</span>, <span class="ruby-constant">URL</span>)
|
17
19
|
|
@@ -48,6 +50,11 @@
|
|
48
50
|
|
49
51
|
<span class="ruby-keyword kw">if</span> <span class="ruby-identifier">resp</span>.<span class="ruby-identifier">code_type</span> <span class="ruby-operator">!=</span> <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTPOK</span>
|
50
52
|
<span class="ruby-identifier">raise</span> <span class="ruby-constant">ConnectionError</span>, <span class="ruby-constant">PROTOCOL_ERROR</span>
|
53
|
+
<span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">old_url</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-value str">'login.live.com'</span>)
|
54
|
+
<span class="ruby-identifier">data</span>, <span class="ruby-identifier">resp</span>, <span class="ruby-identifier">cookies</span>, <span class="ruby-identifier">forward</span>, <span class="ruby-identifier">old_url</span> = <span class="ruby-identifier">get</span>(<span class="ruby-value str">"http://mail.live.com/mail"</span>, <span class="ruby-identifier">cookies</span>)
|
55
|
+
<span class="ruby-identifier">data</span>, <span class="ruby-identifier">resp</span>, <span class="ruby-identifier">cookies</span>, <span class="ruby-identifier">forward</span>, <span class="ruby-identifier">old_url</span> = <span class="ruby-identifier">get</span>(<span class="ruby-identifier">forward</span>, <span class="ruby-identifier">cookies</span>)
|
56
|
+
<span class="ruby-identifier">old_url</span> = <span class="ruby-identifier">forward</span>
|
57
|
+
<span class="ruby-ivar">@use_new_contact_url</span> = <span class="ruby-keyword kw">true</span>
|
51
58
|
<span class="ruby-keyword kw">end</span>
|
52
59
|
|
53
60
|
<span class="ruby-ivar">@domain</span> = <span class="ruby-constant">URI</span>.<span class="ruby-identifier">parse</span>(<span class="ruby-identifier">old_url</span>).<span class="ruby-identifier">host</span>
|
data/doc/created.rid
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
Mon Jun 04 13:35:30 PDT 2007
|
data/lib/contacts/base.rb
CHANGED
@@ -0,0 +1,156 @@
|
|
1
|
+
Index: hotmail.rb
|
2
|
+
===================================================================
|
3
|
+
--- hotmail.rb (revision 8)
|
4
|
+
+++ hotmail.rb (working copy)
|
5
|
+
@@ -1,13 +1,16 @@
|
6
|
+
class Contacts
|
7
|
+
class Hotmail < Base
|
8
|
+
- URL = "http://www.hotmail.com/"
|
9
|
+
- CONTACT_LIST_URL = "http://%s/cgi-bin/addresses"
|
10
|
+
- COMPOSE_URL = "http://%s/cgi-bin/compose?"
|
11
|
+
- PROTOCOL_ERROR = "Hotmail has changed its protocols, please upgrade this library first. If that does not work, contact lucas@rufy.com with this error"
|
12
|
+
+ URL = "http://www.hotmail.com/"
|
13
|
+
+ OLD_CONTACT_LIST_URL = "http://%s/cgi-bin/addresses"
|
14
|
+
+ NEW_CONTACT_LIST_URL = "http://%s/mail/GetContacts.aspx"
|
15
|
+
+ COMPOSE_URL = "http://%s/cgi-bin/compose?"
|
16
|
+
+ PROTOCOL_ERROR = "Hotmail has changed its protocols - we'll need to change something on our end. Please try back later."
|
17
|
+
PWDPAD = "IfYouAreReadingThisYouHaveTooMuchFreeTime"
|
18
|
+
MAX_HTTP_THREADS = 8
|
19
|
+
|
20
|
+
def real_connect
|
21
|
+
+ @use_new_contact_url = false
|
22
|
+
+
|
23
|
+
data, resp, cookies, forward = get(URL)
|
24
|
+
data, resp, cookies, forward = get(forward, cookies, URL)
|
25
|
+
|
26
|
+
@@ -20,9 +23,9 @@
|
27
|
+
data, resp, cookies, forward = post(form_url, postdata, cookies)
|
28
|
+
|
29
|
+
if data.index("The e-mail address or password is incorrect")
|
30
|
+
- raise AuthenticationError, "Username and password do not match"
|
31
|
+
+ raise AuthenticationError, "Username or password is incorrect"
|
32
|
+
elsif data != ""
|
33
|
+
- raise AuthenticationError, "Required field must not be blank"
|
34
|
+
+ raise AuthenticationError, "Username or password is incorrect"
|
35
|
+
elsif cookies == ""
|
36
|
+
raise ConnectionError, PROTOCOL_ERROR
|
37
|
+
end
|
38
|
+
@@ -41,25 +44,33 @@
|
39
|
+
until forward.nil?
|
40
|
+
data, resp, cookies, forward, old_url = get(forward, cookies, old_url) + [forward]
|
41
|
+
end
|
42
|
+
-
|
43
|
+
+
|
44
|
+
if resp.code_type != Net::HTTPOK
|
45
|
+
raise ConnectionError, PROTOCOL_ERROR
|
46
|
+
+ elsif old_url.include?('login.live.com')
|
47
|
+
+ data, resp, cookies, forward, old_url = get("http://mail.live.com/mail", cookies)
|
48
|
+
+ data, resp, cookies, forward, old_url = get(forward, cookies)
|
49
|
+
+ old_url = forward
|
50
|
+
+ @use_new_contact_url = true
|
51
|
+
end
|
52
|
+
|
53
|
+
@domain = URI.parse(old_url).host
|
54
|
+
@cookies = cookies
|
55
|
+
+
|
56
|
+
rescue AuthenticationError => m
|
57
|
+
if @attempt == 1
|
58
|
+
retry
|
59
|
+
else
|
60
|
+
raise m
|
61
|
+
end
|
62
|
+
+
|
63
|
+
end
|
64
|
+
|
65
|
+
private
|
66
|
+
|
67
|
+
def contact_list_url
|
68
|
+
- CONTACT_LIST_URL % @domain
|
69
|
+
+ return OLD_CONTACT_LIST_URL % @domain unless @use_new_contact_url
|
70
|
+
+ return NEW_CONTACT_LIST_URL % @domain
|
71
|
+
end
|
72
|
+
|
73
|
+
def follow_email(data, id, contacts_slot)
|
74
|
+
@@ -82,42 +93,50 @@
|
75
|
+
end
|
76
|
+
|
77
|
+
def parse(data)
|
78
|
+
- chunks = data.split('id="hotmail"')
|
79
|
+
- prev = chunks.delete_at(0)
|
80
|
+
-
|
81
|
+
- queue = Queue.new
|
82
|
+
- threads = []
|
83
|
+
- @contacts = []
|
84
|
+
- chunks.each do |chunk|
|
85
|
+
- name = chunk.split('return false;">')[1].split('</a>')[0] rescue nil
|
86
|
+
- email = chunk.split('return false;">')[2].split('</a>')[0] rescue nil
|
87
|
+
- unless email && email != "more"
|
88
|
+
- prev = chunk
|
89
|
+
- next
|
90
|
+
- end
|
91
|
+
- next_slot = @contacts.size
|
92
|
+
- @contacts[next_slot] = [name, email]
|
93
|
+
- if email.match(/\.\.\.$/)
|
94
|
+
- if m = prev.match(/\s+id="([A-Za-z0-9\-]+)"/)
|
95
|
+
- queue.push([m[1], next_slot])
|
96
|
+
- if threads.size < MAX_HTTP_THREADS
|
97
|
+
- threads.push(Thread.new {
|
98
|
+
- while x = queue.pop
|
99
|
+
- follow_email(data, *x)
|
100
|
+
- end
|
101
|
+
- })
|
102
|
+
+ unless @use_new_contact_url
|
103
|
+
+ chunks = data.split('id="hotmail"')
|
104
|
+
+ prev = chunks.delete_at(0)
|
105
|
+
+
|
106
|
+
+ queue = Queue.new
|
107
|
+
+ threads = []
|
108
|
+
+ @contacts = []
|
109
|
+
+ chunks.each do |chunk|
|
110
|
+
+ name = chunk.split('return false;">')[1].split('</a>')[0] rescue nil
|
111
|
+
+ email = chunk.split('return false;">')[2].split('</a>')[0] rescue nil
|
112
|
+
+ unless email && email != "more"
|
113
|
+
+ prev = chunk
|
114
|
+
+ next
|
115
|
+
+ end
|
116
|
+
+ next_slot = @contacts.size
|
117
|
+
+ @contacts[next_slot] = [name, email]
|
118
|
+
+ if email.match(/\.\.\.$/)
|
119
|
+
+ if m = prev.match(/\s+id="([A-Za-z0-9\-]+)"/)
|
120
|
+
+ queue.push([m[1], next_slot])
|
121
|
+
+ if threads.size < MAX_HTTP_THREADS
|
122
|
+
+ threads.push(Thread.new {
|
123
|
+
+ while x = queue.pop
|
124
|
+
+ follow_email(data, *x)
|
125
|
+
+ end
|
126
|
+
+ })
|
127
|
+
+ end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
+ prev = chunk
|
131
|
+
end
|
132
|
+
- prev = chunk
|
133
|
+
+
|
134
|
+
+ threads.each { queue.push(nil) }
|
135
|
+
+ threads.each { |t| t.join }
|
136
|
+
+ @contacts
|
137
|
+
+ else
|
138
|
+
+ data = CSV.parse(data)
|
139
|
+
+ col_names = data.shift
|
140
|
+
+ @contacts = data.map do |person|
|
141
|
+
+ [[person[1], person[2], person[3]].delete_if{|i|i.nil?}.join(" "), person[46]] unless person[46].nil?
|
142
|
+
+ end.compact
|
143
|
+
end
|
144
|
+
-
|
145
|
+
- threads.each { queue.push(nil) }
|
146
|
+
- threads.each { |t| t.join }
|
147
|
+
- @contacts
|
148
|
+
end
|
149
|
+
-
|
150
|
+
end
|
151
|
+
|
152
|
+
TYPES[:hotmail] = Hotmail
|
153
|
+
-end
|
154
|
+
|
155
|
+
+end
|
156
|
+
+
|
data/lib/contacts/hotmail.rb
CHANGED
@@ -1,13 +1,16 @@
|
|
1
1
|
class Contacts
|
2
2
|
class Hotmail < Base
|
3
3
|
URL = "http://www.hotmail.com/"
|
4
|
-
|
4
|
+
OLD_CONTACT_LIST_URL = "http://%s/cgi-bin/addresses"
|
5
|
+
NEW_CONTACT_LIST_URL = "http://%s/mail/GetContacts.aspx"
|
5
6
|
COMPOSE_URL = "http://%s/cgi-bin/compose?"
|
6
|
-
PROTOCOL_ERROR = "Hotmail has changed its protocols, please upgrade this library first. If that does not work,
|
7
|
+
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"
|
7
8
|
PWDPAD = "IfYouAreReadingThisYouHaveTooMuchFreeTime"
|
8
9
|
MAX_HTTP_THREADS = 8
|
9
10
|
|
10
11
|
def real_connect
|
12
|
+
@use_new_contact_url = false
|
13
|
+
|
11
14
|
data, resp, cookies, forward = get(URL)
|
12
15
|
data, resp, cookies, forward = get(forward, cookies, URL)
|
13
16
|
|
@@ -44,6 +47,11 @@ class Contacts
|
|
44
47
|
|
45
48
|
if resp.code_type != Net::HTTPOK
|
46
49
|
raise ConnectionError, PROTOCOL_ERROR
|
50
|
+
elsif old_url.include?('login.live.com')
|
51
|
+
data, resp, cookies, forward, old_url = get("http://mail.live.com/mail", cookies)
|
52
|
+
data, resp, cookies, forward, old_url = get(forward, cookies)
|
53
|
+
old_url = forward
|
54
|
+
@use_new_contact_url = true
|
47
55
|
end
|
48
56
|
|
49
57
|
@domain = URI.parse(old_url).host
|
@@ -59,7 +67,7 @@ class Contacts
|
|
59
67
|
private
|
60
68
|
|
61
69
|
def contact_list_url
|
62
|
-
|
70
|
+
(@use_new_contact_url ? NEW_CONTACT_LIST_URL : OLD_CONTACT_LIST_URL) % @domain
|
63
71
|
end
|
64
72
|
|
65
73
|
def follow_email(data, id, contacts_slot)
|
@@ -82,39 +90,47 @@ class Contacts
|
|
82
90
|
end
|
83
91
|
|
84
92
|
def parse(data)
|
85
|
-
|
86
|
-
|
93
|
+
if @use_new_contact_url
|
94
|
+
data = CSV.parse(data)
|
95
|
+
col_names = data.shift
|
96
|
+
@contacts = data.map do |person|
|
97
|
+
[[person[1], person[2], person[3]].delete_if{|i|i.nil?}.join(" "), person[46]] unless person[46].nil?
|
98
|
+
end.compact
|
99
|
+
else
|
100
|
+
chunks = data.split('id="hotmail"')
|
101
|
+
prev = chunks.delete_at(0)
|
87
102
|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
103
|
+
queue = Queue.new
|
104
|
+
threads = []
|
105
|
+
@contacts = []
|
106
|
+
chunks.each do |chunk|
|
107
|
+
name = chunk.split('return false;">')[1].split('</a>')[0] rescue nil
|
108
|
+
email = chunk.split('return false;">')[2].split('</a>')[0] rescue nil
|
109
|
+
unless email && email != "more"
|
110
|
+
prev = chunk
|
111
|
+
next
|
112
|
+
end
|
113
|
+
next_slot = @contacts.size
|
114
|
+
@contacts[next_slot] = [name, email]
|
115
|
+
if email.match(/\.\.\.$/)
|
116
|
+
if m = prev.match(/\s+id="([A-Za-z0-9\-]+)"/)
|
117
|
+
queue.push([m[1], next_slot])
|
118
|
+
if threads.size < MAX_HTTP_THREADS
|
119
|
+
threads.push(Thread.new {
|
120
|
+
while x = queue.pop
|
121
|
+
follow_email(data, *x)
|
122
|
+
end
|
123
|
+
})
|
124
|
+
end
|
109
125
|
end
|
110
126
|
end
|
127
|
+
prev = chunk
|
111
128
|
end
|
112
|
-
prev = chunk
|
113
|
-
end
|
114
129
|
|
115
|
-
|
116
|
-
|
117
|
-
|
130
|
+
threads.each { queue.push(nil) }
|
131
|
+
threads.each { |t| t.join }
|
132
|
+
@contacts
|
133
|
+
end
|
118
134
|
end
|
119
135
|
|
120
136
|
end
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.11
|
|
3
3
|
specification_version: 1
|
4
4
|
name: contacts
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 1.0.
|
7
|
-
date: 2007-
|
6
|
+
version: 1.0.3
|
7
|
+
date: 2007-06-04 00:00:00 -07:00
|
8
8
|
summary: Ridiculously easy contact list information from various providers including Yahoo, Gmail, and Hotmail
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -31,6 +31,7 @@ files:
|
|
31
31
|
- lib/contacts
|
32
32
|
- lib/contacts.rb
|
33
33
|
- lib/contacts/base.rb
|
34
|
+
- lib/contacts/foo.diff
|
34
35
|
- lib/contacts/gmail.rb
|
35
36
|
- lib/contacts/hotmail.rb
|
36
37
|
- lib/contacts/yahoo.rb
|