# frozen_string_literal: true class WowRacesWorker < WowSidekiqWorker def perform RBattlenet.authenticate(client_id: ENV['BLIZZARD_API_CLIENT_ID'], client_secret: ENV['BLIZZARD_API_CLIENT_SECRET']) RBattlenet.set_options(locale: 'all') result = RBattlenet::Wow::PlayableRace.all return unless result.status_code == 200 result.races.each do |playable_race| wow_race = WowRace.find_or_initialize_by(race_id: playable_race.id) # Global data wow_race.href = playable_race.key.href # Localisation data locales.each do |locale| Mobility.with_locale(locale[0]) { wow_race.name = playable_race.name[locale[1]] } end wow_race.save WowRaceDetailWorker.perform_async(wow_race.race_id) if wow_race.persisted? end end end