class BlizzardApi::Wow::GenericDataEndpoint
Generic endpoint to support most data requests with minor configurations
Public Class Methods
new(region = nil, mode = :regular)
click to toggle source
@!macro regions
Calls superclass method
BlizzardApi::Wow::Request::new
# File lib/blizzard_api/wow/game_data/generic_data_endpoint.rb, line 12 def initialize(region = nil, mode = :regular) super region, mode endpoint_setup @ttl ||= CACHE_DAY end
Public Instance Methods
complete(**options)
click to toggle source
@!macro complete
# File lib/blizzard_api/wow/game_data/generic_data_endpoint.rb, line 40 def complete(**options) payload = [].tap do |complete_data| index_data = index(**options) threads = [] concurrency = options.key?(:concurrency) ? options[:concurrency].to_i : BlizzardApi.concurrency concurrency.times do threads << Thread.new do while index_data[@collection.to_sym].size.positive? item = index_data[@collection.to_sym].pop link = item.key?(:key) ? item[:key][:href] : item[:href] item_data = request link complete_data.push item_data end end end ThreadsWait.all_waits threads end payload.sort { |a, b| a[:id] <=> b[:id] } end
get(id, **options)
click to toggle source
Fetch all possible data for one of the items listed by the {#index} using its id
@param id [Integer] One of the IDs returned by the {#index} @!macro request_options
@!macro response
# File lib/blizzard_api/wow/game_data/generic_data_endpoint.rb, line 34 def get(id, **options) api_request "#{endpoint_uri}/#{id}", **default_options.merge(options) end
index(**options)
click to toggle source
Fetch a list of all resources available for this endpoint
@!macro request_options @!macro response
# File lib/blizzard_api/wow/game_data/generic_data_endpoint.rb, line 23 def index(**options) api_request "#{endpoint_uri}/index", **default_options.merge(options) end
Protected Instance Methods
default_options()
click to toggle source
# File lib/blizzard_api/wow/game_data/generic_data_endpoint.rb, line 72 def default_options { namespace: @namespace, ttl: @ttl } end
endpoint_setup()
click to toggle source
# File lib/blizzard_api/wow/game_data/generic_data_endpoint.rb, line 68 def endpoint_setup raise NotImplementedError, 'You must override this method to properly set up the endpoint' end
endpoint_uri(variant = nil, scope = :game_data)
click to toggle source
# File lib/blizzard_api/wow/game_data/generic_data_endpoint.rb, line 63 def endpoint_uri(variant = nil, scope = :game_data) endpoint = variant ? "#{@endpoint}-#{variant}" : @endpoint "#{base_url(scope)}/#{endpoint}" end