Class: DuffelAPI::ListResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/duffel_api/list_response.rb

Overview

A page of results returned by a “list” action in the API, provides access to the records on the page, and metadata about the page itself.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ ListResponse

Returns a new instance of ListResponse.



13
14
15
16
17
18
19
# File 'lib/duffel_api/list_response.rb', line 13

def initialize(options = {})
  @response = options.fetch(:response)
  @resource_class = options.fetch(:resource_class)
  @unenveloped_body = options.fetch(:unenveloped_body)

  @records = @unenveloped_body.map { |item| @resource_class.new(item, @response) }
end

Instance Attribute Details

#recordsArray<Resources::BaseResource> (readonly)

Returns the records contained within the page

Returns:

  • (Array<Resources::BaseResource>)

    an array of records - for example, for the list action for offers, this would be a list of ‘Resources::Offer`s



11
12
13
# File 'lib/duffel_api/list_response.rb', line 11

def records
  @records
end

Instance Method Details

#afterString?

Returns the cursor representing the next page of paginated results, if there is a next page

Returns:

  • (String, nil)


40
41
42
# File 'lib/duffel_api/list_response.rb', line 40

def after
  @response.parsed_body["meta"]["after"]
end

#api_responseAPIResponse

Returns the raw API response received for this listing request

Returns:



24
25
26
# File 'lib/duffel_api/list_response.rb', line 24

def api_response
  @api_response ||= APIResponse.new(@response)
end

#beforeString?

Returns the cursor representing the previous page of paginated results, if there is a previous page

Returns:

  • (String, nil)


32
33
34
# File 'lib/duffel_api/list_response.rb', line 32

def before
  @response.parsed_body["meta"]["before"]
end