# frozen_string_literal: true class WowAchievementsWorker < 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::Achievement.all return unless result.status_code == 200 result.achievements.each do |achievement| wow_achievement = WowAchievement.find_or_initialize_by(achievement_id: achievement.id) # Localisation data locales.each do |locale| Mobility.with_locale(locale[0]) { wow_achievement.name = achievement.name[locale[1]] } end wow_achievement.save WowAchievementDetailWorker.perform_async(wow_achievement.achievement_id) if wow_achievement.persisted? end end end