29 lines
1.0 KiB
Ruby
29 lines
1.0 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
class WowStandingWorker < WowSidekiqWorker
|
|
def perform(wow_character_id)
|
|
return unless (wow_character = WowCharacter.find_by(character_id: wow_character_id))
|
|
|
|
RBattlenet.set_options(locale: 'en_US')
|
|
params = { realm: wow_character.wow_realm.slug, name: wow_character.name.downcase }
|
|
result = RBattlenet::Wow::Character::Reputations.find(params)
|
|
|
|
return unless result.status_code == 200
|
|
|
|
result.reputations&.each do |reputation|
|
|
next unless (wow_reputation = WowReputation.find_by(reputation_id: reputation.faction.id))
|
|
|
|
wow_standing = WowStanding.where(wow_reputation: wow_reputation, wow_character: wow_character).first_or_initialize
|
|
|
|
wow_standing.wow_reputation = wow_reputation
|
|
wow_standing.wow_character = wow_character
|
|
wow_standing.raw = reputation.standing.raw
|
|
wow_standing.value = reputation.standing.value
|
|
wow_standing.max = reputation.standing.max
|
|
wow_standing.tier = reputation.standing.tier
|
|
|
|
wow_standing.save
|
|
end
|
|
end
|
|
end
|