liangzan-contacts 1.2.9 → 1.2.10

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/lib/contacts/base.rb CHANGED
@@ -34,7 +34,7 @@ class Contacts
34
34
  if connected?
35
35
  url = URI.parse(contact_list_url)
36
36
  http = open_http(url)
37
- resp, data = http.get("#{url.path}?#{url.query}",
37
+ resp = http.get("#{url.path}?#{url.query}",
38
38
  "Cookie" => @cookies
39
39
  )
40
40
 
@@ -42,7 +42,7 @@ class Contacts
42
42
  raise ConnectionError, self.class.const_get(:PROTOCOL_ERROR)
43
43
  end
44
44
 
45
- parse(data, options)
45
+ parse(resp.body, options)
46
46
  end
47
47
  end
48
48
 
@@ -142,8 +142,8 @@ class Contacts
142
142
  "Content-Type" => 'application/x-www-form-urlencoded'
143
143
  }
144
144
  http_header.reject!{|k, v| k == 'Accept-Encoding'} if skip_gzip?
145
- resp, data = http.post(url.path, postdata, http_header)
146
- data = uncompress(resp, data)
145
+ resp = http.post(url.path, postdata, http_header)
146
+ data = uncompress(resp)
147
147
  cookies = parse_cookies(resp.response['set-cookie'], cookies)
148
148
  forward = resp.response['Location']
149
149
  forward ||= (data =~ /<meta.*?url='([^']+)'/ ? CGI.unescapeHTML($1) : nil)
@@ -156,13 +156,13 @@ class Contacts
156
156
  def get(url, cookies="", referer="")
157
157
  url = URI.parse(url)
158
158
  http = open_http(url)
