Class: APIClientBuilder::Response

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

Overview

The default page object to be used to hold the response from the API in your response handler object. Any response object that will replace this must response to #success?, and #items

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(body, status_code, success_range) ⇒ Response

Returns a new instance of Response.

Parameters:

  • body (String/Array/Hash)

    the response body

  • status_code (Integer)

    the response status code

  • success_range (Array<Integer>)

    the success range of this response



11
12
13
14
15
16
# File 'lib/api_client_builder/response.rb', line 11

def initialize(body, status_code, success_range)
  @body = body
  @status_code = status_code
  @success_range = success_range
  @failed_reason = nil
end

Instance Attribute Details

#bodyObject

Returns the value of attribute body.



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

def body
  @body
end

#status_codeObject

Returns the value of attribute status_code.



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

def status_code
  @status_code
end

Instance Method Details

#mark_failed(reason) ⇒ Object

Used to mark why the response failed



19
20
21
# File 'lib/api_client_builder/response.rb', line 19

def mark_failed(reason)
  @failed_reason = reason
end

#success?Boolean

Defines the success conditional for a response by determining whether or not the status code of the response is within the defined success range

Returns:

  • (Boolean)

    whether or not the response is a success



28
29
30
# File 'lib/api_client_builder/response.rb', line 28

def success?
  @failed_reason.nil? && @success_range.include?(@status_code)
end