blizzard_api 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -60,28 +60,7 @@ module BlizzardApi
60
60
 
61
61
  opts = { ttl: CACHE_DAY, fields: fields.join(',') }.merge(options)
62
62
 
63
- api_request "#{base_url(:community)}/character/#{realm}/#{URI.encode(character)}", opts
64
- end
65
-
66
- ##
67
- # Return the mythic keystone profile of a character
68
- #
69
- # @note This endpoint requires a user token obtained through the user authorization flow
70
- # @see https://develop.battle.net/documentation/guides/using-oauth/authorization-code-flow
71
- #
72
- # @param realm [String] The character realm's slug
73
- # @param character [String] The character name
74
- # @param user_token [String] A token obtained by the authorization flow. See link below.
75
- # @param season [Integer] Season ID if you want only a specific season or nil to include all.
76
- # @!macro request_options
77
- #
78
- # @!macro response
79
- def get_keystone_profile(realm, character, user_token, season = nil, options = {})
80
- opts = { ttl: CACHE_HOUR, namespace: "profile-#{region}" }.merge(options)
81
- opts[:access_token] = user_token
82
- url = "#{base_url(:profile)}/character/#{realm}/#{URI.encode(character)}/mythic-keystone-profile"
83
- url += "/season/#{season}" unless season.nil?
84
- api_request url, opts
63
+ api_request "#{base_url(:community)}/character/#{CGI.escape(realm)}/#{CGI.escape(character)}", opts
85
64
  end
86
65
 
87
66
  ##
@@ -0,0 +1,101 @@
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.achievement
12
+ class Achievement < Wow::GenericDataEndpoint
13
+ ##
14
+ # Fetch all possible data for one of the items listed by the {#index} using its *id*
15
+ #
16
+ # @param id [Integer] One of the IDs returned by the {#index}
17
+ #
18
+ # @!macro request_options
19
+ # @option options [Boolean] :use_community_endpoint If set to true, this method will call the community endpoint
20
+ # instead of the data endpoint https://develop.battle.net/documentation/api-reference/world-of-warcraft-community-api
21
+ #
22
+ # @!macro response
23
+ def get(id, options = {})
24
+ return super id, options unless options.include? :use_community_endpoint
25
+
26
+ api_request "#{base_url(:community)}/achievement/#{id}", { ttl: CACHE_TRIMESTER }.merge(options)
27
+ end
28
+
29
+ ##
30
+ # This method overrides the inherited default behavior to prevent high server load and fetch time
31
+ #
32
+ # @!macro response
33
+ def complete
34
+ raise BlizzardApi::ApiException, 'There are too many achievements to fetch complete data'
35
+ end
36
+
37
+ ##
38
+ # Return a list of possible achievement categories.
39
+ #
40
+ # @!macro request_options
41
+ #
42
+ # @!macro response
43
+ def categories(options = {})
44
+ api_request "#{endpoint_uri('category')}/index", default_options.merge(options)
45
+ end
46
+
47
+ ##
48
+ # Return a achievement category.
49
+ #
50
+ # @!macro request_options
51
+ #
52
+ # @!macro response
53
+ def category(id, options = {})
54
+ api_request "#{endpoint_uri('category')}/#{id}", default_options.merge(options)
55
+ end
56
+
57
+ ##
58
+ # Return a list of possible character achievements.
59
+ # This endpoint uses a community endpoint. It is recommended to use the new data endpoint using {#index}.
60
+ # @see https://us.battle.net/forums/en/bnet/topic/20771546990
61
+ #
62
+ # @!macro request_options
63
+ #
64
+ # @!macro response
65
+ def character_achievement_index(options = {})
66
+ api_request "#{base_url(:community)}/data/character/achievements", { ttl: CACHE_TRIMESTER }.merge(options)
67
+ end
68
+
69
+ ##
70
+ # Return a list of possible guild achievements
71
+ # This endpoint uses a community endpoint. It is recommended to use the new data endpoint using {#index}.
72
+ # @see https://us.battle.net/forums/en/bnet/topic/20771546990
73
+ #
74
+ # @!macro request_options
75
+ #
76
+ # @!macro response
77
+ def guild_achievement_index(options = {})
78
+ api_request "#{base_url(:community)}/data/guild/achievements", { ttl: CACHE_TRIMESTER }.merge(options)
79
+ end
80
+
81
+ ##
82
+ # Fetch media assets for the specified achievement
83
+ #
84
+ # @!macro request_options
85
+ #
86
+ # @!macro response
87
+ def media(id, options = {})
88
+ api_request "#{base_url(:media)}/achievement/#{id}", default_options.merge(options)
89
+ end
90
+
91
+ protected
92
+
93
+ def endpoint_setup
94
+ @endpoint = 'achievement'
95
+ @namespace = endpoint_namespace :static
96
+ @collection = 'achievements'
97
+ @ttl = CACHE_TRIMESTER
98
+ end
99
+ end
100
+ end
101
+ end
@@ -8,22 +8,8 @@ module BlizzardApi
8
8
  # @see https://develop.battle.net/documentation/api-reference/world-of-warcraft-game-data-api
