blizzard_api_rb_rb 3.4.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 (101) hide show
  1. checksums.yaml +7 -0
  2. data/.github/workflows/ruby.yml +22 -0
  3. data/.gitignore +12 -0
  4. data/.rubocop.yml +18 -0
  5. data/.rubocop_todo.yml +7 -0
  6. data/CHANGELOG.md +269 -0
  7. data/Gemfile +8 -0
  8. data/Gemfile.lock +50 -0
  9. data/LICENSE.txt +21 -0
  10. data/README.md +200 -0
  11. data/Rakefile +12 -0
  12. data/bin/console +14 -0
  13. data/bin/setup +8 -0
  14. data/blizzard_api_rb.gemspec +44 -0
  15. data/lib/blizzard_api_rb/api_response.rb +27 -0
  16. data/lib/blizzard_api_rb/api_standards.rb +55 -0
  17. data/lib/blizzard_api_rb/configuration.rb +93 -0
  18. data/lib/blizzard_api_rb/diablo/community/act.rb +35 -0
  19. data/lib/blizzard_api_rb/diablo/community/artisan.rb +38 -0
  20. data/lib/blizzard_api_rb/diablo/community/character_class.rb +38 -0
  21. data/lib/blizzard_api_rb/diablo/community/follower.rb +25 -0
  22. data/lib/blizzard_api_rb/diablo/community/item.rb +25 -0
  23. data/lib/blizzard_api_rb/diablo/community/item_type.rb +35 -0
  24. data/lib/blizzard_api_rb/diablo/community/profile.rb +83 -0
  25. data/lib/blizzard_api_rb/diablo/game_data/era.rb +21 -0
  26. data/lib/blizzard_api_rb/diablo/game_data/generic_data_endpoint.rb +58 -0
  27. data/lib/blizzard_api_rb/diablo/game_data/season.rb +21 -0
  28. data/lib/blizzard_api_rb/diablo/request.rb +15 -0
  29. data/lib/blizzard_api_rb/diablo.rb +91 -0
  30. data/lib/blizzard_api_rb/exception.rb +14 -0
  31. data/lib/blizzard_api_rb/hearthstone/game_data/back.rb +59 -0
  32. data/lib/blizzard_api_rb/hearthstone/game_data/card.rb +111 -0
  33. data/lib/blizzard_api_rb/hearthstone/game_data/deck.rb +30 -0
  34. data/lib/blizzard_api_rb/hearthstone/game_data/generic_data_endpoint.rb +49 -0
  35. data/lib/blizzard_api_rb/hearthstone/game_data/metadata.rb +22 -0
  36. data/lib/blizzard_api_rb/hearthstone/request.rb +15 -0
  37. data/lib/blizzard_api_rb/hearthstone.rb +49 -0
  38. data/lib/blizzard_api_rb/overwatch_league/community/matches.rb +22 -0
  39. data/lib/blizzard_api_rb/overwatch_league/community/players.rb +22 -0
  40. data/lib/blizzard_api_rb/overwatch_league/community/segments.rb +22 -0
  41. data/lib/blizzard_api_rb/overwatch_league/community/summary.rb +22 -0
  42. data/lib/blizzard_api_rb/overwatch_league/community/teams.rb +22 -0
  43. data/lib/blizzard_api_rb/overwatch_league/request.rb +15 -0
  44. data/lib/blizzard_api_rb/overwatch_league.rb +50 -0
  45. data/lib/blizzard_api_rb/request.rb +189 -0
  46. data/lib/blizzard_api_rb/starcraft/community/account.rb +23 -0
  47. data/lib/blizzard_api_rb/starcraft/community/ladder.rb +34 -0
  48. data/lib/blizzard_api_rb/starcraft/community/legacy.rb +87 -0
  49. data/lib/blizzard_api_rb/starcraft/community/profile.rb +76 -0
  50. data/lib/blizzard_api_rb/starcraft/game_data/league.rb +27 -0
  51. data/lib/blizzard_api_rb/starcraft/request.rb +36 -0
  52. data/lib/blizzard_api_rb/starcraft.rb +57 -0
  53. data/lib/blizzard_api_rb/token_manager.rb +49 -0
  54. data/lib/blizzard_api_rb/version.rb +6 -0
  55. data/lib/blizzard_api_rb/wow/game_data/achievement.rb +46 -0
  56. data/lib/blizzard_api_rb/wow/game_data/auction.rb +50 -0
  57. data/lib/blizzard_api_rb/wow/game_data/azerite_essence.rb +30 -0
  58. data/lib/blizzard_api_rb/wow/game_data/connected_realm.rb +18 -0
  59. data/lib/blizzard_api_rb/wow/game_data/covenant.rb +72 -0
  60. data/lib/blizzard_api_rb/wow/game_data/creature.rb +102 -0
  61. data/lib/blizzard_api_rb/wow/game_data/generic_data_endpoint.rb +50 -0
  62. data/lib/blizzard_api_rb/wow/game_data/guild_crest.rb +48 -0
  63. data/lib/blizzard_api_rb/wow/game_data/heirloom.rb +16 -0
  64. data/lib/blizzard_api_rb/wow/game_data/item.rb +102 -0
  65. data/lib/blizzard_api_rb/wow/game_data/journal.rb +110 -0
  66. data/lib/blizzard_api_rb/wow/game_data/media.rb +26 -0
  67. data/lib/blizzard_api_rb/wow/game_data/modified_crafting.rb +60 -0
  68. data/lib/blizzard_api_rb/wow/game_data/mount.rb +18 -0
  69. data/lib/blizzard_api_rb/wow/game_data/mythic_keystone.rb +86 -0
  70. data/lib/blizzard_api_rb/wow/game_data/mythic_keystone_affix.rb +28 -0
  71. data/lib/blizzard_api_rb/wow/game_data/mythic_keystone_leaderboard.rb +48 -0
  72. data/lib/blizzard_api_rb/wow/game_data/mythic_raid_leaderboard.rb +28 -0
  73. data/lib/blizzard_api_rb/wow/game_data/pet.rb +62 -0
  74. data/lib/blizzard_api_rb/wow/game_data/playable_class.rb +39 -0
  75. data/lib/blizzard_api_rb/wow/game_data/playable_race.rb +16 -0
  76. data/lib/blizzard_api_rb/wow/game_data/playable_specialization.rb +65 -0
  77. data/lib/blizzard_api_rb/wow/game_data/power_type.rb +16 -0
  78. data/lib/blizzard_api_rb/wow/game_data/profession.rb +65 -0
  79. data/lib/blizzard_api_rb/wow/game_data/pvp_region.rb +82 -0
  80. data/lib/blizzard_api_rb/wow/game_data/pvp_season.rb +53 -0
  81. data/lib/blizzard_api_rb/wow/game_data/pvp_tier.rb +26 -0
  82. data/lib/blizzard_api_rb/wow/game_data/quest.rb +79 -0
  83. data/lib/blizzard_api_rb/wow/game_data/realm.rb +18 -0
  84. data/lib/blizzard_api_rb/wow/game_data/region.rb +16 -0
  85. data/lib/blizzard_api_rb/wow/game_data/reputation.rb +74 -0
  86. data/lib/blizzard_api_rb/wow/game_data/spell.rb +38 -0
  87. data/lib/blizzard_api_rb/wow/game_data/talent.rb +75 -0
  88. data/lib/blizzard_api_rb/wow/game_data/tech_talent.rb +50 -0
  89. data/lib/blizzard_api_rb/wow/game_data/title.rb +16 -0
  90. data/lib/blizzard_api_rb/wow/game_data/toy.rb +16 -0
  91. data/lib/blizzard_api_rb/wow/game_data/wow_token.rb +20 -0
  92. data/lib/blizzard_api_rb/wow/profile/account_profile.rb +97 -0
  93. data/lib/blizzard_api_rb/wow/profile/character_profile.rb +415 -0
  94. data/lib/blizzard_api_rb/wow/profile/guild.rb +75 -0
  95. data/lib/blizzard_api_rb/wow/request.rb +16 -0
  96. data/lib/blizzard_api_rb/wow/search/search_composer.rb +97 -0
  97. data/lib/blizzard_api_rb/wow/search/search_request.rb +24 -0
  98. data/lib/blizzard_api_rb/wow/slug.rb +12 -0
  99. data/lib/blizzard_api_rb/wow.rb +335 -0
  100. data/lib/blizzard_api_rb.rb +26 -0
  101. metadata +237 -0
