Skip to content

Commit

Permalink
Remove monkey-patch on Hash that conflicts with aws-s3 gem
Browse files Browse the repository at this point in the history
Thanks GICodeWarrior!
  • Loading branch information
Lucas Carlson committed Jan 20, 2010
1 parent 603ac78 commit 0047e07
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 21 deletions.
3 changes: 3 additions & 0 deletions README
Expand Up @@ -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.

40 changes: 19 additions & 21 deletions 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'
Expand Down Expand Up @@ -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]
Expand All @@ -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 <input name="usrd" value="2726212" type="hidden"> 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]
Expand All @@ -97,36 +88,36 @@ 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

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

# parse data and grab <input name="user" value="8QzMPIAKs2" type="hidden">
doc = Hpricot(data)
(doc/:input).each do |input|
postdata["user"] = input.attributes["value"] if input.attributes["name"] == "user"
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
Expand All @@ -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

0 comments on commit 0047e07

Please sign in to comment.