Class: Prodigi::Collection
- Inherits:
-
Object
- Object
- Prodigi::Collection
- Defined in:
- lib/prodigi/collection.rb
Overview
Represents a paginated collection of resources from the Prodigi API
Collections are returned by list endpoints and include pagination information to help traverse large result sets.
Instance Attribute Summary collapse
-
#data ⇒ Array
readonly
The collection of resources.
-
#has_more ⇒ Boolean
readonly
Whether more results are available.
-
#next_url ⇒ String?
readonly
URL to fetch the next page of results.
Class Method Summary collapse
-
.from_response(response, key:, type:) ⇒ Prodigi::Collection
Creates a Collection from an API response.
Instance Method Summary collapse
-
#initialize(data:, has_more:, next_url:) ⇒ Collection
constructor
Initializes a new Collection.
Constructor Details
#initialize(data:, has_more:, next_url:) ⇒ Collection
Initializes a new Collection
44 45 46 47 48 |
# File 'lib/prodigi/collection.rb', line 44 def initialize(data:, has_more:, next_url:) @data = data @has_more = has_more @next_url = @has_more == true ? next_url : nil end |
Instance Attribute Details
#data ⇒ Array (readonly)
The collection of resources
18 19 20 |
# File 'lib/prodigi/collection.rb', line 18 def data @data end |
#has_more ⇒ Boolean (readonly)
Whether more results are available
18 19 20 |
# File 'lib/prodigi/collection.rb', line 18 def has_more @has_more end |
#next_url ⇒ String? (readonly)
URL to fetch the next page of results
18 19 20 |
# File 'lib/prodigi/collection.rb', line 18 def next_url @next_url end |
Class Method Details
.from_response(response, key:, type:) ⇒ Prodigi::Collection
Creates a Collection from an API response
30 31 32 33 34 35 36 37 |
# File 'lib/prodigi/collection.rb', line 30 def self.from_response(response, key:, type:) body = response.body new( data: body[key].map { |attrs| type.new(attrs) }, has_more: body["hasMore"], next_url: body["nextUrl"] ) end |