class Mkmapi::Marketplace

Public Instance Methods

expansions(game_id = 1) click to toggle source
# File lib/mkmapi/marketplace.rb, line 47
def expansions(game_id = 1)
  agent.get("games/#{game_id}/expansions")["expansion"].
    each { |g| g["id"] = g.delete("idExpansion") }
end
games() click to toggle source
# File lib/mkmapi/marketplace.rb, line 56
def games
  agent.get("games")["game"].
    each { |g| g["id"] = g.delete("idGame") }
end
priceguide(game_id = 1) click to toggle source
# File lib/mkmapi/marketplace.rb, line 7
def priceguide(game_id = 1)
  json_data = agent.get("priceguide", { "idGame" => game_id })

  if (json_data && json_data["priceguidefile"])
    data = Base64.decode64(json_data["priceguidefile"])
    gzip = Zlib::GzipReader.new(StringIO.new(data))

    keys = ["id", "average", "low", "trend", "german_low", "suggested", "foil", "foil_low", "foil_trend", "low_ex", "avg1", "avg7", "avg30", "foilavg1", "foilavg7", "foilavg30"]
    skip_first = gzip.readline # Skip the header

    CSV.parse(gzip.read).map do |a|
      item = keys.zip(a.map(&:to_f))
      item[0][1] = item[0][1].to_i

      Hash[item]
    end
  end
end
product(product_id) click to toggle source
# File lib/mkmapi/marketplace.rb, line 61
def product(product_id)
  agent.get("products/#{product_id}")["product"]
end
productlist() click to toggle source
# File lib/mkmapi/marketplace.rb, line 26
def productlist
  json_data = agent.get("productlist")

  if (json_data && json_data["productsfile"])
    data = Base64.decode64(json_data["productsfile"])
    gzip = Zlib::GzipReader.new(StringIO.new(data))

    keys = ["id", "name", "category_id", "category", "expansion_id", "date_added"]
    skip_first = gzip.readline # Skip the header

    CSV.parse(gzip.read).map do |a|
      item = keys.zip(a)
      item[0][1] = item[0][1].to_i
      item[2][1] = item[2][1].to_i
      item[4][1] = item[4][1].to_i
      item[5][1] = item[5][1].to_i
      Hash[item]
    end
  end
end
singles(expansion_id = 1) click to toggle source
# File lib/mkmapi/marketplace.rb, line 52
def singles(expansion_id = 1)
  agent.get("expansions/#{expansion_id}/singles")
end