Commit 45a7f99a authored by Francis's avatar Francis
Browse files

Merge branch 'WoWClassic' into 'master'

Support for wow classic endpoints

See merge request !10
parents 3aae5df6 86225ffd
Pipeline #79033214 passed with stages
in 4 minutes and 22 seconds
Please view this file on the master branch, otherwise it may be outdated
**Version 0.2.6**
* Added namespace `static-classic` for wow classic support.
* Some WoW endpoints now support the `classic: true` option.
**Version 0.2.5**
* Added two unreleased endpoints for character profile(`raid_progression` and `collections`).
* Added new WoW profile endpoints
......
PATH
remote: .
specs:
blizzard_api (0.2.5)
blizzard_api (0.2.6)
redis (~> 4.1, >= 4.1.0)
GEM
......
......@@ -83,13 +83,13 @@ module BlizzardApi
##
# Returns a valid namespace string for consuming the api endpoints
#
# @param [Symbol] scope Scope of the namespace to be used. *:dynamic* or *:static*
def endpoint_namespace(scope)
case scope
# @param [Hash] options A hash containing the namespace key
def endpoint_namespace(options)
case options[:namespace]
when :dynamic
"dynamic-#{region}"
when :static
"static-#{region}"
options.include?(:classic) ? "static-classic-#{region}" : "static-#{region}"
when :profile
"profile-#{region}"
else
......@@ -139,11 +139,14 @@ module BlizzardApi
def api_request(uri, query_string = {})
# List of request options
options_key = %i[ignore_cache ttl format access_token]
options_key = %i[ignore_cache ttl format access_token namespace classic]
# Separates request options from api fields and options. Any user-defined option will be treated as api field.
options = query_string.select { |k, _v| query_string.delete(k) || true if options_key.include? k }
# Namespace
query_string[:namespace] = endpoint_namespace(options) if options.include? :namespace
# In case uri already have query string parameters joins them with &
if query_string.size.positive?
query_string = URI.encode_www_form(query_string, false)
......
......@@ -2,5 +2,5 @@
module BlizzardApi
# Gem version
VERSION = '0.2.5'
VERSION = '0.2.6'
end
......@@ -68,7 +68,7 @@ module BlizzardApi
def endpoint_setup
@endpoint = 'achievement'
@namespace = endpoint_namespace :static
@namespace = :static
@collection = 'achievements'
@ttl = CACHE_TRIMESTER
end
......
......@@ -26,7 +26,7 @@ module BlizzardApi
def endpoint_setup
@endpoint = 'azerite-essence'
@namespace = endpoint_namespace :static
@namespace = :static
@collection = 'azerite_essences'
@ttl = CACHE_TRIMESTER
end
......
......@@ -14,7 +14,7 @@ module BlizzardApi
def endpoint_setup
@endpoint = 'connected-realm'
@namespace = endpoint_namespace :dynamic
@namespace = :dynamic
@collection = 'connected_realms'
@ttl = CACHE_TRIMESTER
end
......
......@@ -22,6 +22,7 @@ module BlizzardApi
# Fetch all creature families
#
# @!macro request_options
# @option options [Boolean] :classic If set to true, this method will call the classic version
#
# @!macro response
def families(options = {})
......@@ -34,6 +35,7 @@ module BlizzardApi
# @param id [Integer] Creature family id
#
# @!macro request_options
# @option options [Boolean] :classic If set to true, this method will call the classic version
#
# @!macro response
def family(id, options = {})
......@@ -46,6 +48,7 @@ module BlizzardApi
# @param id [Integer] Creature family id
#
# @!macro request_options
# @option options [Boolean] :classic If set to true, this method will call the classic version
#
# @!macro response
def family_media(id, options = {})
......@@ -56,6 +59,7 @@ module BlizzardApi
# Fetch all creature types
#
# @!macro request_options
# @option options [Boolean] :classic If set to true, this method will call the classic version
#
# @!macro response
def types(options = {})
......@@ -68,6 +72,7 @@ module BlizzardApi
# @param id [Integer] Creature type id
#
# @!macro request_options
# @option options [Boolean] :classic If set to true, this method will call the classic version
#
# @!macro response
def type(id, options = {})
......@@ -80,6 +85,7 @@ module BlizzardApi
# @param id [Integer] Creature type id
#
# @!macro request_options
# @option options [Boolean] :classic If set to true, this method will call the classic version
#
# @!macro response
def display_media(id, options = {})
......@@ -90,7 +96,7 @@ module BlizzardApi
def endpoint_setup
@endpoint = 'creature'
@namespace = endpoint_namespace :static
@namespace = :static
@collection = 'achievements'
@ttl = CACHE_TRIMESTER
end
......
......@@ -105,7 +105,7 @@ module BlizzardApi
guild = CGI.escape string_to_slug(guild)
url = "#{base_url(:game_data)}/guild/#{realm}/#{guild}"
url += "/#{variant}" if variant
api_request url, { ttl: CACHE_DAY, namespace: endpoint_namespace(:profile) }.merge(options)
api_request url, { ttl: CACHE_DAY, namespace: :profile }.merge(options)
end
end
end
......
......@@ -20,6 +20,7 @@ module BlizzardApi
# @param id [Integer] Border id
#
# @!macro request_options
# @option options [Boolean] :classic If set to true, this method will call the classic version
#
# @!macro response
def border_media(id, options = {})
......@@ -30,6 +31,7 @@ module BlizzardApi
# Return guild embelm assets by its id
#
# @param id [Integer] Emblem id
# @option options [Boolean] :classic If set to true, this method will call the classic version
#
# @!macro request_options
#
......@@ -42,7 +44,7 @@ module BlizzardApi
def endpoint_setup
@endpoint = 'guild-crest'
@namespace = endpoint_namespace(:static)
@namespace = :static
@ttl = CACHE_TRIMESTER
end
end
......
......@@ -33,6 +33,7 @@ module BlizzardApi
# @!macro request_options
# @option options [Boolean] :use_community_endpoint If set to true, this method will call the community endpoint
# instead of the data endpoint https://develop.battle.net/documentation/api-reference/world-of-warcraft-community-api
# @option options [Boolean] :classic If set to true, this method will call the classic version
#
# @!macro response
def get(id, options = {})
......@@ -58,6 +59,7 @@ module BlizzardApi
# @!macro request_options
# @option options [Boolean] :use_community_endpoint If set to true, this method will call the community endpoint
# instead of the data endpoint https://develop.battle.net/documentation/api-reference/world-of-warcraft-community-api
# @option options [Boolean] :classic If set to true, this method will call the classic version
#
# @!macro response
def classes(options = {})
......@@ -73,6 +75,7 @@ module BlizzardApi
#
# @param id [Integer] Item class id
# @!macro request_options
# @option options [Boolean] :classic If set to true, this method will call the classic version
#
# @!macro response
def class(id, options = {})
......@@ -85,6 +88,7 @@ module BlizzardApi
# @param id [Integer] Item class id
# @param subclass_id [Integer] Item subclass id
# @!macro request_options
# @option options [Boolean] :classic If set to true, this method will call the classic version
#
# @!macro response
def subclass(id, subclass_id, options = {})
......@@ -97,6 +101,7 @@ module BlizzardApi
# @param id [Integer] Item id
#
# @!macro request_options
# @option options [Boolean] :classic If set to true, this method will call the classic version
#
# @!macro response
def media(id, options = {})
......@@ -107,7 +112,7 @@ module BlizzardApi
def endpoint_setup
@endpoint = 'item'
@namespace = endpoint_namespace :static
@namespace = :static
@collection = 'items'
@ttl = CACHE_TRIMESTER
end
......
......@@ -28,7 +28,7 @@ module BlizzardApi
def endpoint_setup
@endpoint = 'mount'
@namespace = endpoint_namespace :static
@namespace = :static
@collection = 'mounts'
@ttl = CACHE_TRIMESTER
end
......
......@@ -88,7 +88,7 @@ module BlizzardApi
def endpoint_setup
@endpoint = 'mythic-keystone'
@namespace = endpoint_namespace :dynamic
@namespace = :dynamic
@collection = 'mythic-keystones'
@ttl = CACHE_TRIMESTER
end
......
......@@ -14,7 +14,7 @@ module BlizzardApi
def endpoint_setup
@endpoint = 'keystone-affix'
@namespace = endpoint_namespace :static
@namespace = :static
@collection = 'affixes'
@ttl = CACHE_TRIMESTER
end
......
......@@ -37,7 +37,7 @@ module BlizzardApi
private
def default_options(options)
{ ttl: CACHE_DAY, namespace: endpoint_namespace(:dynamic) }.merge options
{ ttl: CACHE_DAY, namespace: :dynamic }.merge options
end
def endpoint_uri(connected_realm_id)
......
......@@ -20,7 +20,7 @@ module BlizzardApi
#
# @!macro response
def get(raid, faction, options = {})
opts = options.merge(namespace: endpoint_namespace(:dynamic), ttl: CACHE_DAY)
opts = options.merge(namespace: :dynamic, ttl: CACHE_DAY)
api_request "#{base_url(:game_data)}/leaderboard/hall-of-fame/#{raid}/#{faction}", opts
end
end
......
......@@ -89,7 +89,7 @@ module BlizzardApi
def endpoint_setup
@endpoint = 'pet'
@namespace = endpoint_namespace :static
@namespace = :static
@collection = 'pets'
@ttl = CACHE_TRIMESTER
end
......
......@@ -16,6 +16,7 @@ module BlizzardApi
# @!macro request_options
# @option options [Boolean] :use_community_endpoint If set to true, this method will call the community endpoint
# instead of the data endpoint https://develop.battle.net/documentation/api-reference/world-of-warcraft-community-api
# @option options [Boolean] :classic If set to true, this method will call the classic version
#
# @!macro response
def index(options = {})
......@@ -37,6 +38,8 @@ module BlizzardApi
##
# @!macro complete
#
# @option options [Boolean] :classic If set to true, this method will call the classic version
def complete(options = {})
index_data = index options
[].tap do |classes|
......@@ -54,6 +57,7 @@ module BlizzardApi
# @param id [Integer] Playable class id
#
# @!macro request_options
# @option options [Boolean] :classic If set to true, this method will call the classic version
#
# @!macro response
def get(id, options = {})
......@@ -66,12 +70,14 @@ module BlizzardApi
def endpoint_setup
@endpoint = 'playable-class'
@namespace = endpoint_namespace :static
@namespace = :static
@collection = 'classes'
@ttl = CACHE_TRIMESTER
end
def get_class_icon(media_url, options)
return if options.include? :classic
media_data = request media_url[:key][:href], options
%r{56/([a-z_]+).jpg}.match(media_data[:assets][0][:value].to_s)[1]
end
......
......@@ -24,7 +24,7 @@ module BlizzardApi
def endpoint_setup
@endpoint = 'playable-specialization'
@namespace = endpoint_namespace :static
@namespace = :static
@collection = 'playable_specialization'
@ttl = CACHE_TRIMESTER
end
......
......@@ -14,7 +14,7 @@ module BlizzardApi
def endpoint_setup
@endpoint = 'power-type'
@namespace = endpoint_namespace :static
@namespace = :static
@collection = 'power_types'
@ttl = CACHE_TRIMESTER
end
......
......@@ -44,7 +44,7 @@ module BlizzardApi
def endpoint_setup
@endpoint = 'pvp-season'
@namespace = endpoint_namespace :dynamic
@namespace = :dynamic
@collection = 'power_types'
@ttl = CACHE_TRIMESTER
end
......
......@@ -24,7 +24,7 @@ module BlizzardApi
def endpoint_setup
@endpoint = 'pvp-tier'
@namespace = endpoint_namespace :static
@namespace = :static
@collection = 'tiers'
@ttl = CACHE_TRIMESTER
end
......
......@@ -16,6 +16,7 @@ module BlizzardApi
# @!macro request_options
# @option options [Boolean] :use_community_endpoint If set to true, this method will call the community endpoint
# instead of the data endpoint https://develop.battle.net/documentation/api-reference/world-of-warcraft-community-api
# @option options [Boolean] :classic If set to true, this method will call the classic version
#
# @!macro response
def index(options = {})
......@@ -28,7 +29,7 @@ module BlizzardApi
def endpoint_setup
@endpoint = 'playable-race'
@namespace = endpoint_namespace :static
@namespace = :static
@collection = 'races'
@ttl = CACHE_TRIMESTER
end
......
......@@ -27,7 +27,7 @@ module BlizzardApi
def endpoint_setup
@endpoint = 'realm'
@namespace = endpoint_namespace :dynamic
@namespace = :dynamic
@collection = 'realms'
@ttl = CACHE_TRIMESTER
end
......
......@@ -27,7 +27,7 @@ module BlizzardApi
def endpoint_setup
@endpoint = 'region'
@namespace = endpoint_namespace :dynamic
@namespace = :dynamic
@collection = 'regions'
@ttl = CACHE_TRIMESTER
end
......
......@@ -22,7 +22,7 @@ module BlizzardApi
def endpoint_setup
@endpoint = 'title'
@namespace = endpoint_namespace :static
@namespace = :static
@collection = 'titles'
@ttl = CACHE_TRIMESTER
end
......
......@@ -17,7 +17,7 @@ module BlizzardApi
#
# @!macro response
def get(options = {})
opts = { namespace: endpoint_namespace(:dynamic), ttl: CACHE_HOUR }.merge(options)
opts = { namespace: :dynamic, ttl: CACHE_HOUR }.merge(options)
api_request "#{base_url(:game_data)}/token/index", opts
end
end
......
......@@ -274,7 +274,7 @@ module BlizzardApi
private
def default_options(user_token = nil)
opts = { ttl: CACHE_HOUR, namespace: endpoint_namespace(:profile) }
opts = { ttl: CACHE_HOUR, namespace: :profile }
opts.merge access_token: user_token if user_token
opts
end
......
......@@ -12,38 +12,61 @@ module BlizzardApi
def test_creature_get
creature_data = @mythic_keystone_leaderboard.get 42_722
assert_equal 'Young Mastiff', creature_data[:name][:en_US]
creature_data = @mythic_keystone_leaderboard.get 107, classic: true
assert_equal 'Raptor', creature_data[:name][:en_US]
end
def test_creature_families
creature_families_data = @mythic_keystone_leaderboard.families
assert_equal 78, creature_families_data[:creature_families].count
creature_families_data = @mythic_keystone_leaderboard.families classic: true
assert_equal 23, creature_families_data[:creature_families].count
end
def test_creature_family
creature_family_data = @mythic_keystone_leaderboard.family 1
assert_equal 'Wolf', creature_family_data[:name][:en_US]
creature_family_data = @mythic_keystone_leaderboard.family 1, classic: true
assert_equal 'Wolf', creature_family_data[:name][:en_US]
end
def test_creature_family_media
creature_family_media_data = @mythic_keystone_leaderboard.family_media 1
assert_equal 'https://render-us.worldofwarcraft.com/icons/56/ability_hunter_pet_wolf.jpg',
creature_family_media_data[:assets][0][:value]
creature_family_media_data = @mythic_keystone_leaderboard.family_media 1, classic: true
assert_equal 'https://render-classic-us.worldofwarcraft.com/icons/56/ability_hunter_pet_wolf.jpg',
creature_family_media_data[:assets][0][:value]
end
def test_creature_types
creature_types_data = @mythic_keystone_leaderboard.types
assert_equal 15, creature_types_data[:creature_types].count
creature_types_data = @mythic_keystone_leaderboard.types classic: true
assert_equal 11, creature_types_data[:creature_types].count
end
def test_creature_type
creature_type_data = @mythic_keystone_leaderboard.type 1
assert_equal 'Beast', creature_type_data[:name][:en_US]
creature_type_data = @mythic_keystone_leaderboard.type 1, classic: true
assert_equal 'Beast', creature_type_data[:name][:en_US]
end
def test_creature_display_media
creature_display_media_data = @mythic_keystone_leaderboard.display_media 30_221
assert_equal 'https://render-us.worldofwarcraft.com/npcs/portrait/creature-display-30221.jpg',
creature_display_media_data[:assets][0][:value]
creature_display_media_data = @mythic_keystone_leaderboard.display_media 180, classic: true
assert_equal 'https://render-classic-us.worldofwarcraft.com/npcs/portrait/creature-display-180.jpg',
creature_display_media_data[:assets][0][:value]
end
end
end
......
......@@ -13,18 +13,29 @@ module BlizzardApi
guild_crest_data = @guild_crest.index
assert_equal 6, guild_crest_data[:borders].count
assert_equal 196, guild_crest_data[:emblems].count
guild_crest_data = @guild_crest.index classic: true
assert_equal 6, guild_crest_data[:borders].count
end
def test_guild_crest_border
guild_crest_data = @guild_crest.border_media 0
assert_equal 'https://us.battle.net/wow/static/images/guild/tabards/border_00.png',
guild_crest_data[:assets][0][:value]
guild_crest_data = @guild_crest.border_media 0, classic: true
assert_equal 'https://render-classic-us.worldofwarcraft.com/guild/tabards/border_00.png',
guild_crest_data[:assets][0][:value]
end
def test_guild_crest_emblem
guild_crest_data = @guild_crest.emblem_media 0
assert_equal 'https://us.battle.net/wow/static/images/guild/tabards/emblem_00.png',
guild_crest_data[:assets][0][:value]
guild_crest_data = @guild_crest.emblem_media 0, classic: true
assert_equal 'https://render-classic-us.worldofwarcraft.com/guild/tabards/emblem_00.png',
guild_crest_data[:assets][0][:value]
end
end
end
......
......@@ -13,6 +13,9 @@ module BlizzardApi
item_data = @item.get 35_000
assert_equal 'Brutal Gladiator\'s Dragonhide Legguards', item_data[:name][:en_US]
item_data = @item.get 25, classic: true
assert_equal 'Worn Shortsword', item_data[:name][:en_US]
item_data = @item.get 18_803, use_community_endpoint: true
assert_equal 'inv_gizmo_02', item_data[:icon]
end
......@@ -26,6 +29,9 @@ module BlizzardApi
item_data = @item.classes
assert_equal 17, item_data[:item_classes].count
item_data = @item.classes classic: true
assert_equal 12, item_data[:item_classes].count
item_data = @item.classes use_community_endpoint: true
assert_equal 16, item_data[:classes].count
end
......@@ -33,16 +39,25 @@ module BlizzardApi
def test_item_class
item_data = @item.class 1
assert_equal 11, item_data[:item_subclasses].count
item_data = @item.class 1, classic: true
assert_equal 5, item_data[:item_subclasses].count
end
def test_subclass
item_data = @item.subclass 1, 1
assert_equal 'Soul Bag', item_data[:display_name][:en_US]
item_data = @item.subclass 1, 1, classic: true
assert_equal 'Soul Bag', item_data[:display_name][:en_US]
end
def test_item_media
item_data = @item.media 35_000
assert item_data.key? :assets
item_data = @item.media 25, classic: true
assert item_data.key? :assets
end
end
end
......
......@@ -11,7 +11,7 @@ module BlizzardApi
def test_mount_index
mount_data = @mount.index
assert_equal 767, mount_data[:mounts].count
assert_equal 770, mount_data[:mounts].count
mount_data = @mount.index use_community_endpoint: true
assert_equal 919, mount_data[:mounts].count
......
......@@ -27,7 +27,7 @@ module BlizzardApi
def test_mythic_keystone_periods
mythic_keystone_periods = @mythic_keystone_leaderboard.periods
assert_equal 66, mythic_keystone_periods[:periods].count