add covenant
This commit is contained in:
24
app/workers/wow_covenants_worker.rb
Normal file
24
app/workers/wow_covenants_worker.rb
Normal file
@@ -0,0 +1,24 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class WowCovenantsWorker < 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::Covenant.all
|
||||
|
||||
return unless result.status_code == 200
|
||||
|
||||
result.covenants.each do |covenant|
|
||||
wow_covenant = WowCovenant.find_or_initialize_by(covenant_id: covenant.id)
|
||||
|
||||
# Localisation data
|
||||
locales.each do |locale|
|
||||
Mobility.with_locale(locale[0]) { wow_covenant.name = covenant.name[locale[1]] }
|
||||
end
|
||||
|
||||
wow_covenant.save
|
||||
|
||||
WowCovenantDetailWorker.perform_async(wow_covenant.covenant_id) if wow_covenant.persisted?
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user