contacts 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -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">&quot;1.0.2&quot;</td>
140
+ <td class="context-item-value">&quot;1.0.3&quot;</td>
141
141
  </tr>
142
142
  </table>
143
143
  </div>
@@ -111,10 +111,15 @@
111
111
  <td class="context-item-value">&quot;http://www.hotmail.com/&quot;</td>
112
112
  </tr>
113
113
  <tr class="top-aligned-row context-row">
114
- <td class="context-item-name">CONTACT_LIST_URL</td>
114
+ <td class="context-item-name">OLD_CONTACT_LIST_URL</td>
115
115
  <td>=</td>
116
116
  <td class="context-item-value">&quot;http://%s/cgi-bin/addresses&quot;</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">&quot;http://%s/mail/GetContacts.aspx&quot;</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">&quot;Hotmail has changed its protocols, please upgrade this library first. If that does not work, contact lucas@rufy.com with this error&quot;</td>
131
+ <td class="context-item-value">&quot;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&quot;</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 10</span>
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">&quot;http://mail.live.com/mail&quot;</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
- Fri Mar 30 10:28:09 PDT 2007
1
+ Mon Jun 04 13:35:30 PDT 2007
@@ -56,7 +56,7 @@
56
56
  </tr>
57
57
  <tr class="top-aligned-row">
58
58
  <td><strong>Last Update:</strong></td>
59
- <td>Fri Mar 30 10:27:18 PDT 2007</td>
59
+ <td>Mon Jun 04 13:35:11 PDT 2007</td>
60
60
  </tr>
61
61
  </table>
62
62
  </div>
@@ -56,7 +56,7 @@
56
56
  </tr>
57
57
  <tr class="top-aligned-row">
58
58
  <td><strong>Last Update:</strong></td>
59
- <td>Fri Mar 30 10:23:35 PDT 2007</td>
59
+ <td>Mon Jun 04 13:29:50 PDT 2007</td>
60
60
  </tr>
61
61
  </table>
62
62
  </div>
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.2"
11
+ VERSION = "1.0.3"
12
12
 
13
13
  class Base
14
14
  def initialize(login, password)
@@ -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
+ +
@@ -1,13 +1,16 @@
1
1
  class Contacts
2
2
  class Hotmail < Base
3
3
  URL = "http://www.hotmail.com/"
4
- CONTACT_LIST_URL = "http://%s/cgi-bin/addresses"
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, contact lucas@rufy.com with this error"
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
- CONTACT_LIST_URL % @domain
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
- chunks = data.split('id="hotmail"')
86
- prev = chunks.delete_at(0)
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
- queue = Queue.new
89
- threads = []
90
- @contacts = []
91
- chunks.each do |chunk|
92
- name = chunk.split('return false;">')[1].split('</a>')[0] rescue nil
93
- email = chunk.split('return false;">')[2].split('</a>')[0] rescue nil
94
- unless email && email != "more"
95
- prev = chunk
96
- next
97
- end
98
- next_slot = @contacts.size
99
- @contacts[next_slot] = [name, email]
100
- if email.match(/\.\.\.$/)
101
- if m = prev.match(/\s+id="([A-Za-z0-9\-]+)"/)
102
- queue.push([m[1], next_slot])
103
- if threads.size < MAX_HTTP_THREADS
104
- threads.push(Thread.new {
105
- while x = queue.pop
106
- follow_email(data, *x)
107
- end
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
- threads.each { queue.push(nil) }
116
- threads.each { |t| t.join }
117
- @contacts
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.2
7
- date: 2007-03-30 00:00:00 -07:00
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