class ProntoForms::ResourceList
A wrapper for retrieving paged resources.
Attributes
client[R]
@return [Client] API client
method[R]
@return [Symbol] Method to send to parent object (usually the client)
parent[R]
@return [Resource] Parent object (for child resources)
query[R]
@return [Hash] Query parameters for this resource list for e.g. filters
resource[R]
@return [Class] Resource
class
Public Class Methods
new(data, query, method, resource, client, parent = nil)
click to toggle source
Initialize the resource list TODO: splat rubocop:disable Metrics/ParameterLists
Calls superclass method
ProntoForms::Resource::new
# File lib/prontoforms/resource_list.rb, line 22 def initialize(data, query, method, resource, client, parent = nil) super(data, client) @query = query @method = method @resource = resource @parent = parent end
Public Instance Methods
items()
click to toggle source
Retrieve the result set @return [Array] Array of resource objects
# File lib/prontoforms/resource_list.rb, line 40 def items @data.fetch('pageData').map do |item| resource.new(item, client, parent) end end
next()
click to toggle source
Retrieve the next page of results, using the same number of items per page as the original request. @return [ResourceList] A ResourceList
with the next set of results
# File lib/prontoforms/resource_list.rb, line 34 def next client.send(method, query: query.merge({ 'p' => query['p'] + 1 })) end