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 9
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

inspect() click to toggle source

@api private

# File lib/seahorse/client/response.rb, line 61
def inspect
  @data.inspect
end
on(range, &block) 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 40
def on(range, &block)
  response = self
  @context.http_response.on_success(range) do
    block.call(response)
  end
  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 50
def on_success(&block)
  on(200..299, &block)
end
pretty_print(q) click to toggle source

@api private

# File lib/seahorse/client/response.rb, line 66
def pretty_print(q)
  @data.pretty_print(q)
end
respond_to?(*args) click to toggle source

@api private

Calls superclass method
# File lib/seahorse/client/response.rb, line 71
def respond_to?(*args)
  @data.respond_to?(args.first, false) || super
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 56
def successful?
  (200..299).include?(@context.http_response.status_code) && @error.nil?
end

Private Instance Methods

method_missing(*args, &block) click to toggle source
Calls superclass method
# File lib/seahorse/client/response.rb, line 77
def method_missing(*args, &block)
  if @data.respond_to?(args.first, false)
    @data.send(*args, &block)
  else
    super
  end
end