diff --git a/README b/README index 37d374e..f9e80da 100644 --- a/README +++ b/README @@ -42,6 +42,9 @@ See the examples/ directory. * Glenn Sidney from Glenn Fu (mailto:glenn@glennfu.com) - http://glennfu.com * Brian McQuay from Onomojo (mailto:brian@onomojo.com) - http://onomojo.com * Adam Hunter (mailto:adamhunter@me.com) - http://adamhunter.me/ +* Glenn Ford (mailto:glenn@glennfu.com) - http://www.glennfu.com/ +* Leonardo Wong (mailto:mac@boy.name) +* Rusty Burchfield This library is released under the terms of the BSD. diff --git a/lib/contacts/aol.rb b/lib/contacts/aol.rb index aa0136b..e63dc26 100644 --- a/lib/contacts/aol.rb +++ b/lib/contacts/aol.rb @@ -1,12 +1,3 @@ -class Hash - def to_query_string - u = ERB::Util.method(:u) - map { |k, v| - u.call(k) + "=" + u.call(v) - }.join("&") - end -end - class Contacts require 'hpricot' require 'csv' @@ -53,12 +44,12 @@ def real_connect "redirType" => "", "xchk" => "false" } - + # Get this cookie and stick it in the form to confirm to Aol that your cookies work data, resp, cookies, forward = get(URL) postdata["stips"] = cookie_hash_from_string(cookies)["stips"] postdata["tst"] = cookie_hash_from_string(cookies)["tst"] - + data, resp, cookies, forward, old_url = get(LOGIN_REFERER_URL, cookies) + [URL] until forward.nil? data, resp, cookies, forward, old_url = get(forward, cookies, old_url) + [forward] @@ -68,19 +59,19 @@ def real_connect until forward.nil? data, resp, cookies, forward, old_url = get(forward, cookies, old_url) + [forward] end - + doc = Hpricot(data) (doc/:input).each do |input| postdata["usrd"] = input.attributes["value"] if input.attributes["name"] == "usrd" end # parse data for and add it to the postdata - + postdata["SNS_SC"] = cookie_hash_from_string(cookies)["SNS_SC"] postdata["SNS_LDC"] = cookie_hash_from_string(cookies)["SNS_LDC"] postdata["LTState"] = cookie_hash_from_string(cookies)["LTState"] # raise data.inspect - data, resp, cookies, forward, old_url = post(LOGIN_URL, postdata.to_query_string, cookies, LOGIN_REFERER_URL) + [LOGIN_REFERER_URL] + data, resp, cookies, forward, old_url = post(LOGIN_URL, h_to_query_string(postdata), cookies, LOGIN_REFERER_URL) + [LOGIN_REFERER_URL] until forward.nil? data, resp, cookies, forward, old_url = get(forward, cookies, old_url) + [forward] @@ -97,20 +88,20 @@ def real_connect elsif cookies == "" raise ConnectionError, PROTOCOL_ERROR end - + @cookies = cookies end - + def contacts postdata = { "file" => 'contacts', "fileType" => 'csv' } - + return @contacts if @contacts if connected? data, resp, cookies, forward, old_url = get(CONTACT_LIST_URL, @cookies, CONTACT_LIST_URL) + [CONTACT_LIST_URL] - + until forward.nil? data, resp, cookies, forward, old_url = get(forward, cookies, old_url) + [forward] end @@ -118,7 +109,7 @@ def contacts if resp.code_type != Net::HTTPOK raise ConnectionError, self.class.const_get(:PROTOCOL_ERROR) end - + # parse data and grab doc = Hpricot(data) (doc/:input).each do |input| @@ -126,7 +117,7 @@ def contacts end data, resp, cookies, forward, old_url = get(CONTACT_LIST_CSV_URL, @cookies, CONTACT_LIST_URL) + [CONTACT_LIST_URL] - + until forward.nil? data, resp, cookies, forward, old_url = get(forward, cookies, old_url) + [forward] end @@ -147,7 +138,14 @@ def parse(data, options={}) ["#{person[0]} #{person[1]}", person[4]] if person[4] && !person[4].empty? end.compact end + + def h_to_query_string(hash) + u = ERB::Util.method(:u) + hash.map { |k, v| + u.call(k) + "=" + u.call(v) + }.join("&") + end end - + TYPES[:aol] = Aol end \ No newline at end of file