blizzard_api 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BlizzardApi
4
+ module Wow
5
+ ##
6
+ # This class allows access to World of Warcraft talent data
7
+ #
8
+ # @see https://develop.battle.net/documentation/world-of-warcraft/game-data-apis
9
+ #
10
+ # You can get an instance of this class using the default region as follows:
11
+ # api_instance = BlizzardApi::Wow.talent
12
+ class Talent < Wow::GenericDataEndpoint
13
+ ##
14
+ # Fetch pvp talents
15
+ #
16
+ # @!macro request_options
17
+ #
18
+ # @!macro response
19
+ def pvp_talents(options = {})
20
+ api_request "#{base_url(:game_data)}/pvp-talent/index", default_options.merge(options)
21
+ end
22
+
23
+ ##
24
+ # Fetch pvp a talent
25
+ #
26
+ # @param id [Integer] Pvp talent id
27
+ #
28
+ # @!macro request_options
29
+ #
30
+ # @!macro response
31
+ def pvp_talent(id, options = {})
32
+ api_request "#{base_url(:game_data)}/pvp-talent/#{id}", default_options.merge(options)
33
+ end
34
+
35
+ protected
36
+
37
+ def endpoint_setup
38
+ @endpoint = 'talent'
39
+ @namespace = :static
40
+ @collection = 'talents'
41
+ @ttl = CACHE_TRIMESTER
42
+ end
43
+ end
44
+ end
45
+ end
@@ -10,25 +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.achievement
12
12
  class CharacterProfile < Wow::Request
13
- # Valid fields for character profile requests
14
- VALID_FIELDS = %w[
15
- achievements appearance feed guild hunterPets items mounts pets petSlots professions progression
16
- pvp quests reputation statistics stats talents titles audit
17
- ].freeze
18
-
19
- ##
20
- # Helper method for checking valid fields. Use this to validate an array of fields if you are not sure about their
21
- # names.
22
- #
23
- # @param fields [Array<String>] Array containing desired fields to include
24
- #
25
- # @raise ArgumentError
26
- def validate_fields(fields)
27
- fields.each do |field|
28
- raise ArgumentError, "Unrecognized field #{field}" unless VALID_FIELDS.include? field
29
- end
30
- end
31
-
32
13
  ##
33
14
  # Return a list containing all WoW characters of a BNet account
34
15
  #
@@ -51,19 +32,11 @@ module BlizzardApi
51
32
  #
52
33
  # @param realm [String] The character realm's slug
53
34
  # @param character [String] The character name
54
- # @param fields [Array<String>] An array containing all the fields you want to be included in the response. Only
55
- # used for community endpoint.
56
35
  # @!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
59
36
  #
60
37
  # @!macro response
61
- def get(realm, character, fields = [], options = {})
62
- return character_request realm, character, options unless options.include? :use_community_endpoint
63
-
64
- validate_fields fields if options.include? :validate_fields
65
- opts = { ttl: CACHE_DAY, fields: fields.join(',') }.merge(options)
66
- api_request "#{base_url(:community)}/character/#{CGI.escape(realm)}/#{CGI.escape(character)}", opts
38
+ def get(realm, character, options = {})
39
+ character_request realm, character, options
67
40
  end
68
41
 
69
42
  ##
@@ -89,14 +62,24 @@ module BlizzardApi
89
62
  # @param realm [String] The character realm's slug
90
63
  # @param character [String] The character name
91
64
  # @!macro request_options
92
- # @option options [Boolean] :use_community_endpoint If set to true, this method will call the community endpoint
93
- # instead of the data endpoint https://develop.battle.net/documentation/api-reference/world-of-warcraft-community-api
94
65
  #
95
66
  # @!macro response
96
67
  def achievements(realm, character, options = {})
97
- return character_request realm, character, options, 'achievements' unless options.include? :use_community_endpoint
68
+ character_request realm, character, options, 'achievements'
69
+ end
98
70
 
99
- api_request "#{base_url(:community)}/data/guild/achievements", { ttl: CACHE_TRIMESTER }.merge(options)
71
+ ##
72
+ # Return character achievements statistics
73
+ #
74
+ # @see https://develop.battle.net/documentation/api-reference/world-of-warcraft-profile-api
75
+ #
76
+ # @param realm [String] The character realm's slug
77
+ # @param character [String] The character name
78
+ # @!macro request_options
79
+ #
80
+ # @!macro response
81
+ def achievement_statistics(realm, character, options = {})
82
+ character_request realm, character, options, 'achievements/statistics'
100
83
  end
