Module: ErpIntegration::Fulfil::PaginationMethods
- Included in:
- ApiResource
- Defined in:
- lib/erp_integration/fulfil/pagination_methods.rb
Constant Summary collapse
- DEFAULT_LIMIT =
Default limit set in FF
500
- DEFAULT_OFFSET =
Default offset set by FF
0
- MAX_LIMIT =
Max limit set by FF
500
Instance Attribute Summary collapse
-
#limit_value ⇒ Object
Returns the value of attribute limit_value.
-
#offset_value ⇒ Object
Returns the value of attribute offset_value.
-
#page_number ⇒ Object
Returns the value of attribute page_number.
Instance Method Summary collapse
-
#limit(value) ⇒ ErpIntegration::Fulfil::ApiResource
(also: #per_page)
By default, Fulfil returns the first 500 records for every query to their API endpoints.
- #limit!(value) ⇒ Object
-
#offset(value) ⇒ ErpIntegration::Fulfil::ApiResource
The #offset method allows navigating through the returned resources from Fulfil’s API endpoints just as with a regular database.
- #offset!(value) ⇒ Object
-
#page(page_number) ⇒ ErpIntegration::Fulfil::ApiResource
The ‘page` method will simplify the use of `limit` and `offset` together with the `per_page` method.
- #page!(page_number) ⇒ ErpIntegration::Fulfil::ApiResource
Instance Attribute Details
#limit_value ⇒ Object
Returns the value of attribute limit_value.
10 11 12 |
# File 'lib/erp_integration/fulfil/pagination_methods.rb', line 10 def limit_value @limit_value end |
#offset_value ⇒ Object
Returns the value of attribute offset_value.
10 11 12 |
# File 'lib/erp_integration/fulfil/pagination_methods.rb', line 10 def offset_value @offset_value end |
#page_number ⇒ Object
Returns the value of attribute page_number.
10 11 12 |
# File 'lib/erp_integration/fulfil/pagination_methods.rb', line 10 def page_number @page_number end |
Instance Method Details
#limit(value) ⇒ ErpIntegration::Fulfil::ApiResource Also known as: per_page
By default, Fulfil returns the first 500 records for every query to their API endpoints. With the #limit method, it’s possible to modify the number of records to return.
NOTE: The maximum limit is 500 per dictation of Fulfil.
34 35 36 |
# File 'lib/erp_integration/fulfil/pagination_methods.rb', line 34 def limit(value) clone.limit!(value.to_i) end |
#limit!(value) ⇒ Object
38 39 40 41 |
# File 'lib/erp_integration/fulfil/pagination_methods.rb', line 38 def limit!(value) self.limit_value = [value, MAX_LIMIT].min self end |
#offset(value) ⇒ ErpIntegration::Fulfil::ApiResource
The #offset method allows navigating through the returned resources from Fulfil’s API endpoints just as with a regular database.
17 18 19 |
# File 'lib/erp_integration/fulfil/pagination_methods.rb', line 17 def offset(value) clone.offset!(value.to_i) end |
#offset!(value) ⇒ Object
21 22 23 24 |
# File 'lib/erp_integration/fulfil/pagination_methods.rb', line 21 def offset!(value) self.offset_value = value self end |
#page(page_number) ⇒ ErpIntegration::Fulfil::ApiResource
The ‘page` method will simplify the use of `limit` and `offset` together with the `per_page` method. Is the quantity of pages that we want to get on the response. It sets the instance variable page_number which will be useful to calculate the offset lazily when the method `calculated_offset` is called. This is because we need to know first the limit before calculate the offset
53 54 55 |
# File 'lib/erp_integration/fulfil/pagination_methods.rb', line 53 def page(page_number) clone.page!(page_number.to_i) end |
#page!(page_number) ⇒ ErpIntegration::Fulfil::ApiResource
59 60 61 62 |
# File 'lib/erp_integration/fulfil/pagination_methods.rb', line 59 def page!(page_number) self.page_number = page_number self end |