Class: LHC::Response
- Inherits:
-
Object
- Object
- LHC::Response
- Defined in:
- lib/lhc/response.rb
Overview
The response contains the raw response (typhoeus) and provides functionality to access response data.
Instance Attribute Summary collapse
-
#request ⇒ Object
Returns the value of attribute request.
Instance Method Summary collapse
- #body ⇒ Object
- #code ⇒ Object
-
#data ⇒ Object
Access response data.
- #effective_url ⇒ Object
- #headers ⇒ Object
-
#initialize(raw, request) ⇒ Response
constructor
A response is initalized with the underlying raw response (typhoeus in our case) and the associated request.
- #options ⇒ Object
- #success? ⇒ Boolean
-
#time ⇒ Object
Provides response time in ms.
- #timeout? ⇒ Boolean
Constructor Details
#initialize(raw, request) ⇒ Response
A response is initalized with the underlying raw response (typhoeus in our case) and the associated request.
11 12 13 14 |
# File 'lib/lhc/response.rb', line 11 def initialize(raw, request) self.request = request self.raw = raw end |
Instance Attribute Details
#request ⇒ Object
Returns the value of attribute request.
7 8 9 |
# File 'lib/lhc/response.rb', line 7 def request @request end |
Instance Method Details
#body ⇒ Object
27 28 29 |
# File 'lib/lhc/response.rb', line 27 def body raw.body end |
#code ⇒ Object
31 32 33 |
# File 'lib/lhc/response.rb', line 31 def code raw.code end |
#data ⇒ Object
Access response data. Cache parsing.
18 19 20 21 |
# File 'lib/lhc/response.rb', line 18 def data @data ||= format.parse(self) @data end |
#effective_url ⇒ Object
23 24 25 |
# File 'lib/lhc/response.rb', line 23 def effective_url raw.effective_url end |
#headers ⇒ Object
35 36 37 |
# File 'lib/lhc/response.rb', line 35 def headers raw.headers end |
#options ⇒ Object
39 40 41 |
# File 'lib/lhc/response.rb', line 39 def raw. end |
#success? ⇒ Boolean
52 53 54 |
# File 'lib/lhc/response.rb', line 52 def success? raw.success? end |
#time ⇒ Object
Provides response time in ms.
44 45 46 |
# File 'lib/lhc/response.rb', line 44 def time (raw.time || 0) * 1000 end |
#timeout? ⇒ Boolean
48 49 50 |
# File 'lib/lhc/response.rb', line 48 def timeout? raw.timed_out? end |