blizzard_api 0.2.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +4 -0
  3. data/.rubocop_todo.yml +0 -6
  4. data/CHANGELOG.md +3 -0
  5. data/Gemfile.lock +2 -2
  6. data/README.md +93 -34
  7. data/lib/blizzard_api/configuration.rb +32 -0
  8. data/lib/blizzard_api/request.rb +17 -10
  9. data/lib/blizzard_api/version.rb +1 -1
  10. data/lib/blizzard_api/wow.rb +111 -47
  11. data/lib/blizzard_api/wow/community/character.rb +1 -22
  12. data/lib/blizzard_api/wow/game_data/achievement.rb +101 -0
  13. data/lib/blizzard_api/wow/game_data/connected_realm.rb +1 -15
  14. data/lib/blizzard_api/wow/game_data/creature.rb +99 -0
  15. data/lib/blizzard_api/wow/game_data/generic_data_endpoint.rb +14 -7
  16. data/lib/blizzard_api/wow/{community → game_data}/guild.rb +42 -3
  17. data/lib/blizzard_api/wow/game_data/guild_crest.rb +50 -0
  18. data/lib/blizzard_api/wow/game_data/mount.rb +37 -0
  19. data/lib/blizzard_api/wow/game_data/mythic_keystone.rb +97 -0
  20. data/lib/blizzard_api/wow/game_data/mythic_keystone_leaderboard.rb +48 -0
  21. data/lib/blizzard_api/wow/game_data/mythic_raid_leaderboard.rb +28 -0
  22. data/lib/blizzard_api/wow/{community/pets.rb → game_data/pet.rb} +14 -1
  23. data/lib/blizzard_api/wow/game_data/playable_class.rb +10 -4
  24. data/lib/blizzard_api/wow/game_data/pvp_season.rb +53 -0
  25. data/lib/blizzard_api/wow/game_data/pvp_tier.rb +33 -0
  26. data/lib/blizzard_api/wow/game_data/race.rb +1 -15
  27. data/lib/blizzard_api/wow/game_data/realm.rb +0 -14
  28. data/lib/blizzard_api/wow/game_data/region.rb +0 -13
  29. data/lib/blizzard_api/wow/game_data/wow_token.rb +25 -0
  30. data/lib/blizzard_api/wow/profile/character_profile.rb +77 -0
  31. metadata +15 -6
  32. data/lib/blizzard_api/wow/community/achievements.rb +0 -45
  33. data/lib/blizzard_api/wow/community/mount.rb +0 -24
