class GunBroker::ItemsAsPage

Represents a page of GunBroker items (listings).

Public Class Methods

new(attributes = {}) click to toggle source

@param attrs [Hash] The attributes required to fetch items from the API.

# File lib/gun_broker/items_as_page.rb, line 6
def initialize(attributes = {})
  @attributes = attributes
end

Public Instance Methods

fetch_items() click to toggle source

@return [Array<Item>]

# File lib/gun_broker/items_as_page.rb, line 11
def fetch_items
  @attributes[:params].merge!({
    'PageIndex' => @attributes[:page_index],
    'PageSize'  => @attributes[:page_size],
  })
  response = GunBroker::API.get(@attributes[:endpoint], @attributes[:params], @attributes[:token_header])

  response['results'].map { |result| GunBroker::Item.new(result) }
end