47 lines
1.6 KiB
Ruby
47 lines
1.6 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
class WowCharactersWorker < WowSidekiqWorker
|
|
def perform(user_id)
|
|
# 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.find_or_initialize_by(character_id: character.id)
|
|
|
|
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.map_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
|
|
|
|
next unless wow_char.persisted?
|
|
|
|
WowCharacterMediaWorker.perform_async(wow_char.character_id)
|
|
WowCharacterDetailWorker.perform_async(wow_char.character_id)
|
|
WowCharacterPositionsWorker.perform_async(wow_char.character_id)
|
|
WowStandingWorker.perform_async(wow_char.character_id)
|
|
end
|
|
end
|
|
end
|
|
end
|