Class: RestClient::MockHTTPResponse
- Inherits:
-
Object
- Object
- RestClient::MockHTTPResponse
- Defined in:
- lib/cacheability/restclient.rb
Overview
A class that mocks the behaviour of a Net::HTTPResponse class. It is required since RestClient::Response must be initialized with a class that responds to :code and :to_hash.
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
Instance Method Summary collapse
-
#initialize(rack_response) ⇒ MockHTTPResponse
constructor
A new instance of MockHTTPResponse.
- #to_hash ⇒ Object
Constructor Details
#initialize(rack_response) ⇒ MockHTTPResponse
Returns a new instance of MockHTTPResponse.
9 10 11 12 13 14 |
# File 'lib/cacheability/restclient.rb', line 9 def initialize(rack_response) @code, @headers, io = rack_response @body = "" io.each{|block| @body << block} io.close if io.respond_to?(:close) end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
8 9 10 |
# File 'lib/cacheability/restclient.rb', line 8 def body @body end |
#code ⇒ Object (readonly)
Returns the value of attribute code.
8 9 10 |
# File 'lib/cacheability/restclient.rb', line 8 def code @code end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
8 9 10 |
# File 'lib/cacheability/restclient.rb', line 8 def headers @headers end |
Instance Method Details
#to_hash ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/cacheability/restclient.rb', line 16 def to_hash @headers.inject({}) {|out, (key, value)| # In Net::HTTP, headers values are arrays out[key] = value.split(", ") out } end |