@@ -0,0 +1,97 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BlizzardApi
4
+ module Wow
5
+ ##
6
+ # This class allows access to World of Warcraft achievements
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.mythic_keystone
12
+ class MythicKeystone < Wow::GenericDataEndpoint
13
+ def get
14
+ raise BlizzardApi::ApiException, 'Mythic keystone endpoint does not have a get method'
15
+ end
16
+
17
+ def complete
18
+ raise BlizzardApi::ApiException, 'There are too many creatures to fetch complete data'
19
+ end
20
+
21
+ ##
22
+ # Fetch all mythic keystone dungeons
23
+ #
24
+ # @!macro request_options
25
+ #
26
+ # @!macro response
27
+ def dungeons(options = {})
28
+ api_request "#{endpoint_uri}/period/index", default_options.merge(options)
29
+ end
30
+
31
+ ##
32
+ # Fetch all possible data for one of the items listed by the {#dungeons} using its *id*
33
+ #
34
+ # @param id [Integer] Dungeon id
35
+ #
36
+ # @!macro request_options
37
+ #
38
+ # @!macro response
39
+ def dungeon(id, options = {})
40
+ api_request "#{endpoint_uri}/dungeon/#{id}", default_options.merge(options)
41
+ end
42
+
43
+ ##
44
+ # Fetch all mythic keystone periods
45
+ #
46
+ # @!macro request_options
47
+ #
48
+ # @!macro response
49
+ def periods(options = {})
50
+ api_request "#{endpoint_uri}/period/index", default_options.merge(options)
51
+ end
52
+
53
+ ##
54
+ # Fetch all possible data for one of the items listed by the {#periods} using its *id*
55
+ #
56
+ # @param id [Integer] Mythic keystone period id
57
+ #
58
+ # @!macro request_options
59
+ #
60
+ # @!macro response
61
+ def period(id, options = {})
62
+ api_request "#{endpoint_uri}/period/#{id}", default_options.merge(options)
63
+ end
64
+
65
+ ##
66
+ # Fetch all mythic keystone seasons
67
+ #
68
+ # @!macro request_options
69
+ #
70
+ # @!macro response
71
+ def seasons(options = {})
72
+ api_request "#{endpoint_uri}/season/index", default_options.merge(options)
73
+ end
74
+
75
+ ##
76
+ # Fetch all possible data for one of the items listed by the {#seasons} using its *id*
77
+ #
78
+ # @param id [Integer] Mythic keystone season id
79
+ #
80
+ # @!macro request_options
81
+ #
82
+ # @!macro response
83
+ def season(id, options = {})
84
+ api_request "#{endpoint_uri}/season/#{id}", default_options.merge(options)
85
+ end
86
+
87
+ protected
88
+
89
+ def endpoint_setup
90
+ @endpoint = 'mythic-keystone'
91
+ @namespace = endpoint_namespace :dynamic
92
+ @collection = 'mythic-keystones'
93
+ @ttl = CACHE_TRIMESTER
94
+ end
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BlizzardApi
4
+ module Wow
5
+ ##
6
+ # This class allows access to World of Warcraft mythic raid leaderboard
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.mythic_keystone_leaderboard
12
+ class MythicKeystoneLeaderboard < Wow::Request
13
+ ##
14
+ # Fetch mythic keystone leaderboards for the specified realm
15
+ #
16
+ # @param connected_realm_id [Integer] One of the IDs returned by the {ConnectedRealm#index}
17
+ #
18
+ # @!macro request_options
19
+ #
20
+ # @!macro response
21
+ def index(connected_realm_id, options = {})
22
+ api_request "#{endpoint_uri(connected_realm_id)}/index", default_options(options)
23
+ end
24
+
25
+ ##
26
+ # Fetch mythic keystone leaderboard for the specified realm, dungeon and period
27
+ #
28
+ # @param connected_realm_id [Integer] One of the IDs returned by the {ConnectedRealm#index}
29
+ #
30
+ # @!macro request_options
31
+ #
32
+ # @!macro response
33
+ def get(connected_realm_id, dungeon_id, period, options = {})
34
+ api_request "#{endpoint_uri(connected_realm_id)}/#{dungeon_id}/period/#{period}", default_options(options)
35
+ end
36
+
37
+ private
38
+
39
+ def default_options(options)
40
+ { ttl: CACHE_DAY, namespace: endpoint_namespace(:dynamic) }.merge options
41
+ end
42
+
43
+ def endpoint_uri(connected_realm_id)
44
+ "#{base_url(:game_data)}/connected-realm/#{connected_realm_id}/mythic-leaderboard"
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BlizzardApi
4
+ module Wow
5
+ ##
6
+ # This class allows access to World of Warcraft mythic raid leaderboard
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.mythic_raid_leaderboard
12
+ class MythicRaidLeaderboard < Wow::Request
13
+ ##
14
+ # Fetch leaderboard data for given raid and faction
15
+ #
16
+ # @param raid [String] Raid slug
17
+ # @param faction [String] Faction slug
18
+ #
19
+ # @!macro request_options
20
+ #
21
+ # @!macro response
22
+ def get(raid, faction, options = {})
23
+ opts = options.merge(namespace: endpoint_namespace(:dynamic), ttl: CACHE_DAY)
24
+ api_request "#{base_url(:game_data)}/leaderboard/hall-of-fame/#{raid}/#{faction}", opts
25
+ end
26
+ end
27
+ end
28
+ end
@@ -9,7 +9,7 @@ module BlizzardApi
9
9
  #
10
10
  # You can get an instance of this class using the default region as follows:
11
11
  # api_instance = BlizzardApi::Wow.pet
12
- class Pet < Wow::Request
12
+ class Pet < Wow::GenericDataEndpoint
13
13
  # Poor (gray) quality pet
14
14
  PET_QUALITY_POOR = 0
15
15
  # Common (white) quality pet
@@ -27,9 +27,13 @@ module BlizzardApi
27
27
  # Return a list of all available pets
28
28
  #
29
29
  # @!macro request_options
30
+ # @option options [Boolean] :use_community_endpoint If set to true, this method will call the community endpoint
31
+ # instead of the data endpoint https://develop.battle.net/documentation/api-reference/world-of-warcraft-community-api
30
32
  #
31
33
  # @!macro response
32
34
  def index(options = {})
35
+ return super options unless options.include? :use_community_endpoint
36
+
33
37
  api_request "#{base_url(:community)}/pet/", { ttl: CACHE_TRIMESTER }.merge(options)
34
38
  end
35
39
 
@@ -80,6 +84,15 @@ module BlizzardApi
80
84
  def types(options = {})
81
85
  api_request "#{base_url(:community)}/data/pet/types", { ttl: CACHE_TRIMESTER }.merge(options)
82
86
  end
87
+
88
+ protected
89
+
90
+ def endpoint_setup
91
+ @endpoint = 'pet'
92
+ @namespace = endpoint_namespace :static
93
+ @collection = 'pets'
94
+ @ttl = CACHE_TRIMESTER
95
+ end
83
96
  end
