Class: TCGPlayerSDK::ProductPriceList

Inherits:
Object
  • Object
show all
Defined in:
lib/tcg-player-sdk/product_price_list.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(_response) ⇒ ProductPriceList

Group prices by product ID. This will set prices to an empty hash if there was an error. Check response.errors for details about any errors.

Parameters:



9
10
11
12
13
14
15
16
17
# File 'lib/tcg-player-sdk/product_price_list.rb', line 9

def initialize(_response)
  @response = _response

  if(response.success && response.results)
    @prices = response.results.map{|r| TCGPlayerSDK::ProductPrice.new(r)}.group_by{|r| r.productId}
  else
    @prices = {}
  end
end

Instance Attribute Details

#responseObject

Returns the value of attribute response.



2
3
4
# File 'lib/tcg-player-sdk/product_price_list.rb', line 2

def response
  @response
end

Instance Method Details

#pricesHash<Integer, Array<TCGPlayerSDK::ProductPrice>>

Returns a hash with productIds as keys, and a list of prices with subtypes as values:

{
  85736 => [
      {
               "productId" => 85737,
                "lowPrice" => 4.99,
                "midPrice" => 5.63,
               "highPrice" => 7.73,
             "marketPrice" => 10.35,
          "directLowPrice" => nil,
             "subTypeName" => "Reverse Holofoil"
      },
      {
               "productId" => 85737,
                "lowPrice" => nil,
                "midPrice" => nil,
               "highPrice" => nil,
             "marketPrice" => nil,
          "directLowPrice" => nil,
             "subTypeName" => "Unlimited Holofoil"
      },
  ]
}

Returns:



45
46
47
# File 'lib/tcg-player-sdk/product_price_list.rb', line 45

def prices
  @prices
end

#valid_pricesHash<Integer, Array<TCGPlayerSDK::ProductPrice>>

Weed out any ProductPrice objects that have no valid prices.

Returns:



53
54
55
56
57
58
59
60
61
# File 'lib/tcg-player-sdk/product_price_list.rb', line 53

def valid_prices
  valid_prices = {}
  @prices.each do |id, prl|
    valid_prices[id] ||= []
    valid_prices[id] = prl.select{|pr| pr.has_valid_prices?}
  end

  return valid_prices
end