initial rebuild from v1
This commit is contained in:
43
app/workers/wow_realms_worker.rb
Normal file
43
app/workers/wow_realms_worker.rb
Normal file
@@ -0,0 +1,43 @@
|
||||
class WowRealmsWorker
|
||||
include Sidekiq::Worker
|
||||
|
||||
def perform
|
||||
locales = [
|
||||
['en-us', 'en_US'],
|
||||
['es-mx', 'es_MX'],
|
||||
['pt-br', 'pt_BR'],
|
||||
['de-de', 'de_DE'],
|
||||
['en-gb', 'en_GB'],
|
||||
['es-es', 'es_ES'],
|
||||
['fr-fr', 'fr_FR'],
|
||||
['it', 'it_IT'],
|
||||
['ru-ru', 'ru_RU'],
|
||||
['ko', 'ko_KR'],
|
||||
['zh-tw', 'zh_TW'],
|
||||
['zh-cn', 'zh_CN']
|
||||
]
|
||||
|
||||
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.where(realm_id: realm.id).first_or_initialize
|
||||
|
||||
wow_realm.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
|
||||
Reference in New Issue
Block a user