Class: Mkmapi::Marketplace
- Inherits:
-
Struct
- Object
- Struct
- Mkmapi::Marketplace
- Defined in:
- lib/mkmapi/marketplace.rb
Instance Attribute Summary collapse
-
#agent ⇒ Object
Returns the value of attribute agent.
Instance Method Summary collapse
- #card_by_name(name, game_id = 1, language_id = 1) ⇒ Object
- #expansions(game_id = 1) ⇒ Object
- #games ⇒ Object
- #priceguide ⇒ Object
- #productlist ⇒ Object
- #search(name, game_id = 1, language_id = 1) ⇒ Object
- #singles(expansion_id = 1) ⇒ Object
Instance Attribute Details
#agent ⇒ Object
Returns the value of attribute agent
6 7 8 |
# File 'lib/mkmapi/marketplace.rb', line 6 def agent @agent end |
Instance Method Details
#card_by_name(name, game_id = 1, language_id = 1) ⇒ Object
62 63 64 |
# File 'lib/mkmapi/marketplace.rb', line 62 def card_by_name(name, game_id = 1, language_id = 1) product(name, game_id, language_id, true) end |
#expansions(game_id = 1) ⇒ Object
48 49 50 51 |
# File 'lib/mkmapi/marketplace.rb', line 48 def expansions(game_id = 1) agent.get("games/#{game_id}/expansions")['expansion']. each {|g| g['id'] = g.delete('idExpansion') } end |
#games ⇒ Object
57 58 59 60 |
# File 'lib/mkmapi/marketplace.rb', line 57 def games agent.get("games")['game']. each {|g| g['id'] = g.delete('idGame') } end |
#priceguide ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/mkmapi/marketplace.rb', line 8 def priceguide json_data = agent.get("priceguide") if (json_data && json_data["priceguidefile"]) data = Base64.decode64(json_data["priceguidefile"]) gzip = Zlib::GzipReader.new(StringIO.new(data)) keys = ['id', 'average', 'low', 'trend', 'suggested', 'foil', 'foil_low', 'foil_trend' ] 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 |
#productlist ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/mkmapi/marketplace.rb', line 27 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', 'metacard_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 |
#search(name, game_id = 1, language_id = 1) ⇒ Object
66 67 68 |
# File 'lib/mkmapi/marketplace.rb', line 66 def search(name, game_id = 1, language_id = 1) product(name, game_id, language_id, false) end |
#singles(expansion_id = 1) ⇒ Object
53 54 55 |
# File 'lib/mkmapi/marketplace.rb', line 53 def singles(expansion_id = 1) agent.get("expansions/#{expansion_id}/singles") end |