101
84
 
102
85
  ##
@@ -170,6 +153,22 @@ module BlizzardApi
170
153
  character_request realm, character, options, 'pvp-summary'
171
154
  end
172
155
 
156
+ ##
157
+ # Return a character's quests
158
+ #
159
+ # @see https://develop.battle.net/documentation/api-reference/world-of-warcraft-profile-api
160
+ #
161
+ # @param realm [String] The character realm's slug
162
+ # @param character [String] The character name
163
+ # @!macro request_options
164
+ #
165
+ # @!macro response
166
+ def quests(realm, character, completed = false, options = {})
167
+ return character_request realm, character, options, 'quests/completed' if completed
168
+
169
+ character_request realm, character, options, 'quests'
170
+ end
171
+
173
172
  ##
174
173
  # Return a character's specialization
175
174
  #
@@ -5,29 +5,11 @@ module BlizzardApi
5
5
  ##
6
6
  # This class allows access to World of Warcraft guild data
7
7
  #
8
- # @see https://develop.battle.net/documentation/api-reference/world-of-warcraft-community-api
9
8
  # @see https://develop.battle.net/documentation/api-reference/world-of-warcraft-game-data-api
10
9
  #
11
10
  # You can get an instance of this class using the default region as follows:
12
11
  # api_instance = BlizzardApi::Wow.guild
13
12
  class Guild < Wow::Request
14
- # Valid fields for guild profile request
15
- VALID_FIELDS = %w[achievements achievementsCompleted achievementsCompletedTimestamp criteria criteriaCreated
16
- criteriaQuantity criteriaTimestamp challenge members news].freeze
17
-
18
- ##
19
- # Helper method for checking valid fields. Use this to validate an array of fields if you are not sure about their
20
- # names.
21
- #
22
- # @param fields [Array<String>] Array containing desired fields to include
23
- #
24
- # @raise ArgumentError
25
- def validate_fields(fields)
26
- fields.each do |field|
27
- raise ArgumentError, "Unrecognized field #{field}" unless VALID_FIELDS.include? field
28
- end
29
- end
30
-
31
13
  ##
32
14
  # Return a list with all possible rewards.
33
15
  #
@@ -53,18 +35,11 @@ module BlizzardApi
53
35
  #
54
36
  # @param realm [String] The guild realm's slug
55
37
  # @param guild [String] The guild's name
56
- # @param fields [Array<String>] An array containing all the fields you want to be included in the response.
57
38
  # @!macro request_options
58
- # @option options [Boolean] :use_community_endpoint If set to true, this method will call the community endpoint
59
- # instead of the data endpoint https://develop.battle.net/documentation/api-reference/world-of-warcraft-community-api
60
39
  #
61
40
  # @!macro response
62
- def get(realm, guild, options = {}, fields = [])
63
- return guild_request(realm, guild, options) unless options.include? :use_community_endpoint
64
-
65
- validate_fields fields if options.include? :validate_fields
66
- opts = { ttl: CACHE_DAY, fields: fields.join(',') }.merge(options)
67
- api_request "#{base_url(:community)}/guild/#{CGI.escape(realm)}/#{CGI.escape(guild)}", opts
41
+ def get(realm, guild, options = {})
42
+ guild_request(realm, guild, options)
68
43
  end
69
44
 
70
45
  ##
@@ -86,18 +61,24 @@ module BlizzardApi
86
61
  # @param realm [String] The guild realm's slug
87
62
  # @param guild [String] The guild's name
88
63
  # @!macro request_options
89
- # @option options [Boolean] :use_community_endpoint If set to true, this method will call the community endpoint
90
- # instead of the data endpoint https://develop.battle.net/documentation/api-reference/world-of-warcraft-community-api
91
64
  #
92
65
  # @!macro response
93
66
  def achievements(realm, guild, options = {})
94
- if options.include? :use_community_endpoint
95
- return api_request "#{base_url(:community)}/data/guild/achievements", { ttl: CACHE_TRIMESTER }.merge(options)
96
- end
97
-
98
67
  guild_request realm, guild, options, 'achievements'
99
68
  end
100
69
 
70
+ ##
71
+ # Return guild activity
72
+ #
73
+ # @param realm [String] The guild realm's slug
74
+ # @param guild [String] The guild's name
75
+ # @!macro request_options
76
+ #
77
+ # @!macro response
78
+ def activity(realm, guild, options = {})
79
+ guild_request realm, guild, options, 'activity'
80
+ end
81
+
101
82
  private
