Class: DuffelAPI::ListResponse
- Inherits:
-
Object
- Object
- DuffelAPI::ListResponse
- 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
-
#records ⇒ Array<Resources::BaseResource>
readonly
Returns the records contained within the page.
Instance Method Summary collapse
-
#after ⇒ String?
Returns the cursor representing the next page of paginated results, if there is a next page.
-
#api_response ⇒ APIResponse
Returns the raw API response received for this listing request.
-
#before ⇒ String?
Returns the cursor representing the previous page of paginated results, if there is a previous page.
-
#initialize(options = {}) ⇒ ListResponse
constructor
A new instance of ListResponse.
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( = {}) @response = .fetch(:response) @resource_class = .fetch(:resource_class) @unenveloped_body = .fetch(:unenveloped_body) @records = @unenveloped_body.map { |item| @resource_class.new(item, @response) } end |
Instance Attribute Details
#records ⇒ Array<Resources::BaseResource> (readonly)
Returns the records contained within the page
11 12 13 |
# File 'lib/duffel_api/list_response.rb', line 11 def records @records end |
Instance Method Details
#after ⇒ String?
Returns the cursor representing the next page of paginated results, if there is a next page
40 41 42 |
# File 'lib/duffel_api/list_response.rb', line 40 def after @response.parsed_body["meta"]["after"] end |
#api_response ⇒ APIResponse
Returns the raw API response received for this listing request
24 25 26 |
# File 'lib/duffel_api/list_response.rb', line 24 def api_response @api_response ||= APIResponse.new(@response) end |
#before ⇒ String?
Returns the cursor representing the previous page of paginated results, if there is a previous page
32 33 34 |
# File 'lib/duffel_api/list_response.rb', line 32 def before @response.parsed_body["meta"]["before"] end |