class Seahorse::Client::Response

Attributes

context[R]

@return [RequestContext]

data[RW]

@return The response data. This may be ‘nil` if the response contains

an {#error}.
error[RW]

@return [StandardError, nil]

Public Class Methods

new(options = {}) click to toggle source

@option options [RequestContext] :context (nil) @option options [Integer] :status_code (nil) @option options [Http::Headers] :headers (Http::Headers.new) @option options [String] :body (”)

# File lib/seahorse/client/response.rb, line 12
def initialize(options = {})
  @context = options[:context] || RequestContext.new
  @data = options[:data]
  @error = options[:error]
  @http_request = @context.http_request
  @http_response = @context.http_response
  @http_response.on_error do |error|
    @error = error
  end
end

Public Instance Methods

__getobj__() click to toggle source

Necessary to define as a subclass of Delegator @api private

# File lib/seahorse/client/response.rb, line 77
def __getobj__
  @data
end
__setobj__(obj) click to toggle source

Necessary to define as a subclass of Delegator @api private

# File lib/seahorse/client/response.rb, line 83
def __setobj__(obj)
  @data = obj
end
checksum_validated() click to toggle source

@return [String, nil] returns the algorithm used to validate

the response checksum.  Returns nil if no verification was done.
# File lib/seahorse/client/response.rb, line 35
def checksum_validated
  context[:http_checksum][:validated] if context[:http_checksum]
end
on(range) { |response| ... } click to toggle source

@overload on(status_code, &block)

@param [Integer] status_code The block will be
  triggered only for responses with the given status code.

@overload on(status_code_range, &block)

@param [Range<Integer>] status_code_range The block will be
  triggered only for responses with a status code that falls
  witin the given range.

@return [self]

# File lib/seahorse/client/response.rb, line 49
def on(range, &_block)
  response = self
  @context.http_response.on_success(range) do
    yield response
  end
  self
end
on_complete(&block) click to toggle source

@api private

# File lib/seahorse/client/response.rb, line 70
def on_complete(&block)
  @context.http_response.on_done(&block)
  self
end
on_success(&block) click to toggle source

Yields to the block if the response has a 200 level status code. @return [self]

# File lib/seahorse/client/response.rb, line 59
def on_success(&block)
  on(200..299, &block)
end
successful?() click to toggle source

@return [Boolean] Returns ‘true` if the response is complete with

a ~ 200 level http status code.
# File lib/seahorse/client/response.rb, line 65
def successful?
  (200..299).cover?(@context.http_response.status_code) && @error.nil?
end