Class: ProntoForms::ResourceList
- Defined in:
- lib/prontoforms/resource_list.rb
Overview
A wrapper for retrieving paged resources.
Instance Attribute Summary collapse
-
#client ⇒ Client
readonly
API client.
-
#method ⇒ Symbol
readonly
Method to send to parent object (usually the client).
-
#parent ⇒ Resource
readonly
Parent object (for child resources).
-
#query ⇒ Hash
readonly
Query parameters for this resource list for e.g.
-
#resource ⇒ Class
readonly
Resource class.
Attributes inherited from Resource
Instance Method Summary collapse
-
#initialize(data, query, method, resource, client, parent = nil) ⇒ ResourceList
constructor
Initialize the resource list TODO: splat rubocop:disable Metrics/ParameterLists.
-
#items ⇒ Array
Retrieve the result set.
-
#next ⇒ ResourceList
Retrieve the next page of results, using the same number of items per page as the original request.
Methods inherited from Resource
property, resource_name, #resource_name
Constructor Details
#initialize(data, query, method, resource, client, parent = nil) ⇒ ResourceList
Initialize the resource list TODO: splat rubocop:disable Metrics/ParameterLists
22 23 24 25 26 27 28 |
# 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 |
Instance Attribute Details
#client ⇒ Client (readonly)
Returns API client.
15 16 17 |
# File 'lib/prontoforms/resource_list.rb', line 15 def client @client end |
#method ⇒ Symbol (readonly)
Returns Method to send to parent object (usually the client).
11 12 13 |
# File 'lib/prontoforms/resource_list.rb', line 11 def method @method end |
#parent ⇒ Resource (readonly)
Returns Parent object (for child resources).
17 18 19 |
# File 'lib/prontoforms/resource_list.rb', line 17 def parent @parent end |
#query ⇒ Hash (readonly)
Returns Query parameters for this resource list for e.g. filters.
9 10 11 |
# File 'lib/prontoforms/resource_list.rb', line 9 def query @query end |
#resource ⇒ Class (readonly)
Returns Resource class.
13 14 15 |
# File 'lib/prontoforms/resource_list.rb', line 13 def resource @resource end |
Instance Method Details
#items ⇒ Array
Retrieve the result set
40 41 42 43 44 |
# File 'lib/prontoforms/resource_list.rb', line 40 def items @data.fetch('pageData').map do |item| resource.new(item, client, parent) end end |
#next ⇒ ResourceList
Retrieve the next page of results, using the same number of items per page as the original request.
34 35 36 |
# File 'lib/prontoforms/resource_list.rb', line 34 def next client.send(method, query: query.merge({ 'p' => query['p'] + 1 })) end |