Class: OnyxCord::Internal::HTTP::Response

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#bodyString (readonly)

Returns the response body.

Returns:

  • (String)

    the response body



19
20
21
# File 'lib/onyxcord/internal/http.rb', line 19

def body
  @body
end

#codeInteger (readonly)

Returns the HTTP status code.

Returns:

  • (Integer)

    the HTTP status code



22
23
24
# File 'lib/onyxcord/internal/http.rb', line 22

def code
  @code
end

#headersHash (readonly)

Returns the response headers (symbol keys, underscored).

Returns:

  • (Hash)

    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_sObject Also known as: to_str



35
36
37
# File 'lib/onyxcord/internal/http.rb', line 35

def to_s
  @body
end