blizzard_api 0.3.11 → 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +2 -1
  3. data/CHANGELOG.md +65 -0
  4. data/Gemfile.lock +23 -14
  5. data/README.md +45 -0
  6. data/blizzard_api.gemspec +2 -0
  7. data/lib/blizzard_api/diablo/community/item.rb +1 -1
  8. data/lib/blizzard_api/diablo/game_data/generic_data_endpoint.rb +2 -2
  9. data/lib/blizzard_api/diablo/request.rb +2 -2
  10. data/lib/blizzard_api/hearthstone/game_data/generic_data_endpoint.rb +2 -2
  11. data/lib/blizzard_api/hearthstone/request.rb +2 -2
  12. data/lib/blizzard_api/request.rb +46 -38
  13. data/lib/blizzard_api/starcraft/request.rb +2 -2
  14. data/lib/blizzard_api/version.rb +1 -1
  15. data/lib/blizzard_api/wow.rb +35 -0
  16. data/lib/blizzard_api/wow/game_data/azerite_essence.rb +2 -0
  17. data/lib/blizzard_api/wow/game_data/connected_realm.rb +2 -0
  18. data/lib/blizzard_api/wow/game_data/covenant.rb +79 -0
  19. data/lib/blizzard_api/wow/game_data/creature.rb +2 -0
  20. data/lib/blizzard_api/wow/game_data/generic_data_endpoint.rb +4 -4
  21. data/lib/blizzard_api/wow/game_data/item.rb +2 -0
  22. data/lib/blizzard_api/wow/game_data/journal.rb +15 -0
  23. data/lib/blizzard_api/wow/game_data/media.rb +37 -0
  24. data/lib/blizzard_api/wow/game_data/modified_crafting.rb +67 -0
  25. data/lib/blizzard_api/wow/game_data/mount.rb +2 -0
  26. data/lib/blizzard_api/wow/game_data/pet.rb +46 -0
  27. data/lib/blizzard_api/wow/game_data/realm.rb +2 -0
  28. data/lib/blizzard_api/wow/game_data/spell.rb +2 -0
  29. data/lib/blizzard_api/wow/game_data/tech_talent.rb +57 -0
  30. data/lib/blizzard_api/wow/profile/character_profile.rb +19 -1
  31. data/lib/blizzard_api/wow/profile/guild.rb +2 -0
  32. data/lib/blizzard_api/wow/profile/profile.rb +2 -2
  33. data/lib/blizzard_api/wow/request.rb +2 -2
  34. data/lib/blizzard_api/wow/search/search_composer.rb +97 -0
  35. data/lib/blizzard_api/wow/search/search_request.rb +24 -0
  36. data/lib/blizzard_api/wow/slug.rb +12 -0
  37. metadata +43 -8
@@ -0,0 +1,57 @@
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 TechTalent < Wow::GenericDataEndpoint
13
+ ##
14
+ # Fetch tech talent trees
15
+ #
16
+ # @!macro request_options
17
+ #
18
+ # @!macro response
19
+ def tech_talent_trees(options = {})
20
+ api_request "#{base_url(:game_data)}/tech-talent-tree/index", default_options.merge(options)
21
+ end
22
+
23
+ ##
24
+ # Fetch a tech talent tree
25
+ #
26
+ # @param id [Integer] Tech talent id
27
+ #
28
+ # @!macro request_options
29
+ #
30
+ # @!macro response
31
+ def tech_talent_tree(id, options = {})
32
+ api_request "#{base_url(:game_data)}/tech-talent-tree/#{id}", default_options.merge(options)
33
+ end
34
+
35
+ ##
36
+ # Fetch a tech talent media
37
+ #
38
+ # @param id [Integer] Tech talent id
39
+ #
40
+ # @!macro request_options
41
+ #
42
+ # @!macro response
43
+ def media(id, options = {})
44
+ api_request "#{base_url(:media)}/tech-talent/#{id}", default_options.merge(options)
45
+ end
46
+
47
+ protected
48
+
49
+ def endpoint_setup
50
+ @endpoint = 'tech-talent'
51
+ @namespace = :static
52
+ @collection = 'tech-talents'
53
+ @ttl = CACHE_TRIMESTER
54
+ end
55
+ end
56
+ end
57
+ end
@@ -10,6 +10,8 @@ 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
+ include BlizzardApi::Wow::Slug
14
+
13
15
  ##
14
16
  # Return character achievements
15
17
  #
@@ -287,9 +289,11 @@ module BlizzardApi
287
289
  # @param realm [String] The character realm's slug
288
290
  # @param character [String] The character name
289
291
  # @!macro request_options
292
+ # @option options [Boolean] :completed Should return completed quests
290
293
  #
291
294
  # @!macro response
292
- def quests(realm, character, completed = false, options = {})
295
+ def quests(realm, character, options = {})
296
+ completed = options.delete(:completed) || false
293
297
  return character_request realm, character, options, 'quests/completed' if completed
294
298
 
