add geo info and do refractor on workers

This commit is contained in:
2021-04-29 20:44:21 +02:00
parent f7799bb514
commit c5190b48f8
32 changed files with 241 additions and 205 deletions

View File

@@ -1,13 +1,13 @@
# frozen_string_literal: true
class WowCharacterDetailWorker
include Sidekiq::Worker
class WowCharacterDetailWorker < WowSidekiqWorker
def perform(wow_character_id)
return unless (wow_character = WowCharacter.where(character_id: wow_character_id).first)
return unless (wow_character = WowCharacter.find_by(character_id: wow_character_id))
RBattlenet.authenticate(client_id: ENV['BLIZZARD_API_CLIENT_ID'], client_secret: ENV['BLIZZARD_API_CLIENT_SECRET'])
RBattlenet.set_options(locale: 'en_GB')
# Public data
result = RBattlenet::Wow::Character.find({ name: wow_character.name.downcase, realm: wow_character.wow_realm.slug })
return unless result.status_code == 200
@@ -16,7 +16,7 @@ class WowCharacterDetailWorker
wow_character.last_login_timestamp = Time.at(result.last_login_timestamp.to_s[0..-4].to_i).utc
wow_character.average_item_level = result.average_item_level
wow_character.equipped_item_level = result.equipped_item_level
wow_character.wow_character_title = WowCharacterTitle.where(title_id: result.active_title.id).first if result.active_title
wow_character.wow_character_title = WowCharacterTitle.find_by(title_id: result.active_title.id) if result.active_title
wow_character.save
end