Class: AbstractApiWrapper::Response::Collection

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from AbstractApiWrapper::ResponseStatus

#status, #success?

Constructor Details

#initialize(*options) ⇒ Collection

Returns a new instance of Collection.



162
163
164
165
# File 'lib/abstract_api_wrapper.rb', line 162

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

Instance Attribute Details

#requestObject (readonly)

Returns the value of attribute request.



160
161
162
# File 'lib/abstract_api_wrapper.rb', line 160

def request
  @request
end

Instance Method Details

#headersObject



167
168
169
# File 'lib/abstract_api_wrapper.rb', line 167

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

#paginationObject



171
172
173
174
175
176
177
178
179
180
181
# File 'lib/abstract_api_wrapper.rb', line 171

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