295
299
  character_request realm, character, options, 'quests'
@@ -309,6 +313,20 @@ module BlizzardApi
309
313
  character_request realm, character, options, 'reputations'
310
314
  end
311
315
 
316
+ ##
317
+ # Return a character's soulbinds
318
+ #
319
+ # @see https://develop.battle.net/documentation/api-reference/world-of-warcraft-profile-api
320
+ #
321
+ # @param realm [String] The character realm's slug
322
+ # @param character [String] The character name
323
+ # @!macro request_options
324
+ #
325
+ # @!macro response
326
+ def soulbinds(realm, character, options = {})
327
+ character_request realm, character, options, 'soulbinds'
328
+ end
329
+
312
330
  ##
313
331
  # Return a character's specialization
314
332
  #
@@ -10,6 +10,8 @@ module BlizzardApi
10
10
  # You can get an instance of this class using the default region as follows:
11
11
  # api_instance = BlizzardApi::Wow.guild
12
12
  class Guild < Wow::Request
13
+ include BlizzardApi::Wow::Slug
14
+
13
15
  ##
14
16
  # Return data about the specified guild
15
17
  #
@@ -7,8 +7,8 @@ module BlizzardApi
7
7
  class AccountProfile < Request
8
8
  ##
9
9
  # @param token [String] A token obtained using the authorization_code flow
10
- def initialize(token, region = nil)
11
- super region
10
+ def initialize(token, region = nil, mode = :regular)
11
+ super region, mode
12
12
  @token = token
13
13
  end
14
14
 
@@ -7,8 +7,8 @@ module BlizzardApi
7
7
  class Request < BlizzardApi::Request
8
8
  ##
9
9
  # @!macro regions
10
- def initialize(region = nil)
11
- super region
10
+ def initialize(region = nil, mode = :regular)
11
+ super region, mode
12
12
  @game = 'wow'
13
13
  end
14
14
  end
@@ -0,0 +1,97 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BlizzardApi
4
+ module Wow
5
+ ##
6
+ # Composer for search endpoint arguments
7
+ class SearchComposer
8
+ attr_accessor :fields, :order, :page, :page_size
9
+
10
+ def initialize(page, page_size)
11
+ self.page = page
12
+ self.page_size = page_size
13
+ self.fields = []
14
+ self.order = []
15
+ end
16
+
17
+ ##
18
+ # Add a search field
19
+ #
20
+ # The second argument takes a simple value, an array of values or a hash for range searches.
21
+ #
22
+ # @param field [String] Field name
23
+ # @param value [String|Integer|Hash|Array<Integer>|Array<String>]
24
+ # @option value [Integer] :min Range start
25
+ # @option value [Integer] :max Range end
26
+ # @option value [Integer] :mode Range mode (:inclusive|:exclusive)
27
+ #
28
+ # @return {SearchComposer}
29
+ def where(field, value)
30
+ fields.push "#{field}=#{resolve_value(value)}"
31
+ self
32
+ end
33
+
34
+ ##
35
+ # Add a search field
36
+ #
37
+ # The second argument takes a simple value, an array of values or a hash for range searches.
38
+ #
39
+ # @param field [String] Field name
40
+ # @param value [String|Integer|Hash|Array<Integer>|Array<String>]
41
+ # @option value [Integer] :min Range start
42
+ # @option value [Integer] :max Range end
43
+ # @option value [Integer] :mode Range mode (:inclusive|:exclusive)
44
+ #
45
+ # @return {SearchComposer}
46
+ def where_not(field, value)
47
+ fields.push "#{field}!=#{resolve_value(value)}"
48
+ self
49
+ end
50
+
51
+ ##
52
+ # Add a sort field
53
+ #
54
+ # @param field [String] Field name
55
+ # @param mode [Symbol] :asc or :desc
56
+ #
57
+ # @return {SearchComposer}
58
+ def order_by(field, mode = :asc)
59
+ raise ArgumentError, 'Invalid order mode.' unless %i[asc desc].include? mode
60
+
61
+ order.push "#{field}:#{mode}"
62
+ self
63
+ end
64
+
65
+ ##
66
+ # Returns a valid queryString based on the options
67
+ #
68
+ # @return {String}
69
+ def to_search_query
70
+ query_string = "_page=#{page}&_pageSize=#{page_size}"
71
+ query_string += "&#{fields.join('&')}" unless fields.size.zero?
72
+ query_string += "&orderby=#{order.join(',')}" unless order.size.zero?
73
+ query_string
74
+ end
75
+
76
+ protected
77
+
78
+ def resolve_value(value)
79
+ return value.join '||' if value.is_a? Array
80
+
81
+ return value.to_s unless value.is_a? Hash
82
+
83
+ resolve_hash value
84
+ end
85
+
86
+ def resolve_hash(value)
87
+ min = value.key?(:min) ? value[:min] : ''
88
+ max = value.key?(:max) ? value[:max] : ''
89
+ mode = value.key?(:mode) ? value[:mode] : :inclusive
90
+
91
+ return "[#{min},#{max}]" if mode.eql? :inclusive
92
+
93
+ "(#{min},#{max})"
94
+ end
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BlizzardApi
4
+ module Wow
5
+ ##
6
+ # Added search support to an endpoint
7
+ module Searchable
8
+ ##
9
+ # Fetch data based on search criteria
10
+ #
11
+ # @param page [Integer] Page o return
12
+ # @param page_size [Integer] Amount of items per page
13
+ #
14
+ # @!macro request_options
15
+ # @!macro response
16
+ def search(page = 1, page_size = 100, options = {})
17
+ search_options = SearchComposer.new(page, page_size)
18
+ yield search_options if block_given?
19
+
20
+ api_request "#{endpoint_uri(nil, :search)}?#{search_options.to_search_query}", default_options.merge(options)
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BlizzardApi
4
+ module Wow
5
+ # Support for slugs
6
+ module Slug
7
+ def string_to_slug(string)
8
+ CGI.escape(string.downcase.tr(' ', '-'))
9
+ end
10
+ end
11
+ end
12
+ end
metadata CHANGED
@@ -1,35 +1,49 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blizzard_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.11
4
+ version: 0.5.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-04-17 00:00:00.000000000 Z
11
+ date: 2020-11-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: 4.1.0
20
17
  - - "~>"
