Commit 49c4eb12 authored by Francis's avatar Francis
Browse files

New search endpoints

parent ab098955
Pipeline #164528799 passed with stage
in 5 minutes and 30 seconds
Please view this file on the master branch, otherwise it may be outdated
**Version 0.4.2**
Added new retail and classic search endpoints described here: https://us.forums.blizzard.com/en/blizzard/t/world-of-warcraft-api-patch-notes-20200708/10310
**Version 0.4.1**
Added new retail and classic endpoints described here: https://us.forums.blizzard.com/en/blizzard/t/world-of-warcraft-api-patch-notes-20200609/8902
......
PATH
remote: .
specs:
blizzard_api (0.4.0)
blizzard_api (0.4.2)
redis (~> 4.1, >= 4.1.0)
GEM
......@@ -16,7 +16,7 @@ GEM
ast (~> 2.4.0)
rainbow (3.0.0)
rake (13.0.1)
redis (4.1.4)
redis (4.2.1)
rubocop (0.74.0)
jaro_winkler (~> 1.5.1)
parallel (~> 1.10)
......
......@@ -145,6 +145,7 @@ end
- types
- type :id
- display_media :id
- search
* Blizzard::Wow::Guild
- rewards
- perks
......@@ -211,6 +212,7 @@ end
- get :id
- complete
- status :realms
- search
* Blizzard::Wow::Region
- index
- get :id
......@@ -231,10 +233,12 @@ end
- class :id
- subclass :class_id, :subclass_id
- media :id
- search
* Blizzard::Wow::AzeriteEssence
- index
- get :id
- media :id
- search
* Blizzard::Wow::ReputationTier
- index
- get :id
......@@ -262,6 +266,7 @@ end
- get :id
* Blizzard::Wow::Spell
- get :id
- search
* Blizzard::Wow::Zone
- index
- get :id
......
......@@ -183,7 +183,7 @@ module BlizzardApi
def find_in_cache(resource_url)
return false unless BlizzardApi.use_cache
@redis.get resource_url if @redis.exists resource_url
@redis.get resource_url if @redis.exists? resource_url
end
def format_response(data)
......
......@@ -2,5 +2,5 @@
module BlizzardApi
# Gem version
VERSION = '0.4.1'
VERSION = '0.4.2'
end
......@@ -17,6 +17,7 @@ module BlizzardApi
require_relative 'wow/game_data/guild_crest'
require_relative 'wow/game_data/item'
require_relative 'wow/game_data/journal'
require_relative 'wow/game_data/media'
require_relative 'wow/game_data/mount'
require_relative 'wow/game_data/mythic_keystone_affix'
require_relative 'wow/game_data/mythic_keystone'
......@@ -95,6 +96,13 @@ module BlizzardApi
BlizzardApi::Wow::Journal.new(region)
end
##
# @param region [String] API Region
# @return {Media}
def self.media(region = BlizzardApi.region)
BlizzardApi::Wow::Media.new(region)
end
##
# @param region [String] API Region
# @return {Mount}
......
......@@ -10,6 +10,8 @@ module BlizzardApi
# You can get an instance of this class using the default region as follows:
# api_instance = BlizzardApi::Wow.azerite_essence
class AzeriteEssence < Wow::GenericDataEndpoint
include BlizzardApi::Wow::Searchable
##
# Fetch media for one of the azerite essences listed by the {#index} using its *id*
#
......
......@@ -10,6 +10,8 @@ module BlizzardApi
# You can get an instance of this class using the default region as follows:
# api_instance = BlizzardApi::Wow.creature
class Creature < Wow::GenericDataEndpoint
include BlizzardApi::Wow::Searchable
def index
raise BlizzardApi::ApiException, 'Creatures endpoint doesn\'t have a index method'
end
......
......@@ -10,6 +10,8 @@ module BlizzardApi
# You can get an instance of this class using the default region as follows:
# api_instance = BlizzardApi::Wow.item
class Item < Wow::GenericDataEndpoint
include BlizzardApi::Wow::Searchable
##
# This method overrides the inherited default behavior to prevent high server load and fetch time
#
......
......@@ -97,6 +97,21 @@ module BlizzardApi
api_request "#{endpoint_uri('encounter')}/#{id}", default_options.merge(options)
end
##
# Fetch data base on search criteria
#
# @param page [Integer] Page o return
# @param page_size [Integer] Amount of items per page
#
# @!macro request_options
# @!macro response
def encounter_search(page = 1, page_size = 100, options = {})
search_options = SearchComposer.new(page, page_size)
yield search_options if block_given?
api_request "#{endpoint_uri('encounter', :search)}?#{search_options.to_search_query}", default_options.merge(options)
end
protected
def endpoint_setup
......
# frozen_string_literal: true
module BlizzardApi
module Wow
##
# This class allows access to World of Warcraft mounts
#
# @see https://develop.battle.net/documentation/api-reference/world-of-warcraft-game-data-api
#
# You can get an instance of this class using the default region as follows:
# api_instance = BlizzardApi::Wow.mount
class Media < Wow::GenericDataEndpoint
include BlizzardApi::Wow::Searchable
def index(_options = nil)
raise BlizzardApi::ApiException, 'This endpoint does not have a index method'
end
def get(_options = nil)
raise BlizzardApi::ApiException, 'This endpoint does not have a get method'
end
def complete(_options = nil)
raise BlizzardApi::ApiException, 'This endpoint does not have a complete method'
end
protected
def endpoint_setup
@endpoint = 'media'
@namespace = :static
@collection = 'medias'
@ttl = CACHE_TRIMESTER
end
end
end
end
......@@ -10,6 +10,8 @@ module BlizzardApi
# You can get an instance of this class using the default region as follows:
# api_instance = BlizzardApi::Wow.mount
class Mount < Wow::GenericDataEndpoint
include BlizzardApi::Wow::Searchable
protected
def endpoint_setup
......
......@@ -10,6 +10,8 @@ module BlizzardApi
# You can get an instance of this class using the default region as follows:
# api_instance = BlizzardApi::Wow.spell
class Spell < Wow::GenericDataEndpoint
include BlizzardApi::Wow::Searchable
##
# This method overrides the inherited default behavior to prevent high server load and fetch time
#
......
......@@ -20,7 +20,7 @@ module BlizzardApi
# The second argument takes a simple value, an array of values or a hash for range searches.
#
# @param field [String] Field name
# @param value [String|Integer|Hash|Array<Integer|String>]
# @param value [String|Integer|Hash|Array<Integer>|Array<String>]
# @option value [Integer] :min Range start
# @option value [Integer] :max Range end
# @option value [Integer] :mode Range mode (:inclusive|:exclusive)
......@@ -37,7 +37,7 @@ module BlizzardApi
# The second argument takes a simple value, an array of values or a hash for range searches.
#
# @param field [String] Field name
# @param value [String|Integer|Hash|Array<Integer|String>]
# @param value [String|Integer|Hash|Array<Integer>|Array<String>]
# @option value [Integer] :min Range start
# @option value [Integer] :max Range end
# @option value [Integer] :mode Range mode (:inclusive|:exclusive)
......
......@@ -6,7 +6,7 @@ module BlizzardApi
# Added search support to an endpoint
module Searchable
##
# Fetch data base on search criteria
# Fetch data based on search criteria
#
# @param page [Integer] Page o return
# @param page_size [Integer] Amount of items per page
......
......@@ -10,18 +10,25 @@ module BlizzardApi
end
def test_azerite_essence_index
title_data = @azerite_essence.index
assert_equal 28, title_data[:azerite_essences].count
data = @azerite_essence.index
assert_equal 28, data[:azerite_essences].count
end
def test_azerite_essence_get
title_data = @azerite_essence.get 2
assert_equal 'Azeroth\'s Undying Gift', title_data[:name][:en_US]
data = @azerite_essence.get 2
assert_equal 'Azeroth\'s Undying Gift', data[:name][:en_US]
end
def test_azerite_essence_media
item_data = @azerite_essence.media 2
assert item_data.key? :assets
data = @azerite_essence.media 2
assert data.key? :assets
end
def test_azerite_essence_search
data = @azerite_essence.search(1, 100) do |search_options|
search_options.where 'name.en_US', 'Worldvein Resonance'
end
assert_equal 'Ressonância da Veia do Mundo', data[:results][0][:data][:name][:pt_BR]
end
end
end
......
......@@ -68,6 +68,14 @@ module BlizzardApi
assert_equal 'https://render-classic-us.worldofwarcraft.com/npcs/portrait/creature-display-180.jpg',
creature_display_media_data[:assets][0][:value]
end
def test_creature_search
data = @creature.search(1, 100) do |search_options|
search_options.where 'name.en_US', 'Dragon'
search_options.order_by 'id'
end
assert_equal 'Pequeno Dragão Verde', data[:results][0][:data][:name][:pt_BR]
end
end
end
end
......@@ -58,6 +58,14 @@ module BlizzardApi
item_data = @item.media 25, classic: true
assert item_data.key? :assets
end
def test_item_search
data = @item.search(1, 100) do |search_options|
search_options.where 'name.en_US', 'Booterang'
search_options.order_by 'id'
end
assert_equal 'Botarangue', data[:results][0][:data][:name][:pt_BR]
end
end
end
end
......@@ -18,6 +18,13 @@ module BlizzardApi
journal_data = @journal.expansion 72
assert_equal 'Wrath of the Lich King', journal_data[:name][:en_US]
end
def test_journal_encounter_search
journal_data = @journal.encounter_search(1, 100) do |search_options|
search_options.where 'name.en_US', 'Lich King'
end
assert_equal 'O Lich Rei', journal_data[:results][0][:data][:name][:pt_BR]
end
end
end
end
# frozen_string_literal: true
require 'test_helper'
module BlizzardApi
module Wow
class MediaTest < Minitest::Test
def setup
@media = BlizzardApi::Wow.media
end
def test_media_search
data = @media.search(1, 100) do |search_options|
search_options.where 'tags', 'item'
search_options.order_by 'id'
end
assert_equal 'https://render-us.worldofwarcraft.com/icons/56/inv_sword_04.jpg', data[:results][0][:data][:assets][0][:value]
end
end
end
end
......@@ -18,6 +18,14 @@ module BlizzardApi
mount_data = @mount.get 6
assert_equal 'Brown Horse', mount_data[:name][:en_US]
end
def test_mount_search
data = @mount.search(1, 100) do |search_options|
search_options.where 'name.en_US', 'Turtle'
search_options.order_by 'id'
end
assert_equal 'Tartaruga de Montaria', data[:results][0][:data][:name][:pt_BR]
end
end
end
end
......@@ -39,8 +39,8 @@ module BlizzardApi
end
assert_equal 2, realm_data[:results].size
realm_data = @realm.search(1, 100, classic: true) do |options|
options.where 'name.en_US', %w[Mankrik Pagle]
realm_data = @realm.search(1, 100, classic: true) do |search_options|
search_options.where 'name.en_US', %w[Mankrik Pagle]
end
assert_equal 2, realm_data[:results].size
end
......
......@@ -18,6 +18,14 @@ module BlizzardApi
spell_data = @spell.display_media 196_607
assert_equal 'https://render-us.worldofwarcraft.com/icons/56/ability_druid_primalprecision.jpg', spell_data[:assets][0][:value]
end
def test_spell_search
data = @spell.search(1, 100) do |search_options|
search_options.where 'name.en_US', 'Tranquility'
search_options.order_by 'id'
end
assert_equal 'Tranquilidade', data[:results][0][:data][:name][:pt_BR]
end
end
end
end
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