Class: GunBroker::User::ItemsAsPagesDelegate

Inherits:
Object
  • Object
show all
Includes:
TokenHeader
Defined in:
lib/gun_broker/user/items_as_pages_delegate.rb

Overview

Used to scope ItemsAsPage actions by GunBroker::User.

Instance Method Summary collapse

Constructor Details

#initialize(user, options = {}) ⇒ ItemsAsPagesDelegate

Returns a new instance of ItemsAsPagesDelegate.

Parameters:

  • user (User)

    A GunBroker::User instance to scope item pages by.

  • options (Hash) (defaults to: {})

    { items_per_page => (Integer) }.



12
13
14
15
16
17
18
19
20
# File 'lib/gun_broker/user/items_as_pages_delegate.rb', line 12

def initialize(user, options = {})
  max_page_size = GunBroker::API::PAGE_SIZE
  @user = user
  @items_per_page = options.fetch(:items_per_page, max_page_size)

  if @items_per_page > max_page_size
    raise ArgumentError.new("`items_per_page` may not exceed #{max_page_size}")
  end
end

Instance Method Details

#allArray<ItemsAsPage>

Note:

GET /Items

Returns pages for all the the User's items (both selling and not selling).

Returns:



25
26
27
28
# File 'lib/gun_broker/user/items_as_pages_delegate.rb', line 25

def all
  # NOTE: this endpoint will not return items that were sold
  @all ||= build_pages_for(:Items, params_for(:sellername))
end

#bid_onArray<ItemsAsPage>

Note:

GET /ItemsBidOn

Returns pages for all items the User has bid on.

Returns:



33
34
35
# File 'lib/gun_broker/user/items_as_pages_delegate.rb', line 33

def bid_on
  @bid_on ||= build_pages_for(:ItemsBidOn)
end

#not_won(options = {}) ⇒ Array<ItemsAsPage>

Note:

GET /ItemsNotWon

Returns pages for items the User has bid on, but not won.

Returns:



40
41
42
# File 'lib/gun_broker/user/items_as_pages_delegate.rb', line 40

def not_won(options = {})
  @not_won ||= build_pages_for(:ItemsNotWon, params_for(:timeframe, options))
end

#sellingArray<ItemsAsPage>

Note:

GET /Items

Returns pages for items that are currently selling.

Returns:



47
48
49
# File 'lib/gun_broker/user/items_as_pages_delegate.rb', line 47

def selling
  @selling ||= build_pages_for(:ItemsSelling)
end

#sold(options = {}) ⇒ Array<ItemsAsPage>

Note:

GET /ItemsSold

Returns pages for items the User has sold.

Returns:



54
55
56
# File 'lib/gun_broker/user/items_as_pages_delegate.rb', line 54

def sold(options = {})
  @sold ||= build_pages_for(:ItemsSold, params_for(:timeframe, options))
end

#unsold(options = {}) ⇒ Array<ItemsAsPage>

Note:

GET /ItemsUnsold

Returns pages for items that were listed, but not sold.

Returns:



61
62
63
# File 'lib/gun_broker/user/items_as_pages_delegate.rb', line 61

def unsold(options = {})
  @unsold ||= build_pages_for(:ItemsUnsold, params_for(:timeframe, options))
end

#won(options = {}) ⇒ Array<ItemsAsPage>

Note:

GET /ItemsWon

Returns pages for items the User has won.

Returns:



68
69
70
# File 'lib/gun_broker/user/items_as_pages_delegate.rb', line 68

def won(options = {})
  @won ||= build_pages_for(:ItemsWon, params_for(:timeframe, options))
end