module GW2API

Public Class Methods

get(path, query_hash = {}) click to toggle source
# File lib/guilding-swiftly.rb, line 11
def self.get(path, query_hash = {})
  query_string = query_hash.length > 0 ? '?' + Rack::Utils.build_query(query_hash) : ''
  uri = URI::join(BASE_URI, path) + query_string
  response = Net::HTTP.get_response(uri)
  JSON.parse(response.body)
end
get_mats_value(api_key) click to toggle source
# File lib/guilding-swiftly.rb, line 18
def self.get_mats_value(api_key)
  bank_slots = get(
    'account/materials',
    {:access_token => api_key}
  ).select { |bank_slot| bank_slot['count'] > 0 }

  bank_slots.each_with_index.map do |bank_slot, i|
    STDOUT.write "#{i}/#{bank_slots.length} (#{(i.fdiv(bank_slots.length) * 100).round}%)\r"
    get_value(bank_slot['id']) * bank_slot['count']
  end
end
get_value(item_id) click to toggle source
# File lib/guilding-swiftly.rb, line 30
def self.get_value(item_id)
  if !item_id then
    puts "Missing entry."
    return Price.none
  end

  results = get("commerce/prices/#{item_id}")
  results['id'] ? Price.new(results["buys"]["unit_price"], results["sells"]["unit_price"]) : Price.none
end