Class: OctaSpace::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/octaspace/response.rb

Overview

Wraps a raw Faraday response, providing a stable SDK interface

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(faraday_response) ⇒ Response

Returns a new instance of Response.

Parameters:

  • faraday_response (Faraday::Response)


9
10
11
12
13
14
15
# File 'lib/octaspace/response.rb', line 9

def initialize(faraday_response)
  @status = faraday_response.status
  @headers = faraday_response.headers
  @body = faraday_response.body
  # Faraday :json middleware parses JSON body into a Hash/Array automatically
  @data = faraday_response.body
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



6
7
8
# File 'lib/octaspace/response.rb', line 6

def body
  @body
end

#dataObject (readonly)

Returns the value of attribute data.



6
7
8
# File 'lib/octaspace/response.rb', line 6

def data
  @data
end

#headersObject (readonly)

Returns the value of attribute headers.



6
7
8
# File 'lib/octaspace/response.rb', line 6

def headers
  @headers
end

#statusObject (readonly)

Returns the value of attribute status.



6
7
8
# File 'lib/octaspace/response.rb', line 6

def status
  @status
end

Instance Method Details

#client_error?Boolean

Returns true for 4xx status codes.

Returns:

  • (Boolean)

    true for 4xx status codes



21
# File 'lib/octaspace/response.rb', line 21

def client_error? = (400..499).cover?(status)

#error?Boolean

Returns true for any non-2xx error.

Returns:

  • (Boolean)

    true for any non-2xx error



27
# File 'lib/octaspace/response.rb', line 27

def error? = client_error? || server_error?

#request_idString?

Returns X-Request-Id header value.

Returns:

  • (String, nil)

    X-Request-Id header value



30
# File 'lib/octaspace/response.rb', line 30

def request_id = headers["x-request-id"]

#retry_afterInteger?

Returns Retry-After header value in seconds.

Returns:

  • (Integer, nil)

    Retry-After header value in seconds



33
# File 'lib/octaspace/response.rb', line 33

def retry_after = headers["retry-after"]&.to_i

#server_error?Boolean

Returns true for 5xx status codes.

Returns:

  • (Boolean)

    true for 5xx status codes



24
# File 'lib/octaspace/response.rb', line 24

def server_error? = (500..599).cover?(status)

#success?Boolean

Returns true for 2xx status codes.

Returns:

  • (Boolean)

    true for 2xx status codes



18
# File 'lib/octaspace/response.rb', line 18

def success? = (200..299).cover?(status)

#to_sObject Also known as: inspect



35
36
37
# File 'lib/octaspace/response.rb', line 35

def to_s
  "#<OctaSpace::Response status=#{status}>"
end