9
9
  #
10
10
  # You can get an instance of this class using the default region as follows:
11
- # api_instance = BlizzardApi::Wow.connected_realms
11
+ # api_instance = BlizzardApi::Wow.connected_realm
12
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
13
  protected
28
14
 
29
15
  def endpoint_setup
@@ -0,0 +1,99 @@
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.creature
12
+ class Creature < Wow::GenericDataEndpoint
13
+ def index
14
+ raise BlizzardApi::ApiException, 'Creatures endpoint doesn\'t have a index 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 creature families
23
+ #
24
+ # @!macro request_options
25
+ #
26
+ # @!macro response
27
+ def families(options = {})
28
+ api_request "#{endpoint_uri('family')}/index", default_options.merge(options)
29
+ end
30
+
31
+ ##
32
+ # Fetch all possible data for one of the items listed by the {#families} using its *id*
33
+ #
34
+ # @param id [Integer] Creature family id
35
+ #
36
+ # @!macro request_options
37
+ #
38
+ # @!macro response
39
+ def family(id, options = {})
40
+ api_request "#{endpoint_uri('family')}/#{id}", default_options.merge(options)
41
+ end
42
+
43
+ ##
44
+ # Fetch media for one of the items listed by the {#families} using its *id*
45
+ #
46
+ # @param id [Integer] Creature family id
47
+ #
48
+ # @!macro request_options
49
+ #
50
+ # @!macro response
51
+ def family_media(id, options = {})
52
+ api_request "#{base_url(:media)}/creature-family/#{id}", default_options.merge(options)
53
+ end
54
+
55
+ ##
56
+ # Fetch all creature types
57
+ #
58
+ # @!macro request_options
59
+ #
60
+ # @!macro response
61
+ def types(options = {})
62
+ api_request "#{endpoint_uri('type')}/index", default_options.merge(options)
63
+ end
64
+
65
+ ##
66
+ # Fetch all possible data for one of the items listed by the {#types} using its *id*
67
+ #
68
+ # @param id [Integer] Creature type id
69
+ #
70
+ # @!macro request_options
71
+ #
72
+ # @!macro response
73
+ def type(id, options = {})
74
+ api_request "#{endpoint_uri('type')}/#{id}", default_options.merge(options)
75
+ end
76
+
77
+ ##
78
+ # Fetch media for one of the items listed by the {#types} using its *id*
79
+ #
80
+ # @param id [Integer] Creature type id
81
+ #
82
+ # @!macro request_options
83
+ #
84
+ # @!macro response
85
+ def display_media(id, options = {})
86
+ api_request "#{base_url(:media)}/creature-display/#{id}", default_options.merge(options)
87
+ end
88
+
89
+ protected
90
+
91
+ def endpoint_setup
92
+ @endpoint = 'creature'
93
+ @namespace = endpoint_namespace :static
94
+ @collection = 'achievements'
95
+ @ttl = CACHE_TRIMESTER
96
+ end
97
+ end
98
+ end
99
+ end
@@ -19,33 +19,40 @@ module BlizzardApi
19
19
  # @!macro request_options
20
20
  # @!macro response
21
21
  def index(options = {})
22
- api_request "#{base_url(:game_data)}/#{@endpoint}/index", default_options.merge(options)
22
+ api_request "#{endpoint_uri}/index", default_options.merge(options)
23
23
  end
24
24
 
25
25
  ##
26
- # Fetch all possible data for one of items listed by the {#index} using its *id*
26
+ # Fetch all possible data for one of the items listed by the {#index} using its *id*
27
27
  #
28
28
  # @param id [Integer] One of the IDs returned by the {#index}
29
29
  # @!macro request_options
30
30
  #
31
31
  # @!macro response
32
32
  def get(id, options = {})
33
- api_request "#{base_url(:game_data)}/#{@endpoint}/#{id}", default_options.merge(options)
33
+ api_request "#{endpoint_uri}/#{id}", default_options.merge(options)
34
34
  end
35
35
 
36
36
  ##
37
37
  # @!macro complete
38
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'
39
+ [].tap do |complete_data|
40
+ index_data = index options
41
+ index_data[@collection.to_sym].each do |item|
42
+ link = item.key?(:key) ? item[:key][:href] : item[:href]
43
+ item_data = request link
44
+ complete_data.push item_data
43
45
  end
44
46
  end
45
47
  end
46
48
 
47
49
  protected
48
50
 
51
+ def endpoint_uri(variant = nil)
52
+ endpoint = variant ? "#{@endpoint}-#{variant}" : @endpoint
53
+ "#{base_url(:game_data)}/#{endpoint}"
54
+ end
55
+
49
56
  def endpoint_setup
50
57
  raise NotImplementedError, 'You must override this method to properly set up the endpoint'
51
58
  end
@@ -6,6 +6,7 @@ module BlizzardApi
6
6
  # This class allows access to World of Warcraft guild data
7
7
  #
8
8
  # @see https://develop.battle.net/documentation/api-reference/world-of-warcraft-community-api
9
+ # @see https://develop.battle.net/documentation/api-reference/world-of-warcraft-game-data-api
9
10
  #
