Created
September 8, 2010 19:09
-
-
Save godfat/570648 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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