-
Notifications
You must be signed in to change notification settings - Fork 6
Paginators
Matt Muller edited this page Apr 12, 2024
·
6 revisions
Paginators are classes that provide an abstraction for paginating operations. These classes provide enumerators that will automatically iterate the paginated responses and items. Paginators have a 1:1 mapping to Smithy operation shapes modeled with the pagination trait.
@paginated(inputToken: "nextToken", outputToken: "nextToken",
pageSize: "maxResults", items: "highScores")
operation ListHighScores {
input: ListHighScoresInput,
output: ListHighScoresOutput
}
Paginator classes must take an instance of the Client, params for the operation, and optionally any override options for the operation. Modeled param members are generally used to control page size and max items returned. The class has up to two methods, pages
and items
, which will return Enumerator
objects for output pages and each item, respectively. The items
method will only exist if the trait defines the items
property.
client = HighScoreService::Client.new(endpoint: 'http://127.0.0.1:3000')
# => #<HighScoreService::Client ... >
# Must be passed params and optionally any options for list_high_scores
params = {}
options = {}
paginator = HighScoreService::Paginators::ListHighScores.new(client, params, options)
# => #<HighScoreService::Paginators::ListHighScores ... >
paginator.pages
# => #<Enumerator: ... >
paginator.items
# => #<Enumerator: ... >
paginator.pages each do |page|
# do something with each page (Hearth::Output)
end
paginator.items each do |item|
# do something with each item (Types::HighScoreAttributes)
end