Class: Ecommerce::Resources::Collection
- Defined in:
- lib/ecommerce/resources/collection.rb
Overview
A wrapper to Ecommerce collection returns from API. This wrapper represents a collection and it’s responsible for processing pagination information as well.
Direct Known Subclasses
AdjustmentOrderCollection, InvoiceOrderCollection, OrderCollection
Constant Summary collapse
- PAGE_REGEX =
/page=(\d+)/
Instance Attribute Summary collapse
-
#collection ⇒ Object
readonly
Returns the value of attribute collection.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Class Method Summary collapse
Instance Method Summary collapse
- #build ⇒ Object
- #first_page ⇒ Object
-
#initialize(response) ⇒ Collection
constructor
A new instance of Collection.
- #last_page ⇒ Object
- #next_page ⇒ Object
- #previous_page ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(response) ⇒ Collection
Returns a new instance of Collection.
11 12 13 14 15 |
# File 'lib/ecommerce/resources/collection.rb', line 11 def initialize(response) @response = response @collection = [] @headers = response.headers['Link'].split(',') if response.headers['Link'] end |
Instance Attribute Details
#collection ⇒ Object (readonly)
Returns the value of attribute collection.
9 10 11 |
# File 'lib/ecommerce/resources/collection.rb', line 9 def collection @collection end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
9 10 11 |
# File 'lib/ecommerce/resources/collection.rb', line 9 def headers @headers end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
9 10 11 |
# File 'lib/ecommerce/resources/collection.rb', line 9 def response @response end |
Class Method Details
.build(response) ⇒ Object
17 18 19 |
# File 'lib/ecommerce/resources/collection.rb', line 17 def self.build(response) self.new(response).build end |
Instance Method Details
#build ⇒ Object
21 22 23 24 |
# File 'lib/ecommerce/resources/collection.rb', line 21 def build build_collection self end |
#first_page ⇒ Object
38 39 40 |
# File 'lib/ecommerce/resources/collection.rb', line 38 def first_page page_for(:first) end |
#last_page ⇒ Object
30 31 32 |
# File 'lib/ecommerce/resources/collection.rb', line 30 def last_page page_for(:last) end |
#next_page ⇒ Object
26 27 28 |
# File 'lib/ecommerce/resources/collection.rb', line 26 def next_page page_for(:next) end |
#previous_page ⇒ Object
34 35 36 |
# File 'lib/ecommerce/resources/collection.rb', line 34 def previous_page page_for(:prev) end |