Class: WebFetch::Response
- Inherits:
-
Object
- Object
- WebFetch::Response
- Defined in:
- lib/web_fetch/response.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#error ⇒ Object
readonly
Returns the value of attribute error.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#request ⇒ Object
readonly
Returns the value of attribute request.
-
#response_time ⇒ Object
readonly
Returns the value of attribute response_time.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#uid ⇒ Object
readonly
Returns the value of attribute uid.
Instance Method Summary collapse
- #complete? ⇒ Boolean
-
#initialize(response) ⇒ Response
constructor
A new instance of Response.
- #initialize_response(response) ⇒ Object
- #pending? ⇒ Boolean
- #success? ⇒ Boolean
Constructor Details
#initialize(response) ⇒ Response
Returns a new instance of Response.
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/web_fetch/response.rb', line 7 def initialize(response) @pending = response.fetch(:pending, false) return if pending? outcome = response.fetch(:request) @uid = outcome.fetch(:uid) @response_time = outcome.fetch(:response_time, nil) @request = Request.from_hash(outcome.fetch(:request), validate: false) initialize_response(outcome.fetch(:response)) end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
5 6 7 |
# File 'lib/web_fetch/response.rb', line 5 def body @body end |
#error ⇒ Object (readonly)
Returns the value of attribute error.
5 6 7 |
# File 'lib/web_fetch/response.rb', line 5 def error @error end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
5 6 7 |
# File 'lib/web_fetch/response.rb', line 5 def headers @headers end |
#request ⇒ Object (readonly)
Returns the value of attribute request.
5 6 7 |
# File 'lib/web_fetch/response.rb', line 5 def request @request end |
#response_time ⇒ Object (readonly)
Returns the value of attribute response_time.
5 6 7 |
# File 'lib/web_fetch/response.rb', line 5 def response_time @response_time end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
5 6 7 |
# File 'lib/web_fetch/response.rb', line 5 def status @status end |
#uid ⇒ Object (readonly)
Returns the value of attribute uid.
5 6 7 |
# File 'lib/web_fetch/response.rb', line 5 def uid @uid end |
Instance Method Details
#complete? ⇒ Boolean
32 33 34 |
# File 'lib/web_fetch/response.rb', line 32 def complete? !pending? end |
#initialize_response(response) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/web_fetch/response.rb', line 18 def initialize_response(response) @body = Base64.decode64(response.fetch(:body)) @headers = response.fetch(:headers) @status = response.fetch(:status) @success = response.fetch(:success) @error = response.fetch(:error, nil) end |
#pending? ⇒ Boolean
26 27 28 29 30 |
# File 'lib/web_fetch/response.rb', line 26 def pending? return false if @pending.nil? @pending end |
#success? ⇒ Boolean
36 37 38 |
# File 'lib/web_fetch/response.rb', line 36 def success? @success end |