28 lines
787 B
Ruby
28 lines
787 B
Ruby
# frozen_string_literal: true
|
|
|
|
class WowRealmsWorker < 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::Realm.all
|
|
|
|
return unless result.status_code == 200
|
|
|
|
result.realms.each do |realm|
|
|
wow_realm = WowRealm.find_or_initialize_by(realm_id: realm.id)
|
|
|
|
wow_realm.slug = realm.slug
|
|
wow_realm.href = realm.key.href
|
|
|
|
# Localisation data
|
|
locales.each do |locale|
|
|
Mobility.with_locale(locale[0]) { wow_realm.name = realm.name[locale[1]] }
|
|
end
|
|
|
|
wow_realm.save
|
|
|
|
WowRealmDetailWorker.perform_async(wow_realm.realm_id) if wow_realm.persisted?
|
|
end
|
|
end
|
|
end
|