10
11
  # You can get an instance of this class using the default region as follows:
11
12
  # api_instance = BlizzardApi::Wow.guild
@@ -53,14 +54,52 @@ module BlizzardApi
53
54
  # @param guild [String] The guild's name
54
55
  # @param fields [Array<String>] An array containing all the fields you want to be included in the response.
55
56
  # @!macro request_options
57
+ # @option options [Boolean] :use_community_endpoint If set to true, this method will call the community endpoint
58
+ # instead of the data endpoint https://develop.battle.net/documentation/api-reference/world-of-warcraft-community-api
56
59
  #
57
60
  # @!macro response
58
- def get(realm, guild, fields = [], options = {})
59
- validate_fields fields if options.include? :validate_fields
61
+ def get(realm, guild, options = {}, fields = [])
62
+ return guild_request(realm, guild, options) unless options.include? :use_community_endpoint
60
63
 
64
+ validate_fields fields if options.include? :validate_fields
61
65
  opts = { ttl: CACHE_DAY, fields: fields.join(',') }.merge(options)
66
+ api_request "#{base_url(:community)}/guild/#{CGI.escape(realm)}/#{CGI.escape(guild)}", opts
67
+ end
68
+
69
+ ##
70
+ # Return all guild members for a specified guild
71
+ #
72
+ # @param realm [String] The guild realm's slug
73
+ # @param guild [String] The guild's name
74
+ #
75
+ # @!macro request_options
76
+ #
77
+ # @!macro response
78
+ def roster(realm, guild, options = {})
79
+ guild_request realm, guild, options, 'roster'
80
+ end
81
+
82
+ ##
83
+ # Return all guild achievements for a specified guild
84
+ #
85
+ # @param realm [String] The guild realm's slug
86
+ # @param guild [String] The guild's name
87
+ #
88
+ # @!macro request_options
89
+ #
90
+ # @!macro response
91
+ def achievements(realm, guild, options = {})
92
+ guild_request realm, guild, options, 'achievements'
93
+ end
94
+
95
+ private
62
96
 
63
- api_request "#{base_url(:community)}/guild/#{realm}/#{URI.encode(guild)}", opts
97
+ def guild_request(realm, guild, options = {}, variant = nil)
98
+ realm = CGI.escape string_to_slug(realm)
99
+ guild = CGI.escape string_to_slug(guild)
100
+ url = "#{base_url(:game_data)}/guild/#{realm}/#{guild}"
101
+ url += "/#{variant}" if variant
102
+ api_request url, { ttl: CACHE_DAY, namespace: endpoint_namespace(:profile) }.merge(options)
64
103
  end
65
104
  end
66
105
  end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BlizzardApi
4
+ module Wow
5
+ ##
6
+ # This class allows access to World of Warcraft guild crest 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.guild_crest
12
+ class GuildCrest < Wow::GenericDataEndpoint
13
+ def get
14
+ raise BlizzardApi::ApiException, 'This endpoint doens\'t have a get method'
15
+ end
16
+
17
+ ##
18
+ # Return guild border assets by its id
19
+ #
20
+ # @param id [Integer] Border id
21
+ #
22
+ # @!macro request_options
23
+ #
24
+ # @!macro response
25
+ def border_media(id, options = {})
26
+ api_request "#{base_url(:media)}/#{@endpoint}/border/#{id}", default_options.merge(options)
27
+ end
28
+
29
+ ##
30
+ # Return guild embelm assets by its id
31
+ #
32
+ # @param id [Integer] Emblem id
33
+ #
34
+ # @!macro request_options
35
+ #
36
+ # @!macro response
37
+ def emblem_media(id, options = {})
38
+ api_request "#{base_url(:media)}/#{@endpoint}/emblem/#{id}", default_options.merge(options)
39
+ end
40
+
41
+ protected
42
+
43
+ def endpoint_setup
44
+ @endpoint = 'guild-crest'
45
+ @namespace = endpoint_namespace(:static)
46
+ @ttl = CACHE_TRIMESTER
47
+ end
48
+ end
49
+ end
50
+ 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 mounts
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.mount
12
+ class Mount < Wow::GenericDataEndpoint
13
+ ##
14
+ # Returns a index of mounts
15
+ #
16
+ # @!macro request_options
17
+ # @option options [Boolean] :use_community_endpoint If set to true, this method will call the community endpoint
18
+ # instead of the data endpoint https://develop.battle.net/documentation/api-reference/world-of-warcraft-community-api
19
+ #
20
+ # @!macro response
21
+ def index(options = {})
22
+ return super options unless options.include? :use_community_endpoint
23
+
24
+ api_request "#{base_url(:community)}/mount/", { ttl: CACHE_TRIMESTER }.merge(options)
25
+ end
26
+
27
+ protected
28
+
29
+ def endpoint_setup
30
+ @endpoint = 'mount'
31
+ @namespace = endpoint_namespace :static
32
+ @collection = 'mounts'
33
+ @ttl = CACHE_TRIMESTER
34
+ end
35
+ end
36
+ end
37
+ end