add everything to manage reputations

This commit is contained in:
2021-05-01 00:22:15 +02:00
parent ca80fd55fa
commit d227cdc87c
30 changed files with 366 additions and 43 deletions

View File

@@ -0,0 +1,28 @@
# 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