Class: AbstractApiWrapper::Response::Collection

Inherits:
Array
  • Object
show all
Defined in:
lib/abstract_api_wrapper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*options) ⇒ Collection

Returns a new instance of Collection.



149
150
151
152
# File 'lib/abstract_api_wrapper.rb', line 149

def initialize(*options)
  @request = options[1] if options[1]
  super(options[0])
end

Instance Attribute Details

#requestObject (readonly)

Returns the value of attribute request.



147
148
149
# File 'lib/abstract_api_wrapper.rb', line 147

def request
  @request
end

Instance Method Details

#headersObject



154
155
156
# File 'lib/abstract_api_wrapper.rb', line 154

def headers
  @headers ||= Hashie::Mash.new(@request.headers)
end

#paginationObject



158
159
160
161
162
163
164
165
166
167
168
# File 'lib/abstract_api_wrapper.rb', line 158

def pagination
  @pagination ||= Hashie::Mash.new(
    next_page: headers['x-next-page'].to_i,
    offset: headers['x-offset'].to_i,
    page: headers['x-page'].to_i,
    per_page: headers['x-per-page'].to_i,
    prev_page: headers['prev_page'].to_i,
    total: headers['x-total'].to_i,
    total_pages: headers['x-total-pages'].to_i
  )
end