Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ require 'rake/testtask'
require 'rake/rdoctask'
require 'rake/gempackagetask'
require 'rake/contrib/rubyforgepublisher'
require 'lib/contacts'
require './lib/contacts'

PKG_VERSION = Contacts::VERSION

Expand Down Expand Up @@ -88,4 +88,4 @@ task :stats do
["Library", "lib"],
["Units", "test"]
).to_s
end
end
4 changes: 3 additions & 1 deletion lib/contacts/aol.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,9 @@ def contacts
def parse(data, options={})
begin
@contacts = []
FasterCSV.parse(data) do |person|
# Ruby 1.9 CSV is FasterCSV
csv_class = (RUBY_VERSION.split(/\./)[1] == '8') ? FasterCSV : CSV
csv_class.parse(data) do |person|
@contacts << ["#{person[0]} #{person[1]}", person[4]] if person[4] && !person[4].empty?
end
@contacts
Expand Down
14 changes: 7 additions & 7 deletions lib/contacts/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ def contacts(options = {})
if connected?
url = URI.parse(contact_list_url)
http = open_http(url)
resp, data = http.get("#{url.path}?#{url.query}",
resp = http.get("#{url.path}?#{url.query}",
"Cookie" => @cookies
)

if resp.code_type != Net::HTTPOK
raise ConnectionError, self.class.const_get(:PROTOCOL_ERROR)
end

parse(data, options)
parse(resp.body, options)
end
end

Expand Down Expand Up @@ -143,8 +143,8 @@ def post(url, postdata, cookies="", referer="")
"Content-Type" => 'application/x-www-form-urlencoded'
}
http_header.reject!{|k, v| k == 'Accept-Encoding'} if skip_gzip?
resp, data = http.post(url.path, postdata, http_header)
data = uncompress(resp, data)
resp = http.post(url.path, postdata, http_header)
data = uncompress(resp)
cookies = parse_cookies(resp.response['set-cookie'], cookies)
forward = resp.response['Location']
forward ||= (data =~ /<meta.*?url='([^']+)'/ ? CGI.unescapeHTML($1) : nil)
Expand All @@ -157,13 +157,13 @@ def post(url, postdata, cookies="", referer="")
def get(url, cookies="", referer="")
url = URI.parse(url)
http = open_http(url)
resp, data = http.get("#{url.path}?#{url.query}",
resp = http.get("#{url.path}?#{url.query}",
"User-Agent" => "Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.1) Gecko/20061010 Firefox/2.0",
"Accept-Encoding" => "gzip",
"Cookie" => cookies,
"Referer" => referer
)
data = uncompress(resp, data)
data = uncompress(resp)
cookies = parse_cookies(resp.response['set-cookie'], cookies)
forward = resp.response['Location']
if (not forward.nil?) && URI.parse(forward).host.nil?
Expand All @@ -172,7 +172,7 @@ def get(url, cookies="", referer="")
return data, resp, cookies, forward
end

def uncompress(resp, data)
def uncompress(resp, data = resp.body)
case resp.response['content-encoding']
when 'gzip'
gz = Zlib::GzipReader.new(StringIO.new(data))
Expand Down
2 changes: 1 addition & 1 deletion lib/contacts/hotmail.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def contacts(options = {})
go = false
url = URI.parse(get_contact_list_url(index))
http = open_http(url)
resp, data = http.get(get_contact_list_url(index), "Cookie" => @cookies)
resp = http.get(get_contact_list_url(index), "Cookie" => @cookies)

email_match_text_beginning = Regexp.escape("http://m.mail.live.com/?rru=compose&amp;to=")
email_match_text_end = Regexp.escape("&amp;ru=")
Expand Down
10 changes: 6 additions & 4 deletions lib/contacts/yahoo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,10 @@ def contacts
# first, get the addressbook site with the new crumb parameter
url = URI.parse(address_book_url)
http = open_http(url)
resp, data = http.get("#{url.path}?#{url.query}",
resp = http.get("#{url.path}?#{url.query}",
"Cookie" => @cookies
)
data = resp.body

if resp.code_type != Net::HTTPOK
raise ConnectionError, self.class.const_get(:PROTOCOL_ERROR)
Expand All @@ -59,11 +60,12 @@ def contacts
# now proceed with the new ".crumb" parameter to get the csv data
url = URI.parse(contact_list_url.sub("_crumb=crumb","_crumb=#{crumb}").sub("time", Time.now.to_f.to_s.sub(".","")[0...-2]))
http = open_http(url)
resp, more_data = http.get("#{url.path}?#{url.query}",
resp = http.get("#{url.path}?#{url.query}",
"Cookie" => @cookies,
"X-Requested-With" => "XMLHttpRequest",
"Referer" => address_book_url
)
more_data = resp.body

if resp.code_type != Net::HTTPOK
raise ConnectionError, self.class.const_get(:PROTOCOL_ERROR)
Expand All @@ -79,7 +81,7 @@ def contacts
# now proceed with the new ".crumb" parameter to get the csv data
url = URI.parse(contact_list_url.sub("bucket=1","bucket=#{i+1}").sub("_crumb=crumb","_crumb=#{crumb}").sub("time", Time.now.to_f.to_s.sub(".","")[0...-2]))
http = open_http(url)
resp, more_data = http.get("#{url.path}?#{url.query}",
resp = http.get("#{url.path}?#{url.query}",
"Cookie" => @cookies,
"X-Requested-With" => "XMLHttpRequest",
"Referer" => address_book_url
Expand All @@ -89,7 +91,7 @@ def contacts
raise ConnectionError, self.class.const_get(:PROTOCOL_ERROR)
end

parse more_data
parse resp.body
end
end

Expand Down