Skip to content

Instantly share code, notes, and snippets.

@godfat
Created September 8, 2010 19:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save godfat/570648 to your computer and use it in GitHub Desktop.
Save godfat/570648 to your computer and use it in GitHub Desktop.
# monkey patch heroku to replace rest-client with em-http-request
class Heroku::Client
def process(method, uri, extra_headers={}, payload=nil)
headers = heroku_headers.merge(extra_headers)
args = [method, payload, headers].compact
# begin HACK
# response = resource(uri).send(*args)
basic_auth = {'Authorization' => 'Basic ' +
["#{user}:#{password}"].pack('m').delete("\r\n")}
if uri =~ /^https?/
http = EM::HttpRequest.new(uri)
else
http = EM::HttpRequest.new("https://api.#{host}#{uri}")
end
response = http.send(method,
:head => {'Accept' => '*/*; q=0.5, application/xml',
'Accept-Encoding' => 'gzip, deflate'}.
merge(headers.merge(basic_auth)),
:body => payload)
if status = response && response.response_header.status
unless response.error.strip.empty? && status == 200
klass = RestClient::Exceptions::EXCEPTIONS_MAP[status]
if klass
raise klass.new
else
raise RestClient::Exception
end
end
end
class << response
alias_method :headers, :response_header
alias_method :to_s, :response
end
# end HACK
extract_warning(response)
response
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment