blizzard_api 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +12 -0
  3. data/.gitlab-ci.yml +28 -0
  4. data/.rubocop.yml +13 -0
  5. data/.rubocop_todo.yml +7 -0
  6. data/.travis.yml +7 -0
  7. data/CHANGELOG.md +4 -0
  8. data/Gemfile +8 -0
  9. data/Gemfile.lock +44 -0
  10. data/LICENSE.txt +21 -0
  11. data/README.md +208 -0
  12. data/Rakefile +12 -0
  13. data/bin/console +14 -0
  14. data/bin/setup +8 -0
  15. data/blizzard_api.gemspec +42 -0
  16. data/lib/blizzard_api.rb +14 -0
  17. data/lib/blizzard_api/configuration.rb +82 -0
  18. data/lib/blizzard_api/diablo.rb +76 -0
  19. data/lib/blizzard_api/diablo/community/act.rb +35 -0
  20. data/lib/blizzard_api/diablo/community/artisan.rb +38 -0
  21. data/lib/blizzard_api/diablo/community/character.rb +38 -0
  22. data/lib/blizzard_api/diablo/community/follower.rb +25 -0
  23. data/lib/blizzard_api/diablo/community/item.rb +26 -0
  24. data/lib/blizzard_api/diablo/community/item_type.rb +35 -0
  25. data/lib/blizzard_api/diablo/community/profile.rb +77 -0
  26. data/lib/blizzard_api/diablo/game_data/era.rb +21 -0
  27. data/lib/blizzard_api/diablo/game_data/generic_data_endpoint.rb +58 -0
  28. data/lib/blizzard_api/diablo/game_data/season.rb +21 -0
  29. data/lib/blizzard_api/diablo/request.rb +15 -0
  30. data/lib/blizzard_api/exception.rb +12 -0
  31. data/lib/blizzard_api/request.rb +182 -0
  32. data/lib/blizzard_api/starcraft.rb +40 -0
  33. data/lib/blizzard_api/starcraft/community/account.rb +23 -0
  34. data/lib/blizzard_api/starcraft/community/ladder.rb +34 -0
  35. data/lib/blizzard_api/starcraft/community/profile.rb +76 -0
  36. data/lib/blizzard_api/starcraft/game_data/league.rb +27 -0
  37. data/lib/blizzard_api/starcraft/request.rb +36 -0
  38. data/lib/blizzard_api/version.rb +6 -0
  39. data/lib/blizzard_api/wow.rb +167 -0
  40. data/lib/blizzard_api/wow/community/achievements.rb +45 -0
  41. data/lib/blizzard_api/wow/community/auction.rb +25 -0
  42. data/lib/blizzard_api/wow/community/boss.rb +35 -0
  43. data/lib/blizzard_api/wow/community/challenge.rb +35 -0
  44. data/lib/blizzard_api/wow/community/character.rb +103 -0
  45. data/lib/blizzard_api/wow/community/guild.rb +67 -0
  46. data/lib/blizzard_api/wow/community/item.rb +46 -0
  47. data/lib/blizzard_api/wow/community/mount.rb +24 -0
  48. data/lib/blizzard_api/wow/community/pets.rb +85 -0
  49. data/lib/blizzard_api/wow/community/pvp.rb +34 -0
  50. data/lib/blizzard_api/wow/community/quest.rb +25 -0
  51. data/lib/blizzard_api/wow/community/recipe.rb +25 -0
  52. data/lib/blizzard_api/wow/community/spell.rb +25 -0
  53. data/lib/blizzard_api/wow/community/zone.rb +35 -0
  54. data/lib/blizzard_api/wow/game_data/connected_realm.rb +37 -0
  55. data/lib/blizzard_api/wow/game_data/generic_data_endpoint.rb +58 -0
  56. data/lib/blizzard_api/wow/game_data/mythic_keystone_affix.rb +23 -0
  57. data/lib/blizzard_api/wow/game_data/playable_class.rb +62 -0
  58. data/lib/blizzard_api/wow/game_data/playable_specialization.rb +70 -0
  59. data/lib/blizzard_api/wow/game_data/power_type.rb +23 -0
  60. data/lib/blizzard_api/wow/game_data/race.rb +51 -0
  61. data/lib/blizzard_api/wow/game_data/realm.rb +48 -0
  62. data/lib/blizzard_api/wow/game_data/region.rb +49 -0
  63. data/lib/blizzard_api/wow/request.rb +16 -0
  64. metadata +198 -0
@@ -0,0 +1,67 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BlizzardApi
4
+ module Wow
5
+ ##
6
+ # This class allows access to World of Warcraft guild data
7
+ #
8
+ # @see https://develop.battle.net/documentation/api-reference/world-of-warcraft-community-api
9
+ #
10
+ # You can get an instance of this class using the default region as follows:
11
+ # api_instance = BlizzardApi::Wow.guild
12
+ class Guild < Wow::Request
13
+ # Valid fields for guild profile request
14
+ VALID_FIELDS = %w[achievements challenge members news].freeze
15
+
16
+ ##
17
+ # Helper method for checking valid fields. Use this to validate an array of fields if you are not sure about their
18
+ # names.
19
+ #
20
+ # @param fields [Array<String>] Array containing desired fields to include
21
+ #
22
+ # @raise ArgumentError
23
+ def validate_fields(fields)
24
+ fields.each do |field|
25
+ raise ArgumentError, "Unrecognized field #{field}" unless VALID_FIELDS.include? field
26
+ end
27
+ end
28
+
29
+ ##
30
+ # Return a list with all possible rewards.
31
+ #
32
+ # @!macro request_options
33
+ #
34
+ # @!macro response
35
+ def rewards(options = {})
36
+ api_request "#{base_url(:community)}/data/guild/rewards", { ttl: CACHE_TRIMESTER }.merge(options)
37
+ end
38
+
39
+ ##
40
+ # Return a list with all possible perks
41
+ #
42
+ # @!macro request_options
43
+ #
44
+ # @!macro response
45
+ def perks(options = {})
46
+ api_request "#{base_url(:community)}/data/guild/perks", { ttl: CACHE_TRIMESTER }.merge(options)
47
+ end
48
+
49
+ ##
50
+ # Return data about the specified guild
51
+ #
52
+ # @param realm [String] The guild realm's slug
53
+ # @param guild [String] The guild's name
54
+ # @param fields [Array<String>] An array containing all the fields you want to be included in the response.
55
+ # @!macro request_options
56
+ #
57
+ # @!macro response
58
+ def get(realm, guild, fields = [], options = {})
59
+ validate_fields fields if options.include? :validate_fields
60
+
61
+ opts = { ttl: CACHE_DAY, fields: fields.join(',') }.merge(options)
62
+
63
+ api_request "#{base_url(:community)}/guild/#{realm}/#{guild}", opts
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BlizzardApi
4
+ module Wow
5
+ ##
6
+ # This class allows access to World of Warcraft item data
7
+ #
8
+ # @see https://develop.battle.net/documentation/api-reference/world-of-warcraft-community-api
9
+ #
10
+ # You can get an instance of this class using the default region as follows:
11
+ # api_instance = BlizzardApi::Wow.item
12
+ class Item < Wow::Request
13
+ ##
14
+ # Return complete data of an item by id
15
+ #
16
+ # @param id [Integer] Item id
17
+ # @!macro request_options
18
+ #
19
+ # @!macro response
20
+ def get(id, options = {})
21
+ api_request "#{base_url(:community)}/item/#{id}", { ttl: CACHE_TRIMESTER }.merge(options)
22
+ end
23
+
24
+ ##
25
+ # Return complete data of an item set by id
26
+ #
27
+ # @param set_id [Integer] Item set id
28
+ # @!macro request_options
29
+ #
30
+ # @!macro response
31
+ def item_set(set_id, options = {})
32
+ api_request "#{base_url(:community)}/item/set/#{set_id}", { ttl: CACHE_TRIMESTER }.merge(options)
33
+ end
34
+
35
+ ##
36
+ # Return a list of item classes
37
+ #
38
+ # @!macro request_options
39
+ #
40
+ # @!macro response
41
+ def classes(options = {})
42
+ api_request "#{base_url(:community)}/data/item/classes", { ttl: CACHE_TRIMESTER }.merge(options)
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BlizzardApi
4
+ module Wow
5
+ ##
6
+ # This class allows access to World of Warcraft mount data
7
+ #
8
+ # @see https://develop.battle.net/documentation/api-reference/world-of-warcraft-community-api
9
+ #
10
+ # You can get an instance of this class using the default region as follows:
11
+ # api_instance = BlizzardApi::Wow.mount
12
+ class Mount < Wow::Request
13
+ ##
14
+ # Return a list with all available mounts
15
+ #
16
+ # @!macro request_options
17
+ #
18
+ # @!macro response
19
+ def index(options = {})
20
+ api_request "#{base_url(:community)}/mount/", { ttl: CACHE_TRIMESTER }.merge(options)
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,85 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BlizzardApi
4
+ module Wow
5
+ ##
6
+ # This class allows access to World of Warcraft pet data
7
+ #
8
+ # @see https://develop.battle.net/documentation/api-reference/world-of-warcraft-community-api
9
+ #
10
+ # You can get an instance of this class using the default region as follows:
11
+ # api_instance = BlizzardApi::Wow.pet
12
+ class Pet < Wow::Request
13
+ # Poor (gray) quality pet
14
+ PET_QUALITY_POOR = 0
15
+ # Common (white) quality pet
16
+ PET_QUALITY_COMMON = 1
17
+ # Uncommon (green) quality pet
18
+ PET_QUALITY_UNCOMMON = 2
19
+ # Rare (blue) quality pet
20
+ PET_QUALITY_RARE = 3
21
+ # Epic (purple) quality pet
22
+ PET_QUALITY_EPIC = 4
23
+ # Legendary (orange) quality pet
24
+ PET_QUALITY_LEGENDARY = 5
25
+
26
+ ##
27
+ # Return a list of all available pets
28
+ #
29
+ # @!macro request_options
30
+ #
31
+ # @!macro response
32
+ def index(options = {})
33
+ api_request "#{base_url(:community)}/pet/", { ttl: CACHE_TRIMESTER }.merge(options)
34
+ end
35
+
36
+ ##
37
+ # Return complete data about a pet ability by its id
38
+ #
39
+ # @param id [Integer] Pet ability id
40
+ # @!macro request_options
41
+ #
42
+ # @!macro response
43
+ def ability(id, options = {})
44
+ api_request "#{base_url(:community)}/pet/ability/#{id}", { ttl: CACHE_TRIMESTER }.merge(options)
45
+ end
46
+
47
+ ##
48
+ # Return complete data about a pet species by its id
49
+ #
50
+ # @param id [Integer] Pet species id
51
+ # @!macro request_options
52
+ #
53
+ # @!macro response
54
+ def species(id, options = {})
55
+ api_request "#{base_url(:community)}/pet/species/#{id}", { ttl: CACHE_TRIMESTER }.merge(options)
56
+ end
57
+
58
+ ##
59
+ # Return complete data about a pet stats based on its attributes
60
+ #
61
+ # @param id [Integer] Pet id (Obtained by the {#index} or {Character#get} with the fields *pets* or *petSlots*)
62
+ # @param level [Integer] Pet's level (1 - 25)
63
+ # @param breed_id [Integer]
64
+ # @param quality_id [Integer] Pets quality ID where 0 = Poor and 5 = legendary. You can use the
65
+ # constants PET_QUALITY_*
66
+ # @!macro request_options
67
+ #
68
+ # @!macro response
69
+ def stats(id, level = 25, breed_id = 3, quality_id = 1, options = {})
70
+ opts = { level: level, breedId: breed_id, qualityId: quality_id, ttl: CACHE_TRIMESTER }.merge(options)
71
+ api_request "#{base_url(:community)}/pet/stats/#{id}", opts
72
+ end
73
+
74
+ ##
75
+ # Return a complete list of pet types
76
+ #
77
+ # @!macro request_options
78
+ #
79
+ # @!macro response
80
+ def types(options = {})
81
+ api_request "#{base_url(:community)}/data/pet/types", { ttl: CACHE_TRIMESTER }.merge(options)
82
+ end
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BlizzardApi
4
+ module Wow
5
+ ##
6
+ # This class allows access to World of Warcraft PvP data
7
+ #
8
+ # @see https://develop.battle.net/documentation/api-reference/world-of-warcraft-community-api
9
+ #
10
+ # You can get an instance of this class using the default region as follows:
11
+ # api_instance = BlizzardApi::Wow.pvp
12
+ class PvP < Wow::Request
13
+ # Arena 2v2
14
+ BRACKET_2V2 = '2v2'
15
+ # Arena 3x3
16
+ BRACKET_3V3 = '3v3'
17
+ # Arena 5x5
18
+ BRACKET_5V5 = '5v5'
19
+ # Rated battlegrounds
20
+ BRACKET_RBG = 'rbg'
21
+
22
+ ##
23
+ # Returns the current pvp leaderboard for the current region
24
+ #
25
+ # @param bracket [String] PvP leaderboard category. You can use the constants BRACKET_*
26
+ # @!macro request_options
27
+ #
28
+ # @!macro response
29
+ def get(bracket, options = {})
30
+ api_request "#{base_url(:community)}/leaderboard/#{bracket}", { ttl: CACHE_DAY }.merge(options)
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BlizzardApi
4
+ module Wow
5
+ ##
6
+ # This class allows access to World of Warcraft quest data
7
+ #
8
+ # @see https://develop.battle.net/documentation/api-reference/world-of-warcraft-community-api
9
+ #
10
+ # You can get an instance of this class using the default region as follows:
11
+ # api_instance = BlizzardApi::Wow.quest
12
+ class Quest < Wow::Request
13
+ ##
14
+ # Return information about a quest by its id
15
+ #
16
+ # @param id [Integer] Quest id
17
+ # @!macro request_options
18
+ #
19
+ # @!macro response
20
+ def get(id, options = {})
21
+ api_request "#{base_url(:community)}/quest/#{id}", { ttl: CACHE_TRIMESTER }.merge(options)
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BlizzardApi
4
+ module Wow
5
+ ##
6
+ # This class allows access to World of Warcraft recipe data
7
+ #
8
+ # @see https://develop.battle.net/documentation/api-reference/world-of-warcraft-community-api
9
+ #
10
+ # You can get an instance of this class using the default region as follows:
11
+ # api_instance = BlizzardApi::Wow.recipe
12
+ class Recipe < Wow::Request
13
+ ##
14
+ # Return information about a recipe by its id
15
+ #
16
+ # @param id [Integer] Recipe id
17
+ # @!macro request_options
18
+ #
19
+ # @!macro response
20
+ def get(id, options = {})
21
+ api_request "#{base_url(:community)}/recipe/#{id}", { ttl: CACHE_TRIMESTER }.merge(options)
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BlizzardApi
4
+ module Wow
5
+ ##
6
+ # This class allows access to World of Warcraft spell data
7
+ #
8
+ # @see https://develop.battle.net/documentation/api-reference/world-of-warcraft-community-api
9
+ #
10
+ # You can get an instance of this class using the default region as follows:
11
+ # api_instance = BlizzardApi::Wow.spell
12
+ class Spell < Wow::Request
13
+ ##
14
+ # Return information about a spell by its id
15
+ #
16
+ # @param id [Integer] Spell id
17
+ # @!macro request_options
18
+ #
19
+ # @!macro response
20
+ def get(id, options = {})
21
+ api_request "#{base_url(:community)}/spell/#{id}", { ttl: CACHE_TRIMESTER }.merge(options)
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BlizzardApi
4
+ module Wow
5
+ ##
6
+ # This class allows access to World of Warcraft zone data
7
+ #
8
+ # @see https://develop.battle.net/documentation/api-reference/world-of-warcraft-community-api
9
+ #
10
+ # You can get an instance of this class using the default region as follows:
11
+ # api_instance = BlizzardApi::Wow.zone
12
+ class Zone < Wow::Request
13
+ ##
14
+ # Return a list of all zones
15
+ #
16
+ # @!macro request_options
17
+ #
18
+ # @!macro response
19
+ def index(options = {})
20
+ api_request "#{base_url(:community)}/zone/", { ttl: CACHE_TRIMESTER }.merge(options)
21
+ end
22
+
23
+ ##
24
+ # Return complete information about a zone by its id
25
+ #
26
+ # @param id [Integer] Zone id
27
+ # @!macro request_options
28
+ #
29
+ # @!macro response
30
+ def get(id, options = {})
31
+ api_request "#{base_url(:community)}/zone/#{id}", { ttl: CACHE_TRIMESTER }.merge(options)
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BlizzardApi
4
+ module Wow
5
+ ##
6
+ # This class allows access to World of Warcraft connected realms
7
+ #
8
+ # @see https://develop.battle.net/documentation/api-reference/world-of-warcraft-game-data-api
9
+ #
10
+ # You can get an instance of this class using the default region as follows:
11
+ # api_instance = BlizzardApi::Wow.connected_realms
12
+ class ConnectedRealm < Wow::GenericDataEndpoint
13
+ ##
14
+ # @!macro complete
15
+ def complete(options = {})
16
+ [].tap do |data|
17
+ index_data = index options
18
+ index_data[:connected_realms].each do |realm|
19
+ realm_id = %r{connected-realm/([0-9]+)}.match(realm[:href])[1]
20
+ realm_data = get realm_id, options
21
+ realm_data.delete :_links
22
+ data.push realm_data
23
+ end
24
+ end
25
+ end
26
+
27
+ protected
28
+
29
+ def endpoint_setup
30
+ @endpoint = 'connected-realm'
31
+ @namespace = endpoint_namespace :dynamic
32
+ @collection = 'connected_realms'
33
+ @ttl = CACHE_TRIMESTER
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BlizzardApi
4
+ module Wow
5
+ ##
6
+ # Generic endpoint to support most data requests with minor configurations
7
+ class GenericDataEndpoint < Wow::Request
8
+ ##
9
+ # @!macro regions
10
+ def initialize(region = nil)
11
+ super region
12
+ endpoint_setup
13
+ @ttl ||= CACHE_DAY
14
+ end
15
+
16
+ ##
17
+ # Fetch a list of all resources available for this endpoint
18
+ #
19
+ # @!macro request_options
20
+ # @!macro response
21
+ def index(options = {})
22
+ api_request "#{base_url(:game_data)}/#{@endpoint}/index", default_options.merge(options)
23
+ end
24
+
25
+ ##
26
+ # Fetch all possible data for one of items listed by the {#index} using its *id*
27
+ #
28
+ # @param id [Integer] One of the IDs returned by the {#index}
29
+ # @!macro request_options
30
+ #
31
+ # @!macro response
32
+ def get(id, options = {})
33
+ api_request "#{base_url(:game_data)}/#{@endpoint}/#{id}", default_options.merge(options)
34
+ end
35
+
36
+ ##
37
+ # @!macro complete
38
+ def complete(options = {})
39
+ index_data = index options
40
+ index_data[@collection.to_sym].tap do |collection|
41
+ collection.each do |item|
42
+ item.delete 'key'
43
+ end
44
+ end
45
+ end
46
+
47
+ protected
48
+
49
+ def endpoint_setup
50
+ raise NotImplementedError, 'You must override this method to properly set up the endpoint'
51
+ end
52
+
53
+ def default_options
54
+ { namespace: @namespace, ttl: @ttl }
55
+ end
56
+ end
57
+ end
58
+ end