Class: RestClient::Rack::Compatibility
- Inherits:
-
Object
- Object
- RestClient::Rack::Compatibility
- Defined in:
- lib/restclient/components.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ Compatibility
constructor
A new instance of Compatibility.
Constructor Details
#initialize(app) ⇒ Compatibility
Returns a new instance of Compatibility.
7 8 9 |
# File 'lib/restclient/components.rb', line 7 def initialize(app) @app = app end |
Instance Method Details
#call(env) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/restclient/components.rb', line 11 def call(env) status, header, body = @app.call(env) net_http_response = RestClient::MockNetHTTPResponse.new(body, status, header) content = "" net_http_response.body.each{|line| content << line} response = RestClient::Response.create(content, net_http_response, {}) if block = env['restclient.hash'][:block] block.call(response) # only raise error if response is not successful elsif !(200...300).include?(response.code) && e = env['restclient.hash'][:error] raise e else response end end |