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(**json_parse_options) ⇒ Object
- #ok ⇒ Object
- #status_text ⇒ Object
Constructor Details
#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
#body ⇒ Object (readonly)
Returns the value of attribute body.
14 15 16 |
# File 'lib/fetch/response.rb', line 14 def body @body end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
14 15 16 |
# File 'lib/fetch/response.rb', line 14 def headers @headers end |
#redirected ⇒ Object (readonly)
Returns the value of attribute redirected.
14 15 16 |
# File 'lib/fetch/response.rb', line 14 def redirected @redirected end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
14 15 16 |
# File 'lib/fetch/response.rb', line 14 def status @status end |
#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
#json(**json_parse_options) ⇒ Object
24 25 26 27 28 |
# File 'lib/fetch/response.rb', line 24 def json(**) return nil unless body JSON.parse(body, **Fetch.config., **) end |
#ok ⇒ Object
16 17 18 |
# File 'lib/fetch/response.rb', line 16 def ok status.between?(200, 299) end |
#status_text ⇒ Object
20 21 22 |
# File 'lib/fetch/response.rb', line 20 def status_text Rack::Utils::HTTP_STATUS_CODES[status] end |