add WowSpell

This commit is contained in:
2021-05-30 14:32:34 +02:00
parent df26a9ca6f
commit d0e5824d40
7 changed files with 79 additions and 5 deletions

View File

@@ -0,0 +1,38 @@
# frozen_string_literal: true
class WowSpellsWorker < WowSidekiqWorker
def perform(spell_id, batch_size, keep_going_on)
RBattlenet.authenticate(client_id: ENV['BLIZZARD_API_CLIENT_ID'], client_secret: ENV['BLIZZARD_API_CLIENT_SECRET'])
RBattlenet.set_options(locale: 'all')
params = {
_page: 1,
_pageSize: batch_size,
orderby: 'id',
filters: { id: "[#{spell_id},]" }
}
result = RBattlenet::Wow::Search::Spell.find(params)
return unless result.status_code == 200
result.results&.each do |spell|
wow_spell = WowSpell.find_or_initialize_by(spell_id: spell.data.id)
wow_spell.media_id = spell.data.media.id if spell.data.media.id
# Localisation data
locales.each do |locale|
Mobility.with_locale(locale[0]) do
wow_spell.name = spell.data.name[locale[1]]
end
end
wow_spell.save
end
# Create a new job for the next batch if keep_going_on is true
return unless keep_going_on && !result.results.count.zero?
WowSpellsWorker.perform_async(result.results.last.data.id + 1, batch_size, keep_going_on)
end
end