102
83
 
103
84
  def guild_request(realm, guild, options = {}, variant = nil)
@@ -0,0 +1,75 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BlizzardApi
4
+ module Wow
5
+ ##
6
+ # Simplifies the requests to Blizzard APIS
7
+ class AccountProfile < Request
8
+ ##
9
+ # @param token [String] A token obtained using the authorization_code flow
10
+ def initialize(token)
11
+ @token = token
12
+ end
13
+
14
+ ##
15
+ # Returns the account summary for WoW
16
+ #
17
+ # @!macro request_options
18
+ #
19
+ # @!macro response
20
+ def get(_options = {})
21
+ api_request base_url(:user_profile).to_s
22
+ end
23
+
24
+ ##
25
+ # Returns data for protected characters
26
+ #
27
+ # @!macro request_options
28
+ #
29
+ # @!macro response
30
+ def protected_character(realm_id, character_id, options = {})
31
+ api_request "#{base_url(:user_profile)}/protected-character/#{realm_id}-#{character_id}", default_options.merge(options)
32
+ end
33
+
34
+ ##
35
+ # Returns the collection index for the account
36
+ #
37
+ # @!macro request_options
38
+ #
39
+ # @!macro response
40
+ def collection(options = {})
41
+ api_request "#{base_url(:user_profile)}/collections", default_options.merge(options)
42
+ end
43
+
44
+ ##
45
+ # Returns the mount collection index for the account
46
+ #
47
+ # @!macro request_options
48
+ #
49
+ # @!macro response
50
+ def mounts(options = {})
51
+ api_request "#{base_url(:user_profile)}/collections/mounts", default_options.merge(options)
52
+ end
53
+
54
+ ##
55
+ # Returns the pet collection index for the account
56
+ #
57
+ # @!macro request_options
58
+ #
59
+ # @!macro response
60
+ def pets(options = {})
61
+ api_request "#{base_url(:user_profile)}/collections/pets", default_options.merge(options)
62
+ end
63
+
64
+ protected
65
+
66
+ def default_options
67
+ { ttl: CACHE_HOUR, namespace: :profile }
68
+ end
69
+
70
+ def api_request(_uri, query_string = nil)
71
+ query_string[:access_token] = @token
72
+ end
73
+ end
74
+ end
75
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blizzard_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Francis Schiavo
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-01-17 00:00:00.000000000 Z
11
+ date: 2020-02-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis
@@ -50,14 +50,14 @@ dependencies:
50
50
  requirements:
51
51
  - - "~>"
52
52
  - !ruby/object:Gem::Version
53
- version: '10.0'
53
+ version: '13.0'
54
54
  type: :development
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
57
57
  requirements:
58
58
  - - "~>"
59
59
  - !ruby/object:Gem::Version
60
- version: '10.0'
60
+ version: '13.0'
61
61
  - !ruby/object:Gem::Dependency
62
62
  name: rubocop
63
63
  requirement: !ruby/object:Gem::Requirement
@@ -117,22 +117,20 @@ files:
117
117
  - lib/blizzard_api/request.rb
118
118
  - lib/blizzard_api/version.rb
119
119
  - lib/blizzard_api/wow.rb
120
- - lib/blizzard_api/wow/community/auction.rb
121
120
  - lib/blizzard_api/wow/community/boss.rb
122
121
  - lib/blizzard_api/wow/community/challenge.rb
123
122
  - lib/blizzard_api/wow/community/pvp.rb
124
- - lib/blizzard_api/wow/community/quest.rb
125
123
  - lib/blizzard_api/wow/community/recipe.rb
126
- - lib/blizzard_api/wow/community/spell.rb
127
124
  - lib/blizzard_api/wow/community/zone.rb
128
125
  - lib/blizzard_api/wow/game_data/achievement.rb
126
+ - lib/blizzard_api/wow/game_data/auction.rb
129
127
  - lib/blizzard_api/wow/game_data/azerite_essence.rb
130
128
  - lib/blizzard_api/wow/game_data/connected_realm.rb
131
129
  - lib/blizzard_api/wow/game_data/creature.rb
132
130
  - lib/blizzard_api/wow/game_data/generic_data_endpoint.rb
133
- - lib/blizzard_api/wow/game_data/guild.rb
134
131
  - lib/blizzard_api/wow/game_data/guild_crest.rb
135
132
  - lib/blizzard_api/wow/game_data/item.rb
133
+ - lib/blizzard_api/wow/game_data/journal.rb
136
134
  - lib/blizzard_api/wow/game_data/mount.rb
