Class: GunBroker::ItemsAsPage

Inherits:
Object
  • Object
show all
Defined in:
lib/gun_broker/items_as_page.rb

Overview

Represents a page of GunBroker items (listings).

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ ItemsAsPage

Returns a new instance of ItemsAsPage.

Parameters:

  • attrs (Hash)

    The attributes required to fetch items from the API.



6
7
8
# File 'lib/gun_broker/items_as_page.rb', line 6

def initialize(attributes = {})
  @attributes = attributes
end

Instance Method Details

#fetch_itemsArray<Item>

Returns:



11
12
13
14
15
16
17
18
19
# 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