initial rebuild from v1
This commit is contained in:
60
app/workers/wow_characters_worker.rb
Normal file
60
app/workers/wow_characters_worker.rb
Normal file
@@ -0,0 +1,60 @@
|
||||
class WowCharactersWorker
|
||||
include Sidekiq::Worker
|
||||
|
||||
def perform(user_id)
|
||||
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']
|
||||
]
|
||||
|
||||
# Update the WoW character list
|
||||
return unless (user = User.find(user_id))
|
||||
|
||||
RBattlenet.set_options(locale: 'all')
|
||||
result = RBattlenet::Wow::Profile::User.find(user.token)
|
||||
|
||||
return unless result.status_code == 200
|
||||
|
||||
result.wow_accounts.each do |account|
|
||||
account.characters.each do |character|
|
||||
wow_char = user.wow_characters.where(character_id: character.id).first_or_initialize
|
||||
|
||||
wow_char.name = character.name
|
||||
wow_char.gender = character.gender.type
|
||||
wow_char.faction = character.faction.type
|
||||
wow_char.href = character.character.href
|
||||
wow_char.level = character.level
|
||||
wow_char.wow_realm = WowRealm.where(realm_id: character.realm.id).first
|
||||
wow_char.wow_class = WowClass.where(class_id: character.playable_class.id).first
|
||||
wow_char.wow_race = WowRace.where(race_id: character.playable_race.id).first
|
||||
wow_char.user = user
|
||||
wow_char.account_id = account.id
|
||||
wow_char.character_id = character.id
|
||||
|
||||
locales.each do |locale|
|
||||
Mobility.with_locale(locale[0]) do
|
||||
wow_char.translated_faction = character.faction.name[locale[1]]
|
||||
wow_char.translated_gender = character.gender.name[locale[1]]
|
||||
end
|
||||
end
|
||||
|
||||
wow_char.save
|
||||
|
||||
if wow_char.persisted?
|
||||
WowCharacterMediaWorker.perform_async(wow_char.character_id)
|
||||
WowCharacterDetailWorker.perform_async(wow_char.character_id)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user