137
135
  - lib/blizzard_api/wow/game_data/mythic_keystone.rb
138
136
  - lib/blizzard_api/wow/game_data/mythic_keystone_affix.rb
@@ -140,18 +138,22 @@ files:
140
138
  - lib/blizzard_api/wow/game_data/mythic_raid_leaderboard.rb
141
139
  - lib/blizzard_api/wow/game_data/pet.rb
142
140
  - lib/blizzard_api/wow/game_data/playable_class.rb
141
+ - lib/blizzard_api/wow/game_data/playable_race.rb
143
142
  - lib/blizzard_api/wow/game_data/playable_specialization.rb
144
143
  - lib/blizzard_api/wow/game_data/power_type.rb
145
144
  - lib/blizzard_api/wow/game_data/pvp_season.rb
146
145
  - lib/blizzard_api/wow/game_data/pvp_tier.rb
147
- - lib/blizzard_api/wow/game_data/race.rb
146
+ - lib/blizzard_api/wow/game_data/quest.rb
148
147
  - lib/blizzard_api/wow/game_data/realm.rb
149
148
  - lib/blizzard_api/wow/game_data/region.rb
150
- - lib/blizzard_api/wow/game_data/reputation_faction.rb
151
- - lib/blizzard_api/wow/game_data/reputation_tier.rb
149
+ - lib/blizzard_api/wow/game_data/reputation.rb
150
+ - lib/blizzard_api/wow/game_data/spell.rb
151
+ - lib/blizzard_api/wow/game_data/talent.rb
152
152
  - lib/blizzard_api/wow/game_data/title.rb
153
153
  - lib/blizzard_api/wow/game_data/wow_token.rb
154
154
  - lib/blizzard_api/wow/profile/character_profile.rb
155
+ - lib/blizzard_api/wow/profile/guild.rb
156
+ - lib/blizzard_api/wow/profile/profile.rb
155
157
  - lib/blizzard_api/wow/request.rb
156
158
  homepage: https://gitlab.com/francisschiavo/blizzard_api
157
159
  licenses:
@@ -1,27 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module BlizzardApi
4
- module Wow
5
- ##
6
- # This class allows access to World of Warcraft auctions
7
- #
8
- # @deprecated See https://us.forums.blizzard.com/en/blizzard/t/world-of-warcraft-community-api-migration/767
9
- #
10
- # @see https://develop.battle.net/documentation/api-reference/world-of-warcraft-community-api
11
- #
12
- # You can get an instance of this class using the default region as follows:
13
- # api_instance = BlizzardApi::Wow.auction
14
- class Auction < Wow::Request
15
- ##
16
- # Return a link to the most recent dump of all active auctions for the desired realm
17
- #
18
- # @param realm [String] Realm's slug
19
- # @!macro request_options
20
- #
21
- # @!macro response
22
- def get(realm, options = {})
23
- api_request "#{base_url(:community)}/auction/data/#{realm}", { ttl: CACHE_HOUR }.merge(options)
24
- end
25
- end
26
- end
27
- end
@@ -1,27 +0,0 @@
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
- # @deprecated See https://us.forums.blizzard.com/en/blizzard/t/world-of-warcraft-community-api-migration/767
11
- #
12
- # You can get an instance of this class using the default region as follows:
13
- # api_instance = BlizzardApi::Wow.quest
14
- class Quest < Wow::Request
15
- ##
16
- # Return information about a quest by its id
17
- #
18
- # @param id [Integer] Quest id
19
- # @!macro request_options
20
- #
21
- # @!macro response
22
- def get(id, options = {})
23
- api_request "#{base_url(:community)}/quest/#{id}", { ttl: CACHE_TRIMESTER }.merge(options)
24
- end
25
- end
26
- end
27
- end
@@ -1,27 +0,0 @@
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
- # @deprecated See https://us.forums.blizzard.com/en/blizzard/t/world-of-warcraft-community-api-migration/767
11
- #
12
- # You can get an instance of this class using the default region as follows:
13
- # api_instance = BlizzardApi::Wow.spell
14
- class Spell < Wow::Request
15
- ##
16
- # Return information about a spell by its id
17
- #
18
- # @param id [Integer] Spell id
19
- # @!macro request_options
20
- #
21
- # @!macro response
22
- def get(id, options = {})
23
- api_request "#{base_url(:community)}/spell/#{id}", { ttl: CACHE_TRIMESTER }.merge(options)
24
- end
25
- end
26
- end
27
- end