84
97
  end
85
98
  end
@@ -32,7 +32,7 @@ module BlizzardApi
32
32
  #
33
33
  # @!macro response
34
34
  def talent_slots(id, options = {})
35
- api_request "#{base_url(:game_data)}/#{@endpoint}/#{id}/pvp-talent-slots", default_options.merge(options)
35
+ api_request "#{endpoint_uri}/#{id}/pvp-talent-slots", default_options.merge(options)
36
36
  end
37
37
 
38
38
  ##
@@ -48,11 +48,17 @@ module BlizzardApi
48
48
  end
49
49
  end
50
50
 
51
+ ##
52
+ # Return playable class data by its id
53
+ #
54
+ # @param id [Integer] Playable class id
55
+ #
56
+ # @!macro request_options
57
+ #
58
+ # @!macro response
51
59
  def get(id, options = {})
52
- data = api_request "#{base_url(:game_data)}/#{@endpoint}/#{id}", default_options.merge(options)
60
+ data = api_request "#{endpoint_uri}/#{id}", default_options.merge(options)
53
61
  data[:icon] = get_class_icon data[:media], options
54
- data.delete :_links
55
- data.delete :media
56
62
  data
57
63
  end
58
64
 
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BlizzardApi
4
+ module Wow
5
+ ##
6
+ # This class allows access to World of Warcraft PvP seasons
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.pvp_season
12
+ class PvpSeason < Wow::GenericDataEndpoint
13
+ ##
14
+ # Returns a index of pvp leaderboard for a season
15
+ #
16
+ # @!macro request_options
17
+ #
18
+ # @!macro response
19
+ def leaderboards(season_id, options = {})
20
+ api_request "#{endpoint_uri}/#{season_id}/pvp-leaderboard/index", default_options.merge(options)
21
+ end
22
+
23
+ ##
24
+ # Returns the leaderboard for a given season and bracket
25
+ #
26
+ # @!macro request_options
27
+ #
28
+ # @!macro response
29
+ def leaderboard(season_id, brackets, options = {})
30
+ api_request "#{endpoint_uri}/#{season_id}/pvp-leaderboard/#{brackets}", default_options.merge(options)
31
+ end
32
+
33
+ ##
34
+ # Returns a list of pvp rewards for a season
35
+ #
36
+ # @!macro request_options
37
+ #
38
+ # @!macro response
39
+ def rewards(season_id, options = {})
40
+ api_request "#{endpoint_uri}/#{season_id}/pvp-reward/index", default_options.merge(options)
41
+ end
42
+
43
+ protected
44
+
45
+ def endpoint_setup
46
+ @endpoint = 'pvp-season'
47
+ @namespace = endpoint_namespace :dynamic
48
+ @collection = 'power_types'
49
+ @ttl = CACHE_TRIMESTER
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BlizzardApi
4
+ module Wow
5
+ ##
6
+ # This class allows access to World of Warcraft power types
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.power_type
12
+ class PvpTier < Wow::GenericDataEndpoint
13
+ ##
14
+ # Returns media assets for a pvp tier
15
+ #
16
+ # @!macro request_options
17
+ #
18
+ # @!macro response
19
+ def tier_media(id, options = {})
20
+ api_request "#{base_url(:media)}/#{@endpoint}/#{id}", default_options.merge(options)
21
+ end
22
+
23
+ protected
24
+
25
+ def endpoint_setup
26
+ @endpoint = 'pvp-tier'
27
+ @namespace = endpoint_namespace :static
28
+ @collection = 'tiers'
29
+ @ttl = CACHE_TRIMESTER
30
+ end
31
+ end
32
+ end
33
+ end
@@ -24,24 +24,10 @@ module BlizzardApi
24
24
  api_request "#{base_url(:community)}/data/character/races", { ttl: CACHE_TRIMESTER }.merge(options)
25
25
  end
26
26
 
27
- ##
28
- # @!macro complete
29
- def complete(options = {})
30
- index_data = index options
31
- [].tap do |races|
32
- index_data[:races].each do |race|
33
- race_id = %r{race/([0-9]+)}.match(race[:key].to_s)[1]
34
- race_data = get race_id, options
35
- race_data.delete :name
36
- races.push race_data
37
- end
38
- end
39
- end
40
-
41
27
  protected
42
28
 
43
29
  def endpoint_setup
44
- @endpoint = 'race'
30
+ @endpoint = 'playable-race'
45
31
  @namespace = endpoint_namespace :static
46
32
  @collection = 'races'
47
33
  @ttl = CACHE_TRIMESTER
