Class: Fetch::Response
- Inherits:
-
Object
- Object
- Fetch::Response
- Defined in:
- lib/fetch/response.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#redirected ⇒ Object
readonly
Returns the value of attribute redirected.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
-
#initialize(url:, status:, headers:, body:, redirected:) ⇒ Response
constructor
A new instance of Response.
- #json ⇒ Object
- #ok ⇒ Object
- #status_text ⇒ Object
Constructor Details
permalink #initialize(url:, status:, headers:, body:, redirected:) ⇒ Response
Returns a new instance of Response.
6 7 8 9 10 11 12 |
# File 'lib/fetch/response.rb', line 6 def initialize(url:, status:, headers:, body:, redirected:) @url = url @status = status @headers = headers @body = body @redirected = redirected end |
Instance Attribute Details
permalink #body ⇒ Object (readonly)
Returns the value of attribute body.
14 15 16 |
# File 'lib/fetch/response.rb', line 14 def body @body end |
permalink #headers ⇒ Object (readonly)
Returns the value of attribute headers.
14 15 16 |
# File 'lib/fetch/response.rb', line 14 def headers @headers end |
permalink #redirected ⇒ Object (readonly)
Returns the value of attribute redirected.
14 15 16 |
# File 'lib/fetch/response.rb', line 14 def redirected @redirected end |
permalink #status ⇒ Object (readonly)
Returns the value of attribute status.
14 15 16 |
# File 'lib/fetch/response.rb', line 14 def status @status end |
permalink #url ⇒ Object (readonly)
Returns the value of attribute url.
14 15 16 |
# File 'lib/fetch/response.rb', line 14 def url @url end |
Instance Method Details
permalink #json ⇒ Object
[View source]
24 25 26 27 28 |
# File 'lib/fetch/response.rb', line 24 def json(...) return nil unless body JSON.parse(body, ...) end |
permalink #ok ⇒ Object
[View source]
16 17 18 |
# File 'lib/fetch/response.rb', line 16 def ok status.between?(200, 299) end |
permalink #status_text ⇒ Object
[View source]
20 21 22 |
# File 'lib/fetch/response.rb', line 20 def status_text Rack::Utils::HTTP_STATUS_CODES[status] end |