class Inventory

Public Class Methods

add(item, credentials) click to toggle source
# File lib/minitest/game/inventory.rb, line 12
def add(item, credentials)
  url = NagaApiClient.BASE_URL + "inventory/add"
  options = { headers: { "Content-Type" => "application/x-www-form-urlencoded" } }
  options[:body] = "email=" + credentials[:email] + "&authentication_token=" + credentials[:authentication_token] + "&item_id=" + item.id.to_s
  response = HTTParty.post(url, options)
  handle_add(response.parsed_response, item, "backpack")
end
add_to_desk(item, credentials) click to toggle source
# File lib/minitest/game/inventory.rb, line 4
def add_to_desk(item, credentials)
  url = NagaApiClient.BASE_URL + "inventory/desk/add"
  options = { headers: { "Content-Type" => "application/x-www-form-urlencoded" } }
  options[:body] = "email=" + credentials[:email] + "&authentication_token=" + credentials[:authentication_token] + "&item_id=" + item.id.to_s
  response = HTTParty.post(url, options)
  handle_add(response.parsed_response, item, "desk")
end

Private Class Methods

handle_add(parsed_response, item, storage) click to toggle source
# File lib/minitest/game/inventory.rb, line 22
def handle_add(parsed_response, item, storage)
  if parsed_response["error"]
    STDERR.puts(("\nError: " + parsed_response["error"] + "\n\n").colorize(:red))
  elsif parsed_response["warning"] == "No desk space"
    say("You received a " + item.name.upcase + "!")
    say("But as you have no space on your desk, it's been added to your backpack instead.")
  else
    say("You received a " + item.name.upcase + " and added it to your " + storage + "!")
  end
end