@@ -21,20 +21,6 @@ module BlizzardApi
21
21
  api_request "#{base_url(:community)}/realm/status", { ttl: CACHE_MINUTE }.merge(options)
22
22
  end
23
23
 
24
- ##
25
- # @!macro complete
26
- def complete(options = {})
27
- index_data = index options
28
- [].tap do |realms|
29
- index_data[:realms].each do |realm|
30
- realm_data = get realm[:id], options
31
- realm_data.delete :_links
32
- realm_data[:region].delete :key
33
- realms.push realm_data
34
- end
35
- end
36
- end
37
-
38
24
  protected
39
25
 
40
26
  def endpoint_setup
@@ -10,19 +10,6 @@ module BlizzardApi
10
10
  # You can get an instance of this class using the default region as follows:
11
11
  # api_instance = BlizzardApi::Wow.region
12
12
  class Region < Wow::GenericDataEndpoint
13
- ##
14
- # @!macro complete
15
- def complete(options = {})
16
- [].tap do |data|
17
- index_data = index options
18
- index_data[:regions].each do |region|
19
- region_data = request region[:href], options
20
- region_data.delete :_links
21
- data.push region_data
22
- end
23
- end
24
- end
25
-
26
13
  ##
27
14
  # Returns data about region battlegroups
28
15
  #
@@ -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 tokens
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.wow_token
12
+ class WowToken < Wow::Request
13
+ ##
14
+ # Returns wow token data
15
+ #
16
+ # @!macro request_options
17
+ #
18
+ # @!macro response
19
+ def get(options = {})
20
+ opts = { namespace: endpoint_namespace(:dynamic), ttl: CACHE_HOUR }.merge(options)
21
+ api_request "#{base_url(:game_data)}/token/index", opts
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,77 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BlizzardApi
4
+ module Wow
5
+ ##
6
+ # This class allows access to World of Warcraft character profile data
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.achievement
12
+ class CharacterProfile < Wow::Request
13
+ ##
14
+ # Return the mythic keystone profile of a character
15
+ #
16
+ # @note This endpoint requires a user token obtained through the user authorization flow
17
+ # @see https://develop.battle.net/documentation/guides/using-oauth/authorization-code-flow
18
+ #
19
+ # @param realm [String] The character realm's slug
20
+ # @param character [String] The character name
21
+ # @param user_token [String] A token obtained by the authorization flow. See link below.
22
+ # @param season [Integer] Season ID if you want only a specific season or nil to include all.
23
+ # @!macro request_options
24
+ #
25
+ # @!macro response
26
+ def get_keystone_profile(realm, character, user_token, season = nil, options = {})
27
+ url = "#{endpoint_uri(realm, character)}/mythic-keystone-profile"
28
+ url += "/season/#{season}" unless season.nil?
29
+ api_request url, default_options(user_token).merge(options)
30
+ end
31
+
32
+ ##
33
+ # Return the pvp summary of a character
34
+ #
35
+ # @note This endpoint requires a user token obtained through the user authorization flow
36
+ # @see https://develop.battle.net/documentation/guides/using-oauth/authorization-code-flow
37
+ #
38
+ # @param realm [String] The character realm's slug
39
+ # @param character [String] The character name
40
+ # @param user_token [String] A token obtained by the authorization flow. See link below.
41
+ # @!macro request_options
42
+ #
43
+ # @!macro response
44
+ def pvp_summmary(realm, character, user_token, options = {})
45
+ api_request "#{endpoint_uri(realm, character)}/pvp-summary", default_options(user_token).merge(options)
46
+ end
47
+
48
+ ##
49
+ # Return the pvp bracket of a character
50
+ #
51
+ # @note This endpoint requires a user token obtained through the user authorization flow
52
+ # @see https://develop.battle.net/documentation/guides/using-oauth/authorization-code-flow
53
+ #
54
+ # @param realm [String] The character realm's slug
55
+ # @param character [String] The character name
56
+ # @param bracket [String] Pvp bracket
57
+ # @param user_token [String] A token obtained by the authorization flow. See link below.
58
+ # @!macro request_options
59
+ #
60
+ # @!macro response
61
+ def pvp_bracket(realm, character, bracket, user_token, options = {})
62
+ api_request "#{endpoint_uri(realm, character)}/pvp-bracket/#{bracket}",
63
+ default_options(user_token).merge(options)
64
+ end
65
+
66
+ private
67
+
68
+ def default_options(user_token)
69
+ { ttl: CACHE_HOUR, namespace: endpoint_namespace(:profile), access_token: user_token }
70
+ end
71
+
72
+ def endpoint_uri(realm, character)
73
+ "#{base_url(:profile)}/character/#{CGI.escape(realm)}/#{CGI.escape(character)}"
74
+ end
75
+ end
76
+ end
77
+ end