contacts 1.2.1 → 1.2.2

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -42,6 +42,9 @@ See the examples/ directory.
42
42
  * Glenn Sidney from Glenn Fu (mailto:glenn@glennfu.com) - http://glennfu.com
43
43
  * Brian McQuay from Onomojo (mailto:brian@onomojo.com) - http://onomojo.com
44
44
  * Adam Hunter (mailto:adamhunter@me.com) - http://adamhunter.me/
45
+ * Glenn Ford (mailto:glenn@glennfu.com) - http://www.glennfu.com/
46
+ * Leonardo Wong (mailto:mac@boy.name)
47
+ * Rusty Burchfield
45
48
 
46
49
  This library is released under the terms of the BSD.
47
50
 
@@ -1,12 +1,3 @@
1
- class Hash
2
- def to_query_string
3
- u = ERB::Util.method(:u)
4
- map { |k, v|
5
- u.call(k) + "=" + u.call(v)
6
- }.join("&")
7
- end
8
- end
9
-
10
1
  class Contacts
11
2
  require 'hpricot'
12
3
  require 'csv'
@@ -53,12 +44,12 @@ class Contacts
53
44
  "redirType" => "",
54
45
  "xchk" => "false"
55
46
  }
56
-
47
+
57
48
  # Get this cookie and stick it in the form to confirm to Aol that your cookies work
58
49
  data, resp, cookies, forward = get(URL)
59
50
  postdata["stips"] = cookie_hash_from_string(cookies)["stips"]
60
51
  postdata["tst"] = cookie_hash_from_string(cookies)["tst"]
61
-
52
+
62
53
  data, resp, cookies, forward, old_url = get(LOGIN_REFERER_URL, cookies) + [URL]
63
54
  until forward.nil?
64
55
  data, resp, cookies, forward, old_url = get(forward, cookies, old_url) + [forward]
@@ -68,19 +59,19 @@ class Contacts
68
59
  until forward.nil?
69
60
  data, resp, cookies, forward, old_url = get(forward, cookies, old_url) + [forward]
70
61
  end
71
-
62
+
72
63
  doc = Hpricot(data)
73
64
  (doc/:input).each do |input|
74
65
  postdata["usrd"] = input.attributes["value"] if input.attributes["name"] == "usrd"
75
66
  end
76
67
  # parse data for <input name="usrd" value="2726212" type="hidden"> and add it to the postdata
77
-
68
+
78
69
  postdata["SNS_SC"] = cookie_hash_from_string(cookies)["SNS_SC"]
79
70
  postdata["SNS_LDC"] = cookie_hash_from_string(cookies)["SNS_LDC"]
80
71
  postdata["LTState"] = cookie_hash_from_string(cookies)["LTState"]
81
72
  # raise data.inspect
82
73
 
83
- data, resp, cookies, forward, old_url = post(LOGIN_URL, postdata.to_query_string, cookies, LOGIN_REFERER_URL) + [LOGIN_REFERER_URL]
74
+ data, resp, cookies, forward, old_url = post(LOGIN_URL, h_to_query_string(postdata), cookies, LOGIN_REFERER_URL) + [LOGIN_REFERER_URL]
84
75
 
85
76
  until forward.nil?
86
77
  data, resp, cookies, forward, old_url = get(forward, cookies, old_url) + [forward]
@@ -97,20 +88,20 @@ class Contacts
97
88
  elsif cookies == ""
98
89
  raise ConnectionError, PROTOCOL_ERROR
99
90
  end
100
-
91
+
101
92
  @cookies = cookies
102
93
  end
103
-
94
+
104
95
  def contacts
105
96
  postdata = {
106
97
  "file" => 'contacts',
107
98
  "fileType" => 'csv'
108
99
  }
109
-
100
+
110
101
  return @contacts if @contacts
111
102
  if connected?
112
103
  data, resp, cookies, forward, old_url = get(CONTACT_LIST_URL, @cookies, CONTACT_LIST_URL) + [CONTACT_LIST_URL]
113
-
104
+
114
105
  until forward.nil?
115
106
  data, resp, cookies, forward, old_url = get(forward, cookies, old_url) + [forward]
116
107
  end
@@ -118,7 +109,7 @@ class Contacts
118
109
  if resp.code_type != Net::HTTPOK
119
110
  raise ConnectionError, self.class.const_get(:PROTOCOL_ERROR)
