Class: Nfe::Http::Response
- Inherits:
-
Data
- Object
- Data
- Nfe::Http::Response
- Defined in:
- lib/nfe/http/response.rb,
sig/nfe/http/response.rbs
Overview
Immutable value object describing a single HTTP response.
A Response carries the raw status code, normalized headers (lowercase
string keys), and a binary-safe body. HTTP errors (4xx/5xx) are returned as
ordinary responses — never raised — so the retry decorator and
ErrorFactory can act on the status. Redirects and 202 are not
followed by the transport; the Location header is preserved here.
response = Nfe::Http::Response.new(status: 200, headers: { "content-type" => "application/json" }, body: "{}")
response.success? # => true
response.header("Content-Type") # => "application/json"
Instance Attribute Summary collapse
-
#body ⇒ String?
readonly
Returns the value of attribute body.
-
#headers ⇒ Hash[String, String]
readonly
Returns the value of attribute headers.
-
#status ⇒ Integer
readonly
Returns the value of attribute status.
Class Method Summary collapse
Instance Method Summary collapse
-
#header(name) ⇒ String?
Case-insensitive header lookup.
-
#initialize(status:, headers: {}, body: nil) ⇒ Response
constructor
A new instance of Response.
-
#location ⇒ String?
The
Locationheader, or nil. -
#success? ⇒ Boolean
True when the status is in the 2xx range.
Constructor Details
#initialize(status:, headers: {}, body: nil) ⇒ Response
Returns a new instance of Response.
20 21 22 |
# File 'lib/nfe/http/response.rb', line 20 def initialize(status:, headers: {}, body: nil) super end |
Instance Attribute Details
#body ⇒ String? (readonly)
Returns the value of attribute body.
6 7 8 |
# File 'sig/nfe/http/response.rbs', line 6 def body @body end |
#headers ⇒ Hash[String, String] (readonly)
Returns the value of attribute headers.
5 6 7 |
# File 'sig/nfe/http/response.rbs', line 5 def headers @headers end |
#status ⇒ Integer (readonly)
Returns the value of attribute status.
4 5 6 |
# File 'sig/nfe/http/response.rbs', line 4 def status @status end |
Class Method Details
.new ⇒ Object
8 |
# File 'sig/nfe/http/response.rbs', line 8
def self.new: (
|
Instance Method Details
#header(name) ⇒ String?
Case-insensitive header lookup.
28 29 30 |
# File 'lib/nfe/http/response.rb', line 28 def header(name) headers[name.downcase] end |
#location ⇒ String?
Returns the Location header, or nil.
38 39 40 |
# File 'lib/nfe/http/response.rb', line 38 def location header("location") end |
#success? ⇒ Boolean
Returns true when the status is in the 2xx range.
33 34 35 |
# File 'lib/nfe/http/response.rb', line 33 def success? (200..299).cover?(status) end |