Class: ConvertSdk::HttpClient::Response

Inherits:
Struct
  • Object
show all
Defined in:
lib/convert_sdk/http_client.rb

Overview

An immutable result of a single HTTP request.

+status+ is the HTTP status integer (or FAILURE_STATUS on a transport failure); +body+ is the parsed JSON object (or nil); +headers+ is the response header hash; +#success?+ is a strict 2xx predicate.

Declared as an explicit +class < Struct.new(...)+ subclass (NOT the +Struct.new do...end+ block form): this is the only shape Steep can statically resolve +#success?+ and the keyword constructor against, the same reason the frozen value objects (BucketedVariation/BucketedFeature) use it.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializevoid

Returns builds the struct then freezes it (immutable value object).



71
72
73
74
# File 'lib/convert_sdk/http_client.rb', line 71

def initialize(**)
  super
  freeze
end

Instance Attribute Details

#bodyObject

Returns the value of attribute body

Returns:

  • (Object)

    the current value of body



69
70
71
# File 'lib/convert_sdk/http_client.rb', line 69

def body
  @body
end

#headersObject

Returns the value of attribute headers

Returns:

  • (Object)

    the current value of headers



69
70
71
# File 'lib/convert_sdk/http_client.rb', line 69

def headers
  @headers
end

#statusObject

Returns the value of attribute status

Returns:

  • (Object)

    the current value of status



69
70
71
# File 'lib/convert_sdk/http_client.rb', line 69

def status
  @status
end

Instance Method Details

#success?Boolean

Returns true iff +status+ is in the 2xx range.

Returns:

  • (Boolean)

    true iff +status+ is in the 2xx range.



77
78
79
# File 'lib/convert_sdk/http_client.rb', line 77

def success?
  status.between?(200, 299)
end