class CompanionApi::Resources::Market
Attributes
profile[RW]
Public Class Methods
new(profile)
click to toggle source
# File lib/companion_api/resources/market.rb, line 6 def initialize(profile) @profile = profile end
Public Instance Methods
item_market_listings(item_id, hq: false)
click to toggle source
# File lib/companion_api/resources/market.rb, line 10 def item_market_listings(item_id, hq: false) endpoint = "/market/items/catalog/#{item_id}" endpoint += "/hq" if hq request_result(endpoint) end
market_listings_by_category(category_id)
click to toggle source
# File lib/companion_api/resources/market.rb, line 17 def market_listings_by_category(category_id) request_result("/market/items/category/#{category_id}") end
transaction_history(catalog_id)
click to toggle source
# File lib/companion_api/resources/market.rb, line 21 def transaction_history(catalog_id) request_result("/market/items/history/catalog/#{catalog_id}") end
Protected Instance Methods
request_result(endpoint)
click to toggle source
# File lib/companion_api/resources/market.rb, line 27 def request_result(endpoint) region = @profile.get('region') raise CompanionApi::Error, 'No region set in profile, login a character first' if region.blank? req = CompanionApi::Request.new( uri: region, endpoint: endpoint, token: @profile.get("token"), ) res = req.get! json = JSON.parse(res.body) raise CompanionApi::ApiError, 'got an error message from companion api' if json["error"].present? && json["error"]["code"].present? json end