Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Switch to GitLab Next
Sign in / Register
Toggle navigation
Open sidebar
Francis
Blizzard api
Commits
2a15a25d
Commit
2a15a25d
authored
Jul 03, 2019
by
Francis
Browse files
Added WoW profile endpoints and HS cards search method
parent
67a5aab5
Pipeline
#69302674
passed with stages
in 4 minutes and 9 seconds
Changes
8
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
222 additions
and
37 deletions
+222
-37
CHANGELOG.md
CHANGELOG.md
+4
-0
lib/blizzard_api/hearthstone/game_data/card.rb
lib/blizzard_api/hearthstone/game_data/card.rb
+70
-0
lib/blizzard_api/hearthstone/game_data/deck.rb
lib/blizzard_api/hearthstone/game_data/deck.rb
+3
-9
lib/blizzard_api/wow/profile/character_profile.rb
lib/blizzard_api/wow/profile/character_profile.rb
+129
-23
test/blizzard/hearthstone/game_data/card_test.rb
test/blizzard/hearthstone/game_data/card_test.rb
+13
-2
test/blizzard/wow/game_data/mount_test.rb
test/blizzard/wow/game_data/mount_test.rb
+1
-1
test/blizzard/wow/game_data/mythic_keystone_test.rb
test/blizzard/wow/game_data/mythic_keystone_test.rb
+1
-1
test/blizzard/wow/game_data/pvp_season_test.rb
test/blizzard/wow/game_data/pvp_season_test.rb
+1
-1
No files found.
CHANGELOG.md
View file @
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
...
...
lib/blizzard_api/hearthstone/game_data/card.rb
View file @
2a15a25d
...
...
@@ -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
...
...
lib/blizzard_api/hearthstone/game_data/deck.rb
View file @
2a15a25d
...
...
@@ -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
...
...
lib/blizzard_api/wow/profile/character_profile.rb
View file @
2a15a25d
...
...
@@ -11,62 +11,168 @@ module BlizzardApi
# api_instance = BlizzardApi::Wow.achievement
class
CharacterProfile
<
Wow
::
Request
##
# Return
the mythic keystone profile of
a
ch
aracter
# Return
character
ach
ievements
#
# @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
)
...
...
test/blizzard/hearthstone/game_data/card_test.rb
View file @
2a15a25d
...
...
@@ -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
...
...
test/blizzard/wow/game_data/mount_test.rb
View file @
2a15a25d
...
...
@@ -11,7 +11,7 @@ module BlizzardApi
def
test_mount_index
mount_data
=
@mount
.
index
assert_equal
76
6
,
mount_data
[
:mounts
].
count
assert_equal
76
7
,
mount_data
[
:mounts
].
count
mount_data
=
@mount
.
index
use_community_endpoint:
true
assert_equal
919
,
mount_data
[
:mounts
].
count
...
...
test/blizzard/wow/game_data/mythic_keystone_test.rb
View file @
2a15a25d
...
...
@@ -27,7 +27,7 @@ module BlizzardApi
def
test_mythic_keystone_periods
mythic_keystone_periods
=
@mythic_keystone_leaderboard
.
periods
assert_equal
6
4
,
mythic_keystone_periods
[
:periods
].
count
assert_equal
6
5
,
mythic_keystone_periods
[
:periods
].
count
end
def
test_mythic_keystone_period
...
...
test/blizzard/wow/game_data/pvp_season_test.rb
View file @
2a15a25d
...
...
@@ -26,7 +26,7 @@ module BlizzardApi
def
test_pvp_season_leaderboard
pvp_data
=
@pvp
.
leaderboard
27
,
'3v3'
assert_equal
5_00
8
,
pvp_data
[
:entries
].
count
assert_equal
5_00
7
,
pvp_data
[
:entries
].
count
end
def
test_pvp_season_rewards
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment