Class: OnyxCord::Internal::HTTP::Response
- Inherits:
-
Object
- Object
- OnyxCord::Internal::HTTP::Response
- Defined in:
- lib/onyxcord/internal/http.rb
Overview
Lightweight response wrapper so call-sites that relied on RestClient's
.body, .headers, .code interface keep working unchanged.
Instance Attribute Summary collapse
-
#body ⇒ String
readonly
The response body.
-
#code ⇒ Integer
readonly
The HTTP status code.
-
#headers ⇒ Hash
readonly
The response headers (symbol keys, underscored).
Instance Method Summary collapse
-
#initialize(httpx_response) ⇒ Response
constructor
A new instance of Response.
- #to_s ⇒ Object (also: #to_str)
Constructor Details
#initialize(httpx_response) ⇒ Response
Returns a new instance of Response.
27 28 29 30 31 32 33 |
# File 'lib/onyxcord/internal/http.rb', line 27 def initialize(httpx_response) @raw = httpx_response @body = httpx_response.body.to_s @code = httpx_response.respond_to?(:status) ? httpx_response.status : httpx_response.code.to_i response_headers = httpx_response.respond_to?(:headers) ? httpx_response.headers : httpx_response.to_hash @headers = normalize_headers(response_headers) end |
Instance Attribute Details
#body ⇒ String (readonly)
Returns the response body.
19 20 21 |
# File 'lib/onyxcord/internal/http.rb', line 19 def body @body end |
#code ⇒ Integer (readonly)
Returns the HTTP status code.
22 23 24 |
# File 'lib/onyxcord/internal/http.rb', line 22 def code @code end |
#headers ⇒ Hash (readonly)
Returns the response headers (symbol keys, underscored).
25 26 27 |
# File 'lib/onyxcord/internal/http.rb', line 25 def headers @headers end |
Instance Method Details
#to_s ⇒ Object Also known as: to_str
35 36 37 |
# File 'lib/onyxcord/internal/http.rb', line 35 def to_s @body end |