@@ -0,0 +1,415 @@
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
+ include BlizzardApi::Wow::Slug
14
+
15
+ ##
16
+ # Return character basic data
17
+ #
18
+ # @see https://develop.battle.net/documentation/api-reference/world-of-warcraft-profile-api
19
+ #
20
+ # @param realm [String] The character realm's slug
21
+ # @param character [String] The character name
22
+ # @!macro request_options
23
+ #
24
+ # @!macro response
25
+ def get(realm, character, **options)
26
+ character_request realm, character, **options
27
+ end
28
+
29
+ ##
30
+ # Return character achievements
31
+ #
32
+ # @see https://develop.battle.net/documentation/api-reference/world-of-warcraft-profile-api
33
+ #
34
+ # @param realm [String] The character realm's slug
35
+ # @param character [String] The character name
36
+ # @!macro request_options
37
+ #
38
+ # @!macro response
39
+ def achievements(realm, character, **options)
40
+ character_request realm, character, 'achievements', **options
41
+ end
42
+
43
+ ##
44
+ # Return character achievements statistics
45
+ #
46
+ # @see https://develop.battle.net/documentation/api-reference/world-of-warcraft-profile-api
47
+ #
48
+ # @param realm [String] The character realm's slug
49
+ # @param character [String] The character name
50
+ # @!macro request_options
51
+ #
52
+ # @!macro response
53
+ def achievement_statistics(realm, character, **options)
54
+ character_request realm, character, 'achievements/statistics', **options
55
+ end
56
+
57
+ ##
58
+ # Return character appearance
59
+ #
60
+ # @see https://develop.battle.net/documentation/api-reference/world-of-warcraft-profile-api
61
+ #
62
+ # @param realm [String] The character realm's slug
63
+ # @param character [String] The character name
64
+ # @!macro request_options
65
+ #
66
+ # @!macro response
67
+ def appearance(realm, character, **options)
68
+ character_request realm, character, 'appearance', **options
69
+ end
70
+
71
+ ##
72
+ # Return a character's collections
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 collections(realm, character, **options)
82
+ character_request realm, character, 'collections', **options
83
+ end
84
+
85
+ ##
86
+ # Return a character's pet collection
87
+ #
88
+ # @see https://develop.battle.net/documentation/api-reference/world-of-warcraft-profile-api
89
+ #
90
+ # @param realm [String] The character realm's slug
91
+ # @param character [String] The character name
92
+ # @!macro request_options
93
+ #
94
+ # @!macro response
95
+ def pets(realm, character, **options)
96
+ character_request realm, character, 'collections/pets', **options
97
+ end
98
+
99
+ ##
100
+ # Return a character's mount collection
101
+ #
102
+ # @see https://develop.battle.net/documentation/api-reference/world-of-warcraft-profile-api
103
+ #
104
+ # @param realm [String] The character realm's slug
105
+ # @param character [String] The character name
106
+ # @!macro request_options
107
+ #
108
+ # @!macro response
109
+ def mounts(realm, character, **options)
110
+ character_request realm, character, 'collections/mounts', **options
111
+ end
112
+
113
+ ##
114
+ # Return a character's toy collection
115
+ #
116
+ # @see https://develop.battle.net/documentation/api-reference/world-of-warcraft-profile-api
117
+ #
118
+ # @param realm [String] The character realm's slug
119
+ # @param character [String] The character name
120
+ # @!macro request_options
121
+ #
122
+ # @!macro response
123
+ def toys(realm, character, **options)
124
+ character_request realm, character, 'collections/toys', **options
125
+ end
126
+
127
+ ##
128
+ # Return a character's heirloom collection
129
+ #
130
+ # @see https://develop.battle.net/documentation/api-reference/world-of-warcraft-profile-api
131
+ #
132
+ # @param realm [String] The character realm's slug
133
+ # @param character [String] The character name
134
+ # @!macro request_options
135
+ #
136
+ # @!macro response
137
+ def heirlooms(realm, character, **options)
138
+ character_request realm, character, 'collections/heirlooms', **options
139
+ end
140
+
141
+ ##
142
+ # Return a character's encounter summary
143
+ #
144
+ # @see https://develop.battle.net/documentation/api-reference/world-of-warcraft-profile-api
145
+ #
146
+ # @param realm [String] The character realm's slug
147
+ # @param character [String] The character name
148
+ # @!macro request_options
149
+ #
150
+ # @!macro response
151
+ def encounters(realm, character, **options)
152
+ character_request realm, character, 'encounters', **options
153
+ end
154
+
155
+ ##
156
+ # Return a character's dungeon progress
157
+ #
158
+ # @see https://develop.battle.net/documentation/api-reference/world-of-warcraft-profile-api
159
+ #
160
+ # @param realm [String] The character realm's slug
161
+ # @param character [String] The character name
162
+ # @!macro request_options
163
+ #
164
+ # @!macro response
165
+ def dungeons(realm, character, **options)
166
+ character_request realm, character, 'encounters/dungeons', **options
167
+ end
168
+
169
+ ##
170
+ # Return a character's raid progress
171
+ #
172
+ # @see https://develop.battle.net/documentation/api-reference/world-of-warcraft-profile-api
173
+ #
174
+ # @param realm [String] The character realm's slug
175
+ # @param character [String] The character name
176
+ # @!macro request_options
177
+ #
178
+ # @!macro response
179
+ def raids(realm, character, **options)
180
+ character_request realm, character, 'encounters/raids', **options
181
+ end
182
+
183
+ ##
184
+ # Return character equipment
185
+ #
186
+ # @see https://develop.battle.net/documentation/api-reference/world-of-warcraft-profile-api
187
+ #
188
+ # @param realm [String] The character realm's slug
189
+ # @param character [String] The character name
190
+ # @!macro request_options
191
+ #
192
+ # @!macro response
193
+ def equipment(realm, character, **options)
194
+ character_request realm, character, 'equipment', **options
195
+ end
196
+
197
+ ##
198
+ # Return a character's hunter pets
199
+ #
200
+ # @see https://develop.battle.net/documentation/api-reference/world-of-warcraft-profile-api
201
+ #
202
+ # @param realm [String] The character realm's slug
203
+ # @param character [String] The character name
204
+ # @!macro request_options
205
+ #
206
+ # @!macro response
207
+ def hunter_pets(realm, character, **options)
208
+ character_request realm, character, 'hunter-pets', **options
209
+ end
210
+
211
+ ##
212
+ # Return character media
213
+ #
214
+ # @see https://develop.battle.net/documentation/api-reference/world-of-warcraft-profile-api
215
+ #
216
+ # @param realm [String] The character realm's slug
217
+ # @param character [String] The character name
218
+ # @!macro request_options
219
+ #
220
+ # @!macro response
221
+ def media(realm, character, **options)
222
+ character_request realm, character, 'character-media', **options
223
+ end
224
+
225
+ ##
226
+ # Return the mythic keystone profile of a character
227
+ #
228
+ # @see https://develop.battle.net/documentation/api-reference/world-of-warcraft-profile-api
229
+ #
230
+ # @param realm [String] The character realm's slug
231
+ # @param character [String] The character name
232
+ # @!macro request_options
233
+ #
234
+ # @!macro response
235
+ def mythic_keystone_profile(realm, character, **options)
236
+ character_request realm, character, 'mythic-keystone-profile', **options
237
+ end
238
+
239
+ ##
240
+ # Return the mythic keystone profile of a character
241
+ #
242
+ # @see https://develop.battle.net/documentation/api-reference/world-of-warcraft-profile-api
243
+ #
244
+ # @param realm [String] The character realm's slug
245
+ # @param character [String] The character name
246
+ # @param season [Integer] Season ID if you want only a specific season or nil to include all.
247
+ # @!macro request_options
248
+ #
249
+ # @!macro response
250
+ def mythic_keystone_seasons(realm, character, season = nil, **options)
251
+ character_request realm, character, "mythic-keystone-profile/season/#{season}", **options
252
+ end
253
+
254
+ ##
255
+ # Return professions from a character
256
+ #
257
+ # @see https://develop.battle.net/documentation/api-reference/world-of-warcraft-profile-api
258
+ #
259
+ # @param realm [String] The character realm's slug
260
+ # @param character [String] The character name
261
+ # @!macro request_options
262
+ #
263
+ # @!macro response
264
+ def professions(realm, character, **options)
265
+ character_request realm, character, 'professions', **options
266
+ end
267
+
268
+ ##
269
+ # Return character status
270
+ #
271
+ # @see https://develop.battle.net/documentation/api-reference/world-of-warcraft-profile-api
272
+ # @see https://us.forums.blizzard.com/en/blizzard/t/data-protection-notice-and-faq/609
273
+ #
274
+ # @param realm [String] The character realm's slug
275
+ # @param character [String] The character name
276
+ # @!macro request_options
277
+ #
278
+ # @!macro response
279
+ def status(realm, character, **options)
280
+ character_request realm, character, 'status', **options
281
+ end
282
+
283
+ ##
284
+ # Return the pvp bracket of a character
285
+ #
286
+ # @see https://develop.battle.net/documentation/api-reference/world-of-warcraft-profile-api
287
+ #
288
+ # @param realm [String] The character realm's slug
289
+ # @param character [String] The character name
290
+ # @param bracket [String] Pvp bracket
291
+ # @!macro request_options
292
+ #
293
+ # @!macro response
294
+ def pvp_bracket(realm, character, bracket, **options)
295
+ character_request realm, character, "pvp-bracket/#{bracket}", **options
296
+ end
297
+
298
+ ##
299
+ # Return the pvp summary of a character
300
+ #
301
+ # @see https://develop.battle.net/documentation/api-reference/world-of-warcraft-profile-api
302
+ #
303
+ # @param realm [String] The character realm's slug
304
+ # @param character [String] The character name
305
+ # @!macro request_options
306
+ #
307
+ # @!macro response
308
+ def pvp_summary(realm, character, **options)
309
+ character_request realm, character, 'pvp-summary', **options
310
+ end
311
+
312
+ ##
313
+ # Return a character's quests
314
+ #
315
+ # @see https://develop.battle.net/documentation/api-reference/world-of-warcraft-profile-api
316
+ #
317
+ # @param realm [String] The character realm's slug
318
+ # @param character [String] The character name
319
+ # @!macro request_options
320
+ # @option options [Boolean] :completed Should return completed quests
321
+ #
322
+ # @!macro response
323
+ def quests(realm, character, **options)
324
+ completed = options.delete(:completed) || false
325
+ return character_request realm, character, 'quests/completed', **options if completed
326
+
327
+ character_request realm, character, 'quests', **options
328
+ end
329
+
330
+ ##
331
+ # Return a character's reputations
332
+ #
333
+ # @see https://develop.battle.net/documentation/api-reference/world-of-warcraft-profile-api
334
+ #
335
+ # @param realm [String] The character realm's slug
336
+ # @param character [String] The character name
337
+ # @!macro request_options
338
+ #
339
+ # @!macro response
340
+ def reputation(realm, character, **options)
341
+ character_request realm, character, 'reputations', **options
342
+ end
343
+
344
+ ##
345
+ # Return a character's soulbinds
346
+ #
347
+ # @see https://develop.battle.net/documentation/api-reference/world-of-warcraft-profile-api
348
+ #
349
+ # @param realm [String] The character realm's slug
350
+ # @param character [String] The character name
351
+ # @!macro request_options
352
+ #
353
+ # @!macro response
354
+ def soulbinds(realm, character, **options)
355
+ character_request realm, character, 'soulbinds', **options
356
+ end
357
+
358
+ ##
359
+ # Return a character's specialization
360
+ #
361
+ # @see https://develop.battle.net/documentation/api-reference/world-of-warcraft-profile-api
362
+ #
363
+ # @param realm [String] The character realm's slug
364
+ # @param character [String] The character name
365
+ # @!macro request_options
366
+ #
367
+ # @!macro response
368
+ def specializations(realm, character, **options)
369
+ character_request realm, character, 'specializations', **options
370
+ end
371
+
372
+ ##
373
+ # Return a character's statistics
374
+ #
375
+ # @see https://develop.battle.net/documentation/api-reference/world-of-warcraft-profile-api
376
+ #
377
+ # @param realm [String] The character realm's slug
378
+ # @param character [String] The character name
379
+ # @!macro request_options
380
+ #
381
+ # @!macro response
382
+ def statistics(realm, character, **options)
383
+ character_request realm, character, 'statistics', **options
384
+ end
385
+
386
+ ##
387
+ # Return a character's titles
388
+ #
389
+ # @see https://develop.battle.net/documentation/api-reference/world-of-warcraft-profile-api
390
+ #
391
+ # @param realm [String] The character realm's slug
392
+ # @param character [String] The character name
393
+ # @!macro request_options
394
+ #
395
+ # @!macro response
396
+ def titles(realm, character, **options)
397
+ character_request realm, character, 'titles', **options
398
+ end
399
+
400
+ private
401
+
402
+ def default_options(user_token = nil)
403
+ opts = { ttl: CACHE_HOUR, namespace: :profile }
404
+ opts.merge access_token: user_token if user_token
405
+ opts
406
+ end
407
+
408
+ def character_request(realm, character, variant = nil, **options)
409
+ uri = "#{base_url(:profile)}/character/#{string_to_slug(realm)}/#{string_to_slug(character)}"
410
+ uri += "/#{variant}" if variant
411
+ api_request uri, **default_options.merge(options)
412
+ end
413
+ end
414
+ end
415
+ end
@@ -0,0 +1,75 @@
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-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
12
+ class Guild < Wow::Request
13
+ include BlizzardApi::Wow::Slug
14
+
15
+ ##
16
+ # Return data about the specified guild
17
+ #
18
+ # @param realm [String] The guild realm's slug
19
+ # @param guild [String] The guild's name
20
+ # @!macro request_options
21
+ #
22
+ # @!macro response
23
+ def get(realm, guild, **options)
24
+ guild_request(realm, guild, **options)
25
+ end
26
+
27
+ ##
28
+ # Return all guild members for a specified guild
29
+ #
30
+ # @param realm [String] The guild realm's slug
31
+ # @param guild [String] The guild's name
32
+ #
33
+ # @!macro request_options
34
+ #
35
+ # @!macro response
36
+ def roster(realm, guild, **options)
37
+ guild_request realm, guild, 'roster', **options
38
+ end
39
+
40
+ ##
41
+ # Return all guild achievements for a specified guild
42
+ #
43
+ # @param realm [String] The guild realm's slug
44
+ # @param guild [String] The guild's name
45
+ # @!macro request_options
46
+ #
47
+ # @!macro response
48
+ def achievements(realm, guild, **options)
49
+ guild_request realm, guild, 'achievements', **options
50
+ end
51
+
52
+ ##
53
+ # Return guild activity
54
+ #
55
+ # @param realm [String] The guild realm's slug
56
+ # @param guild [String] The guild's name
57
+ # @!macro request_options
58
+ #
59
+ # @!macro response
60
+ def activity(realm, guild, **options)
61
+ guild_request realm, guild, 'activity', **options
62
+ end
63
+
64
+ private
65
+
66
+ def guild_request(realm, guild, variant = nil, **options)
67
+ realm = string_to_slug(realm)
68
+ guild = string_to_slug(guild)
69
+ url = "#{base_url(:game_data)}/guild/#{realm}/#{guild}"
70
+ url += "/#{variant}" if variant
71
+ api_request url, **{ ttl: CACHE_DAY, namespace: :profile }.merge(options)
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BlizzardApi
4
+ module Wow
5
+ ##
6
+ # World of Warcraft requests
7
+ class Request < BlizzardApi::Request
8
+ ##
9
+ # @!macro init_options
10
+ def initialize(**options)
11
+ super(**options)
12
+ @game = 'wow'
13
+ end
14
+ end
15
+ end
16
+ 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}=#{URI.encode_www_form_component(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}!=#{URI.encode_www_form_component(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