120
111
  end
121
-
112
+
122
113
  # parse data and grab <input name="user" value="8QzMPIAKs2" type="hidden">
123
114
  doc = Hpricot(data)
124
115
  (doc/:input).each do |input|
@@ -126,7 +117,7 @@ class Contacts
126
117
  end
127
118
 
128
119
  data, resp, cookies, forward, old_url = get(CONTACT_LIST_CSV_URL, @cookies, CONTACT_LIST_URL) + [CONTACT_LIST_URL]
129
-
120
+
130
121
  until forward.nil?
131
122
  data, resp, cookies, forward, old_url = get(forward, cookies, old_url) + [forward]
132
123
  end
@@ -147,7 +138,14 @@ class Contacts
147
138
  ["#{person[0]} #{person[1]}", person[4]] if person[4] && !person[4].empty?
148
139
  end.compact
149
140
  end
141
+
142
+ def h_to_query_string(hash)
143
+ u = ERB::Util.method(:u)
144
+ hash.map { |k, v|
145
+ u.call(k) + "=" + u.call(v)
146
+ }.join("&")
147
+ end
150
148
  end
151
-
149
+
152
150
  TYPES[:aol] = Aol
153
151
  end
@@ -9,7 +9,7 @@ require "erb"
9
9
 
10
10
  class Contacts
11
11
  TYPES = {}
12
- VERSION = "1.2.1"
12
+ VERSION = "1.2.2"
13
13
 
14
14
  class Base
15
15
  def initialize(login, password)
@@ -167,14 +167,14 @@ class Contacts
167
167
 
168
168
  def uncompress(resp, data)
169
169
  case resp.response['content-encoding']
170
- when 'gzip':
170
+ when 'gzip'
171
171
  gz = Zlib::GzipReader.new(StringIO.new(data))
172
172
  data = gz.read
173
173
  gz.close
174
174
  resp.response['content-encoding'] = nil
175
175
  # FIXME: Not sure what Hotmail was feeding me with their 'deflate',
176
176
  # but the headers definitely were not right
177
- when 'deflate':
177
+ when 'deflate'
178
178
  data = Zlib::Inflate.inflate(data)
179
179
  resp.response['content-encoding'] = nil
180
180
  end
@@ -98,7 +98,7 @@ class Contacts
98
98
  c_info[2]
99
99
  end
100
100
 
101
- go = resp.body.include?("Next page")
101
+ go = resp.body.include?("ContactList_next")
102
102
  index += 1
103
103
  end
104
104
 
@@ -94,7 +94,7 @@ class Contacts
94
94
 
95
95
  def parse(data, options={})
96
96
  @contacts ||= []
97
- if data =~ /var InitialContacts = (\[.*?\])/
97
+ if data =~ /var InitialContacts = (\[.*?\]);/
98
98
  @contacts += Contacts.parse_json($1).select{|contact|!contact["email"].to_s.empty?}.map{|contact|[contact["contactName"], contact["email"]]}
99
99
  elsif data =~ /^\{"response":/
100
100
  @contacts += Contacts.parse_json(data)["response"]["ResultSet"]["Contacts"].to_a.select{|contact|!contact["email"].to_s.empty?}.map{|contact|[contact["contactName"], contact["email"]]}
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: contacts
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lucas Carlson
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-05-06 00:00:00 -07:00
12
+ date: 2010-01-20 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -32,7 +32,7 @@ dependencies:
32
32
  - !ruby/object:Gem::Version
33
33
  version: 1.1.1
34
34
  version:
35
- description: A universal interface to grab contact list information from various providers including Yahoo, Gmail, Hotmail, and Plaxo.
35
+ description: A universal interface to grab contact list information from various providers including Yahoo, AOL, Gmail, Hotmail, and Plaxo.
36
36
  email: lucas@rufy.com
37
37
  executables: []
38
38
 
@@ -80,6 +80,6 @@ rubyforge_project:
80
80
  rubygems_version: 1.3.5
81
81
  signing_key:
82
82
  specification_version: 3
83
- summary: A universal interface to grab contact list information from various providers including Yahoo, Gmail, Hotmail, and Plaxo.
83
+ summary: A universal interface to grab contact list information from various providers including Yahoo, AOL, Gmail, Hotmail, and Plaxo.
84
84
  test_files: []
85
85