Class: Ecommerce::Resources::Collection

Inherits:
Base
  • Object
show all
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.

Constant Summary collapse

PAGE_REGEX =
/page=(\d+)/

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

client

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

#collectionObject (readonly)

Returns the value of attribute collection.



9
10
11
# File 'lib/ecommerce/resources/collection.rb', line 9

def collection
  @collection
end

#headersObject (readonly)

Returns the value of attribute headers.



9
10
11
# File 'lib/ecommerce/resources/collection.rb', line 9

def headers
  @headers
end

#responseObject (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

#buildObject



21
22
23
24
# File 'lib/ecommerce/resources/collection.rb', line 21

def build
  build_collection
  self
end

#first_pageObject



38
39
40
# File 'lib/ecommerce/resources/collection.rb', line 38

def first_page
  page_for(:first)
end

#last_pageObject



30
31
32
# File 'lib/ecommerce/resources/collection.rb', line 30

def last_page
  page_for(:last)
end

#next_pageObject



26
27
28
# File 'lib/ecommerce/resources/collection.rb', line 26

def next_page
  page_for(:next)
end

#previous_pageObject



34
35
36
# File 'lib/ecommerce/resources/collection.rb', line 34

def previous_page
  page_for(:prev)
end