159
- resp, data = http.get("#{url.path}?#{url.query}",
159
+ resp = http.get("#{url.path}?#{url.query}",
160
160
  "User-Agent" => "Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.1) Gecko/20061010 Firefox/2.0",
161
161
  "Accept-Encoding" => "gzip",
162
162
  "Cookie" => cookies,
163
163
  "Referer" => referer
164
164
  )
165
- data = uncompress(resp, data)
165
+ data = uncompress(resp)
166
166
  cookies = parse_cookies(resp.response['set-cookie'], cookies)
167
167
  forward = resp.response['Location']
168
168
  if (not forward.nil?) && URI.parse(forward).host.nil?
@@ -171,7 +171,8 @@ class Contacts
171
171
  return data, resp, cookies, forward
172
172
  end
173
173
 
174
- def uncompress(resp, data)
174
+ def uncompress(resp)
175
+ data = resp.body
175
176
  case resp.response['content-encoding']
176
177
  when 'gzip'
177
178
  gz = Zlib::GzipReader.new(StringIO.new(data))
@@ -210,7 +211,12 @@ class Contacts
210
211
  end
211
212
 
212
213
  def self.guess(login, password, options={})
213
- TYPES.inject([]) do |a, t|
214
+ if keys = options[:types]
215
+ types = TYPES.select{|k, v| keys.include?(k)}
216
+ end
217
+ types ||= TYPES
218
+
219
+ types.inject([]) do |a, t|
214
220
  begin
215
221
  a + t[1].new(login, password, options).contacts
216
222
  rescue AuthenticationError
@@ -62,6 +62,9 @@ class Contacts
62
62
  url = URI.parse(contact_list_url)
63
63
  data, resp, cookies, forward = get(get_contact_list_url, @cookies )
64
64
 
65
+
66
+ data.force_encoding('ISO-8859-1')
67
+
65
68
  @contacts = CSV.parse(data, {:headers => true, :col_sep => data[7]}).map do |row|
66
69
  name = ""
67
70
  name = row["First Name"] if !row["First Name"].nil?
@@ -41,7 +41,7 @@ class Contacts
41
41
  # first, get the addressbook site with the new crumb parameter
42
42
  url = URI.parse(address_book_url)
43
43
  http = open_http(url)
44
- resp, data = http.get("#{url.path}?#{url.query}",
44
+ resp = http.get("#{url.path}?#{url.query}",
45
45
  "Cookie" => @cookies
46
46
  )
47
47
 
@@ -49,12 +49,12 @@ class Contacts
49
49
  raise ConnectionError, self.class.const_get(:PROTOCOL_ERROR)
50
50
  end
51
51
 
52
- crumb = data.to_s[/dotCrumb: '(.*?)'/][13...-1]
52
+ crumb = resp.body.to_s[/dotCrumb: '(.*?)'/][13...-1]
53
53
 
54
54
  # now proceed with the new ".crumb" parameter to get the csv data
55
55
  url = URI.parse(contact_list_url.sub("_crumb=crumb","_crumb=#{crumb}").sub("time", Time.now.to_f.to_s.sub(".","")[0...-2]))
56
56
  http = open_http(url)
57
- resp, more_data = http.get("#{url.path}?#{url.query}",
57
+ resp = http.get("#{url.path}?#{url.query}",
58
58
  "Cookie" => @cookies,
59
59
  "X-Requested-With" => "XMLHttpRequest",
60
60
  "Referer" => address_book_url
@@ -64,13 +64,13 @@ class Contacts
64
64
  raise ConnectionError, self.class.const_get(:PROTOCOL_ERROR)
65
65
  end
66
66
 
67
- if more_data =~ /"TotalABContacts":(\d+)/
67
+ if resp.body =~ /"TotalABContacts":(\d+)/
68
68
  total = $1.to_i
69
69
  ((total / 50.0).ceil).times do |i|
70
70
  # now proceed with the new ".crumb" parameter to get the csv data
71
71
  url = URI.parse(contact_list_url.sub("bucket=1","bucket=#{i}").sub("_crumb=crumb","_crumb=#{crumb}").sub("time", Time.now.to_f.to_s.sub(".","")[0...-2]))
72
72
  http = open_http(url)
73
- resp, more_data = http.get("#{url.path}?#{url.query}",
73
+ resp = http.get("#{url.path}?#{url.query}",
74
74
  "Cookie" => @cookies,
75
75
  "X-Requested-With" => "XMLHttpRequest",
76
76
  "Referer" => address_book_url
@@ -80,7 +80,7 @@ class Contacts
80
80
  raise ConnectionError, self.class.const_get(:PROTOCOL_ERROR)
81
81
  end
82
82
 
83
- parse more_data
83
+ parse resp.body
84
84
  end
85
85
  end
86
86
 
metadata CHANGED
@@ -1,21 +1,22 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: liangzan-contacts
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.9
4
+ version: 1.2.10
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Lucas Carlson
9
9
  - Brad Imbierowicz
10
10
  - Wong Liang Zan
11
+ - Mateusz Konikowski
11
12
  autorequire:
12
13
  bindir: bin
13
14
  cert_chain: []
14
- date: 2012-02-23 00:00:00.000000000Z
15
+ date: 2012-03-02 00:00:00.000000000Z
15
16
  dependencies:
16
17
  - !ruby/object:Gem::Dependency
17
18
  name: json
18
- requirement: &11509120 !ruby/object:Gem::Requirement
19
+ requirement: &8102920 !ruby/object:Gem::Requirement
19
20
  none: false
20
21
  requirements:
21
22
  - - ~>
@@ -23,10 +24,10 @@ dependencies:
23
24
  version: 1.6.5
24
25
  type: :runtime
25
26
  prerelease: false
26
- version_requirements: *11509120
27
+ version_requirements: *8102920
27
28
  - !ruby/object:Gem::Dependency
28
29
  name: gdata_19
29
- requirement: &11507380 !ruby/object:Gem::Requirement
30
+ requirement: &8101380 !ruby/object:Gem::Requirement
30
31
  none: false
31
32
  requirements:
32
33
  - - ~>
@@ -34,10 +35,10 @@ dependencies:
34
35
  version: 1.1.3
35
36
  type: :runtime
36
37
  prerelease: false
37
- version_requirements: *11507380
38
+ version_requirements: *8101380
38
39
  - !ruby/object:Gem::Dependency
39
40
  name: nokogiri
40
- requirement: &11506500 !ruby/object:Gem::Requirement
41
+ requirement: &8100560 !ruby/object:Gem::Requirement
41
42
  none: false
42
43
  requirements:
43
44
  - - ~>
@@ -45,7 +46,7 @@ dependencies:
45
46
  version: 1.5.0
46
47
  type: :runtime
47
48
  prerelease: false
48
- version_requirements: *11506500
49
+ version_requirements: *8100560
49
50
  description: A universal interface to grab contact list information from various providers
50
51
  including Yahoo, AOL, Gmail, Hotmail, and Plaxo. Now supporting Ruby 1.9.
51
52
  email: zan@liangzan.net