add achievement management

This commit is contained in:
2021-08-15 16:45:49 +02:00
parent 2552a78d15
commit 39ebeea387
27 changed files with 435 additions and 26 deletions

View File

@@ -0,0 +1,24 @@
# 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