21
18
  - !ruby/object:Gem::Version
22
19
  version: '4.1'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 4.1.0
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '4.1'
27
30
  - - ">="
28
31
  - !ruby/object:Gem::Version
29
32
  version: 4.1.0
30
- - - "~>"
33
+ - !ruby/object:Gem::Dependency
34
+ name: dotenv
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
31
38
  - !ruby/object:Gem::Version
32
- version: '4.1'
39
+ version: '0'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
33
47
  - !ruby/object:Gem::Dependency
34
48
  name: minitest
35
49
  requirement: !ruby/object:Gem::Requirement
@@ -72,6 +86,20 @@ dependencies:
72
86
  - - "~>"
73
87
  - !ruby/object:Gem::Version
74
88
  version: '0.61'
89
+ - !ruby/object:Gem::Dependency
90
+ name: yard
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
75
103
  description: This is a simple interface to obtain data from Blizzard API
76
104
  email:
77
105
  - francis.schiavo@francisschiavo.com
@@ -127,11 +155,14 @@ files:
127
155
  - lib/blizzard_api/wow/game_data/auction.rb
128
156
  - lib/blizzard_api/wow/game_data/azerite_essence.rb
129
157
  - lib/blizzard_api/wow/game_data/connected_realm.rb
158
+ - lib/blizzard_api/wow/game_data/covenant.rb
130
159
  - lib/blizzard_api/wow/game_data/creature.rb
131
160
  - lib/blizzard_api/wow/game_data/generic_data_endpoint.rb
132
161
  - lib/blizzard_api/wow/game_data/guild_crest.rb
133
162
  - lib/blizzard_api/wow/game_data/item.rb
134
163
  - lib/blizzard_api/wow/game_data/journal.rb
164
+ - lib/blizzard_api/wow/game_data/media.rb
165
+ - lib/blizzard_api/wow/game_data/modified_crafting.rb
135
166
  - lib/blizzard_api/wow/game_data/mount.rb
136
167
  - lib/blizzard_api/wow/game_data/mythic_keystone.rb
137
168
  - lib/blizzard_api/wow/game_data/mythic_keystone_affix.rb
@@ -151,12 +182,16 @@ files:
151
182
  - lib/blizzard_api/wow/game_data/reputation.rb
152
183
  - lib/blizzard_api/wow/game_data/spell.rb
153
184
  - lib/blizzard_api/wow/game_data/talent.rb
185
+ - lib/blizzard_api/wow/game_data/tech_talent.rb
154
186
  - lib/blizzard_api/wow/game_data/title.rb
155
187
  - lib/blizzard_api/wow/game_data/wow_token.rb
156
188
  - lib/blizzard_api/wow/profile/character_profile.rb
157
189
  - lib/blizzard_api/wow/profile/guild.rb
158
190
  - lib/blizzard_api/wow/profile/profile.rb
159
191
  - lib/blizzard_api/wow/request.rb
192
+ - lib/blizzard_api/wow/search/search_composer.rb
193
+ - lib/blizzard_api/wow/search/search_request.rb
194
+ - lib/blizzard_api/wow/slug.rb
160
195
  homepage: https://gitlab.com/francisschiavo/blizzard_api
161
196
  licenses:
162
197
  - MIT
@@ -179,7 +214,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
179
214
  - !ruby/object:Gem::Version
180
215
  version: '0'
181
216
  requirements: []
182
- rubygems_version: 3.0.6
217
+ rubygems_version: 3.1.2
183
218
  signing_key:
184
219
  specification_version: 4
185
220
  summary: Unofficial Ruby client for Blizzard Entertainment API