Commit 78420087 authored by Francis's avatar Francis
Browse files

Merge branch 'CharacterProfile' into 'master'

Added WoW profile endpoints and HS cards search method

Closes #2

See merge request !4
parents 67a5aab5 2a15a25d
Please view this file on the master branch, otherwise it may be outdated
**Version 0.2.4**
* Added new WoW profile endpoints: #2 https://us.battle.net/forums/en/bnet/topic/20772457051
* Added support for HearthStone: !1 (Thanks Bradyn Glines for implementing this)
**Version 0.2.3**
* Added new api endpoints listed here: https://us.battle.net/forums/en/bnet/topic/20772337044
......
......@@ -10,8 +10,78 @@ module BlizzardApi
# You can get an instance of this class using the default region as follows:
# api_instance = BlizzardApi::Hearthstone.card
class Card < Hearthstone::GenericDataEndpoint
# Valid options for card search
VALID_SEARCH_OPTIONS = %i[
set
class
manaCost
attack
health
collectible
rarity
type
minionType
keyword
textFilter
page
pageSize
sort
order
].freeze
##
# Fetch all possible data for one of the items listed by the {#index} using its *id*
#
# @param search_options [Hash] Search options accepted by the endpoint
# @option search_options [String] :set The slug of the set the card belongs to.
# If you do not supply a value cards from all sets will be returned.
# @option search_options [String] :class The slug of the card's class.
# @option search_options [Integer] :manaCost The mana cost required to play the card.
# You can include multiple values in a comma-separated list of numeric values.
# @option search_options [Integer] :attack The attack power of the minion or weapon.
# You can include multiple values in a comma-separated list of numeric values.
# @option search_options [Integer] :health The health of a minion.
# You can include multiple values in a comma-separated list of numeric values.
# @option search_options [Float] :collectible Whether a card is collectible.
# A value of 1 indicates that collectible cards should be returned; 0 indicates uncollectible cards.
# To return all cards, use a value of '0,1'.
# @option search_options [String] :rarity The rarity of a card.
# This value must match the rarity slugs found in metadata.
# @option search_options [String] :type The type of card (for example, minion, spell, and so on).
# This value must match the type slugs found in metadata.
# @option search_options [String] :minionType The type of minion card (for example, beast, murloc, dragon, and
# so on). This value must match the minion type slugs found in metadata.
# @option search_options [String] :keyword A required keyword on the card (for example, battlecry, deathrattle,
# 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 [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
# maximum allowed. @option search_options [String] :sort The field used to sort the results.
# Valid values include manaCost, attack, health, and name. Results are sorted by manaCost by default.
# Cards will also be sorted by class automatically in most cases.
# @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)}/cards", 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 = 'cards'
@ttl = CACHE_TRIMESTER
......
......@@ -9,15 +9,9 @@ module BlizzardApi
#
# You can get an instance of this class using the default region as follows:
# api_instance = BlizzardApi::Hearthstone.deck
class Deck < Hearthstone::Request
def initialize(region = nil)
super region
endpoint_setup
@ttl ||= CACHE_DAY
end
def get(deck_code, options = {})
api_request "#{base_url(:community)}/#{@endpoint}/#{deck_code}", default_options.merge(options)
class Deck < Hearthstone::GenericDataEndpoint
def index
raise ApiException, 'This endpoint does not have a index method'
end
protected
......
......@@ -11,62 +11,168 @@ module BlizzardApi
# api_instance = BlizzardApi::Wow.achievement
class CharacterProfile < Wow::Request
##
# Return the mythic keystone profile of a character
# Return character achievements
#
# @note This endpoint requires a user token obtained through the user authorization flow
# @see https://develop.battle.net/documentation/guides/using-oauth/authorization-code-flow
# @see https://develop.battle.net/documentation/api-reference/world-of-warcraft-profile-api
#
# @param realm [String] The character realm's slug
# @param character [String] The character name
# @param user_token [String] A token obtained by the authorization flow. See link below.
# @param season [Integer] Season ID if you want only a specific season or nil to include all.
# @!macro request_options
#
# @!macro response
def get_keystone_profile(realm, character, user_token, season = nil, options = {})
url = "#{endpoint_uri(realm, character)}/mythic-keystone-profile"
url += "/season/#{season}" unless season.nil?
api_request url, default_options(user_token).merge(options)
def achievements(realm, character, options = {})
api_request "#{endpoint_uri(realm, character)}/achievements", default_options.merge(options)
end
##
# Return the pvp summary of a character
# Return character appearance
#
# @see https://develop.battle.net/documentation/api-reference/world-of-warcraft-profile-api
#
# @param realm [String] The character realm's slug
# @param character [String] The character name
# @!macro request_options
#
# @!macro response
def appearance(realm, character, options = {})
api_request "#{endpoint_uri(realm, character)}/appearance", default_options.merge(options)
end
##
# Return character equipment
#
# @see https://develop.battle.net/documentation/api-reference/world-of-warcraft-profile-api
#
# @param realm [String] The character realm's slug
# @param character [String] The character name
# @!macro request_options
#
# @!macro response
def equipment(realm, character, options = {})
api_request "#{endpoint_uri(realm, character)}/equipment", default_options.merge(options)
end
##
# Return character media
#
# @note This endpoint requires a user token obtained through the user authorization flow
# @see https://develop.battle.net/documentation/guides/using-oauth/authorization-code-flow
# @see https://develop.battle.net/documentation/api-reference/world-of-warcraft-profile-api
#
# @param realm [String] The character realm's slug
# @param character [String] The character name
# @param user_token [String] A token obtained by the authorization flow. See link below.
# @!macro request_options
#
# @!macro response
def pvp_summmary(realm, character, user_token, options = {})
api_request "#{endpoint_uri(realm, character)}/pvp-summary", default_options(user_token).merge(options)
def media(realm, character, options = {})
api_request "#{endpoint_uri(realm, character)}/character-media", default_options.merge(options)
end
##
# Return the pvp bracket of a character
#
# @note This endpoint requires a user token obtained through the user authorization flow
# @see https://develop.battle.net/documentation/guides/using-oauth/authorization-code-flow
# @see https://develop.battle.net/documentation/api-reference/world-of-warcraft-profile-api
#
# @param realm [String] The character realm's slug
# @param character [String] The character name
# @param bracket [String] Pvp bracket
# @param user_token [String] A token obtained by the authorization flow. See link below.
# @!macro request_options
#
# @!macro response
def pvp_bracket(realm, character, bracket, user_token, options = {})
api_request "#{endpoint_uri(realm, character)}/pvp-bracket/#{bracket}",
default_options(user_token).merge(options)
def pvp_bracket(realm, character, bracket, options = {})
api_request "#{endpoint_uri(realm, character)}/pvp-bracket/#{bracket}", default_options.merge(options)
end
##
# Return the pvp summary of a character
#
# @see https://develop.battle.net/documentation/api-reference/world-of-warcraft-profile-api
#
# @param realm [String] The character realm's slug
# @param character [String] The character name
# @!macro request_options
#
# @!macro response
def pvp_summary(realm, character, options = {})
api_request "#{endpoint_uri(realm, character)}/pvp-summary", default_options.merge(options)
end
##
# Return a character's specialization
#
# @see https://develop.battle.net/documentation/api-reference/world-of-warcraft-profile-api
#
# @param realm [String] The character realm's slug
# @param character [String] The character name
# @!macro request_options
#
# @!macro response
def specializations(realm, character, options = {})
api_request "#{endpoint_uri(realm, character)}/specializations", default_options.merge(options)
end
##
# Return a character's statistics
#
# @see https://develop.battle.net/documentation/api-reference/world-of-warcraft-profile-api
#
# @param realm [String] The character realm's slug
# @param character [String] The character name
# @!macro request_options
#
# @!macro response
def statistics(realm, character, options = {})
api_request "#{endpoint_uri(realm, character)}/statistics", default_options.merge(options)
end
##
# Return a character's titles
#
# @see https://develop.battle.net/documentation/api-reference/world-of-warcraft-profile-api
#
# @param realm [String] The character realm's slug
# @param character [String] The character name
# @!macro request_options
#
# @!macro response
def titles(realm, character, options = {})
api_request "#{endpoint_uri(realm, character)}/titles", default_options.merge(options)
end
##
# Return the mythic keystone profile of a character
#
# @see https://develop.battle.net/documentation/api-reference/world-of-warcraft-profile-api
#
# @param realm [String] The character realm's slug
# @param character [String] The character name
# @!macro request_options
#
# @!macro response
def keystone_profile(realm, character, options = {})
api_request "#{endpoint_uri(realm, character)}/mythic-keystone-profile", default_options.merge(options)
end
##
# Return the mythic keystone profile of a character
#
# @see https://develop.battle.net/documentation/api-reference/world-of-warcraft-profile-api
#
# @param realm [String] The character realm's slug
# @param character [String] The character name
# @param season [Integer] Season ID if you want only a specific season or nil to include all.
# @!macro request_options
#
# @!macro response
def keystone_season_details(realm, character, season = nil, options = {})
api_request api_request "#{endpoint_uri(realm, character)}/mythic-keystone-profile/season/#{season}",
default_options.merge(options)
end
private
def default_options(user_token)
{ ttl: CACHE_HOUR, namespace: endpoint_namespace(:profile), access_token: user_token }
def default_options(user_token = nil)
opts = { ttl: CACHE_HOUR, namespace: endpoint_namespace(:profile) }
opts.merge access_token: user_token if user_token
opts
end
def endpoint_uri(realm, character)
......
......@@ -13,8 +13,19 @@ module BlizzardApi
def test_card_get
card = BlizzardApi::Hearthstone::Card.new
card_data = card.get 254
assert card_data[:slug]
card_data = card.index
assert card_data[:cards]
end
def test_card_search
search_options = { set: 'rise-of-shadows', class: 'mage', mana_cost: 10, attack: 4, health: 10, collectible: 1,
rarity: 'legendary', type: 'minion', minion_type: 'dragon', keyword: 'battlecry',
text_filter: 'kalecgos', page: 1, page_size: 5, sort: 'name', order: 'desc' }
card = BlizzardApi::Hearthstone::Card.new
card_data = card.search search_options
assert_equal 1, card_data[:cardCount]
assert_equal 53_002, card_data[:cards][0][:id]
end
end
end
......
......@@ -11,7 +11,7 @@ module BlizzardApi
def test_mount_index
mount_data = @mount.index
assert_equal 766, mount_data[:mounts].count
assert_equal 767, 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 64, mythic_keystone_periods[:periods].count
assert_equal 65, mythic_keystone_periods[:periods].count
end
def test_mythic_keystone_period
......
......@@ -26,7 +26,7 @@ module BlizzardApi
def test_pvp_season_leaderboard
pvp_data = @pvp.leaderboard 27, '3v3'
assert_equal 5_008, pvp_data[:entries].count
assert_equal 5_007, pvp_data[:entries].count
end
def test_pvp_season_rewards
......
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