Commit 186f7dfe authored by Francis's avatar Francis
Browse files

Hearthstone update

parent a919ac03
Pipeline #110334354 passed with stage
in 4 minutes and 42 seconds
......@@ -6,7 +6,7 @@ stages:
test:
stage: test
script:
- gem install bundler -v 1.17.3
- gem install bundler -v 2.1.2
- bundle install
- rubocop
- rake
\ No newline at end of file
Please view this file on the master branch, otherwise it may be outdated
**Version 0.3.1**
https://us.forums.blizzard.com/en/blizzard/t/hearthstone-api-updates/2978
Hearthstone updates:
* Added the new Cardback endpoint
* Card endpoint now supports the new `gameMode` search option
**Version 0.3.0**
https://us.forums.blizzard.com/en/blizzard/t/starcraft-ii-community-api-update/2652
......
PATH
remote: .
specs:
blizzard_api (0.3.0)
blizzard_api (0.3.1)
redis (~> 4.1, >= 4.1.0)
GEM
......@@ -15,7 +15,7 @@ GEM
ast (~> 2.4.0)
rainbow (3.0.0)
rake (10.5.0)
redis (4.1.2)
redis (4.1.3)
rubocop (0.74.0)
jaro_winkler (~> 1.5.1)
parallel (~> 1.10)
......@@ -36,4 +36,4 @@ DEPENDENCIES
rubocop (~> 0.61)
BUNDLED WITH
1.17.3
2.1.2
......@@ -8,6 +8,7 @@ module BlizzardApi
# Hearthstone data api
require_relative 'hearthstone/game_data/card'
require_relative 'hearthstone/game_data/back'
require_relative 'hearthstone/game_data/deck'
require_relative 'hearthstone/game_data/metadata'
......@@ -17,6 +18,12 @@ module BlizzardApi
BlizzardApi::Hearthstone::Card.new
end
##
# @return {Back}
def self.back
BlizzardApi::Hearthstone::Back.new
end
##
# @return {Deck}
def self.deck
......
# frozen_string_literal: true
module BlizzardApi
module Hearthstone
##
# This class allows access to Hearthstone card data
#
# @see https://develop.battle.net/documentation/api-reference/hearthstone-game-data-api
# @see https://develop.battle.net/documentation/hearthstone/guides/card-backs
#
# You can get an instance of this class using the default region as follows:
# api_instance = BlizzardApi::Hearthstone.card
class Back < Hearthstone::GenericDataEndpoint
# Valid options for card search
VALID_SEARCH_OPTIONS = %i[
cardBackCategory
textFilter
sort
order
].freeze
##
# Returns an up-to-date list of all card backs matching the search criteria. For more information about the
# search parameters, see the Card Backs Guide.
#
# @param search_options [Hash] Search options accepted by the endpoint
# @option search_options [String] :cardBackCategory A category of the card back. The category must match a valid category.
# @option search_options [String] :textFilter A text string used to filter cards.
# You must include a locale along with the textFilter parameter.
# @option search_options [String] :sort The field used to sort the results. Valid value include name.
# Results are sorted by date (desc) by default.
# @option search_options [String] :order The order in which to sort the results.
# Valid values are asc or desc. The default value is asc.
# @!macro request_options
# @option options [Boolean] :validate_fields If set to true, this method will throw an exception if nay search
# option is invalid
#
# @!macro response
def search(search_options = {}, options = {})
validate_search_options search_options if options.include? :validate_fields
api_request "#{base_url(:community)}/cardbacks", default_options.merge(options).merge(search_options)
end
protected
def validate_search_options(search_options)
search_options.each do |field|
raise ArgumentError, "Unrecognized search option #{field}" unless VALID_SEARCH_OPTIONS.include? field
end
end
def endpoint_setup
@endpoint = 'cardbacks'
@ttl = CACHE_TRIMESTER
end
end
end
end
......@@ -6,6 +6,7 @@ module BlizzardApi
# This class allows access to Hearthstone card data
#
# @see https://develop.battle.net/documentation/api-reference/hearthstone-game-data-api
# @see https://develop.battle.net/documentation/hearthstone/guides/card-search
#
# You can get an instance of this class using the default region as follows:
# api_instance = BlizzardApi::Hearthstone.card
......@@ -23,6 +24,7 @@ module BlizzardApi
minionType
keyword
textFilter
gameMode
page
pageSize
sort
......@@ -55,6 +57,8 @@ module BlizzardApi
# and so on). This value must match the keyword slugs found in metadata.
# @option search_options [String] :textFilter A text string used to filter cards.
# You must include a locale along with the textFilter parameter.
# @option search_options [String] :gameMode A recognized game mode (for example, battlegrounds or constructed).
# The default value is constructed. See the Game Modes Guide for more information.
# @option search_options [Integer] :page A page number.
# @option search_options [Integer] :pageSize The number of results to choose per page.
# A value will be selected automatically if you do not supply a pageSize or if the pageSize is higher than the
......@@ -74,6 +78,22 @@ module BlizzardApi
api_request "#{base_url(:community)}/cards", default_options.merge(options).merge(search_options)
end
##
# Returns the card with an ID or slug that matches the one you specify. For more information, see the Card Search Guide.
#
# @see https://develop.battle.net/documentation/hearthstone/guides/card-search
# @see https://develop.battle.net/documentation/hearthstone/guides/game-modes
#
# @param id_or_slug [String] Card ID or slug
# @param game_mode [String] A recognized game mode (for example, battlegrounds or constructed).
# The default value is constructed. See the Game Modes Guide for more information.
# @!macro request_options
#
# @!macro response
def get(id_or_slug, game_mode = 'constructed', options = {})
super id_or_slug, { gameMode: game_mode }.merge(options)
end
protected
def validate_search_options(search_options)
......
......@@ -6,6 +6,7 @@ module BlizzardApi
# This class allows access to Hearthstone deck data
#
# @see https://develop.battle.net/documentation/api-reference/hearthstone-game-data-api
# @see https://develop.battle.net/documentation/hearthstone/guides/decks
#
# You can get an instance of this class using the default region as follows:
# api_instance = BlizzardApi::Hearthstone.deck
......
......@@ -27,7 +27,7 @@ module BlizzardApi
##
# Fetch all possible data for one of items listed by the {#index} using its *id*
#
# @param [Integer] id One of the IDs returned by the {#index}
# @param [Integer|String] id One of the IDs returned by the {#index}
# @!macro request_options
#
# @!macro response
......
......@@ -6,6 +6,7 @@ module BlizzardApi
# This class allows access to Hearthstone metadata data
#
# @see https://develop.battle.net/documentation/api-reference/hearthstone-game-data-api
# https://develop.battle.net/documentation/hearthstone/guides/metadata
#
# You can get an instance of this class using the default region as follows:
# api_instance = BlizzardApi::Hearthstone.metadata
......
......@@ -2,5 +2,5 @@
module BlizzardApi
# Gem version
VERSION = '0.3.0'
VERSION = '0.3.1'
end
# frozen_string_literal: true
require 'test_helper'
module BlizzardApi
module Hearthstone
class BackTest < Minitest::Test
def test_back_index
back = BlizzardApi::Hearthstone::Back.new
back_data = back.index
assert back_data[:cardBacks]
end
def test_back_get
back = BlizzardApi::Hearthstone::Back.new
back_data = back.get 1
assert back_data[:slug]
end
end
end
end
......@@ -8,7 +8,7 @@ module BlizzardApi
def test_achievement_index
achievement = BlizzardApi::Wow::Achievement.new
achievement_data = achievement.index
assert_equal 5034, achievement_data[:achievements].count
assert_equal 5131, achievement_data[:achievements].count
end
def test_achievement_get
......@@ -31,7 +31,7 @@ module BlizzardApi
achievement = BlizzardApi::Wow::Achievement.new
achievement_categories_data = achievement.categories
assert_equal 14, achievement_categories_data[:root_categories].count
assert_equal 113, achievement_categories_data[:categories].count
assert_equal 115, achievement_categories_data[:categories].count
assert_equal 24, achievement_categories_data[:guild_categories].count
end
......@@ -39,7 +39,7 @@ module BlizzardApi
achievement = BlizzardApi::Wow::Achievement.new
achievement_categories_data = achievement.category 81
assert_equal 'Feats of Strength', achievement_categories_data[:name][:en_US]
assert_equal 108, achievement_categories_data[:achievements].count
assert_equal 109, achievement_categories_data[:achievements].count
end
def test_achievement_media
......
......@@ -11,7 +11,7 @@ module BlizzardApi
def test_azerite_essence_index
title_data = @azerite_essence.index
assert_equal 21, title_data[:azerite_essences].count
assert_equal 28, title_data[:azerite_essences].count
end
def test_azerite_essence_get
......
......@@ -61,7 +61,7 @@ module BlizzardApi
def test_creature_display_media
creature_display_media_data = @creature.display_media 30_221
assert_equal 'https://render-us.worldofwarcraft.com/npcs/portrait/creature-display-30221.jpg',
assert_equal 'https://render-us.worldofwarcraft.com/npcs/zoom/creature-display-30221.jpg',
creature_display_media_data[:assets][0][:value]
creature_display_media_data = @creature.display_media 180, classic: true
......
......@@ -20,7 +20,7 @@ module BlizzardApi
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',
assert_equal 'https://render-us.worldofwarcraft.com/guild/tabards/border_00.png',
guild_crest_data[:assets][0][:value]
guild_crest_data = @guild_crest.border_media 0, classic: true
......@@ -30,7 +30,7 @@ module BlizzardApi
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',
assert_equal 'https://render-us.worldofwarcraft.com/guild/tabards/emblem_00.png',
guild_crest_data[:assets][0][:value]
guild_crest_data = @guild_crest.emblem_media 0, classic: true
......
......@@ -11,10 +11,10 @@ module BlizzardApi
def test_mount_index
mount_data = @mount.index
assert_equal 778, mount_data[:mounts].count
assert_equal 805, mount_data[:mounts].count
mount_data = @mount.index use_community_endpoint: true
assert_equal 930, mount_data[:mounts].count
assert_equal 952, mount_data[:mounts].count
end
def test_mount_get
......
......@@ -11,7 +11,7 @@ module BlizzardApi
def test_mythic_keystone_dungeons
mythic_keystone_leaderboard_data = @mythic_keystone_leaderboard.index 11
assert_equal 10, mythic_keystone_leaderboard_data[:current_leaderboards].count
assert_equal 12, mythic_keystone_leaderboard_data[:current_leaderboards].count
end
def test_mythic_keystone_dungeon
......
......@@ -27,7 +27,7 @@ module BlizzardApi
def test_mythic_keystone_periods
mythic_keystone_periods = @mythic_keystone_leaderboard.periods
assert_equal 92, mythic_keystone_periods[:periods].count
assert_equal 93, mythic_keystone_periods[:periods].count
end
def test_mythic_keystone_period
......@@ -37,7 +37,7 @@ module BlizzardApi
def test_mythic_keystone_seasons
mythic_keystone_seasons_data = @mythic_keystone_leaderboard.seasons
assert_equal 4, mythic_keystone_seasons_data[:seasons].count
assert_equal 5, mythic_keystone_seasons_data[:seasons].count
end
def test_mythic_keystone_season
......
......@@ -11,10 +11,10 @@ module BlizzardApi
def test_pet_index
pet_data = @pet.index
assert_equal 1248, pet_data[:pets].count
assert_equal 1280, pet_data[:pets].count
pet_data = @pet.index use_community_endpoint: true
assert_equal 1244, pet_data[:pets].count
assert_equal 1280, pet_data[:pets].count
end
def test_pet_get
......
......@@ -8,10 +8,10 @@ module BlizzardApi
def test_race_index
race = BlizzardApi::Wow::Race.new
race_data = race.index
assert_equal 23, race_data[:races].count
assert_equal 25, race_data[:races].count
race_data = race.index
assert_equal 23, race_data[:races].count
assert_equal 25, race_data[:races].count
end
def test_race_get
......
......@@ -11,7 +11,7 @@ module BlizzardApi
def test_reputation_tier_index
reputation_data = @reputation.index
assert_equal 196, reputation_data[:factions].count
assert_equal 199, reputation_data[:factions].count
end
def test_reputation_tier_get
......
......@@ -11,7 +11,7 @@ module BlizzardApi
def test_title_index
title_data = @title.index
assert_equal 368, title_data[:titles].count
assert_equal 375, title_data[:titles].count
end
def test_title_get
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment