Class: FocusNfe::HTTP::Response
- Inherits:
-
Object
- Object
- FocusNfe::HTTP::Response
- Defined in:
- lib/focus_nfe/http/response.rb
Overview
Wrapper imutável de uma resposta HTTP da API Focus NFe.
Expõe status, headers (leitura case-insensitive), body (JSON
parseado quando o Content-Type indica JSON, senão a string crua) e
raw_body (sempre a string original). O parsing é eager no construtor —
a instância é congelada, então não há memoização preguiçosa.
Defined Under Namespace
Classes: Headers
Constant Summary collapse
- JSON_TYPE =
Returns reconhece
Content-TypeJSON (incluindo sufixos +.../...+json+). %r{\bapplication/(?:[\w.+-]+\+)?json\b}i
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#raw_body ⇒ Object
readonly
Returns the value of attribute raw_body.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Instance Method Summary collapse
-
#initialize(status:, headers: {}, body: nil) ⇒ Response
constructor
A new instance of Response.
-
#success? ⇒ Boolean
truequando o status está na faixa 2xx.
Constructor Details
#initialize(status:, headers: {}, body: nil) ⇒ Response
Returns a new instance of Response.
45 46 47 48 49 50 51 |
# File 'lib/focus_nfe/http/response.rb', line 45 def initialize(status:, headers: {}, body: nil) @status = status @headers = Headers.new(headers) @raw_body = body @body = parse_body freeze end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
40 41 42 |
# File 'lib/focus_nfe/http/response.rb', line 40 def body @body end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
40 41 42 |
# File 'lib/focus_nfe/http/response.rb', line 40 def headers @headers end |
#raw_body ⇒ Object (readonly)
Returns the value of attribute raw_body.
40 41 42 |
# File 'lib/focus_nfe/http/response.rb', line 40 def raw_body @raw_body end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
40 41 42 |
# File 'lib/focus_nfe/http/response.rb', line 40 def status @status end |
Instance Method Details
#success? ⇒ Boolean
Returns true quando o status está na faixa 2xx.
54 55 56 |
# File 'lib/focus_nfe/http/response.rb', line 54 def success? status.between?(200, 299) end |