add everything to manage reputations
This commit is contained in:
@@ -1,4 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module CharactersHelper
|
||||
end
|
||||
16
app/helpers/wow_characters_helper.rb
Normal file
16
app/helpers/wow_characters_helper.rb
Normal file
@@ -0,0 +1,16 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module WowCharactersHelper
|
||||
def wow_character_title_name(wow_character)
|
||||
if wow_character.wow_character_title
|
||||
case wow_character.gender
|
||||
when 'FEMALE'
|
||||
wow_character.wow_character_title.female_name.gsub('{name}', wow_character.name)
|
||||
when 'MALE'
|
||||
wow_character.wow_character_title.male_name.gsub('{name}', wow_character.name)
|
||||
end
|
||||
else
|
||||
wow_character.name
|
||||
end
|
||||
end
|
||||
end
|
||||
12
app/helpers/wow_classes_helper.rb
Normal file
12
app/helpers/wow_classes_helper.rb
Normal file
@@ -0,0 +1,12 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module WowClassesHelper
|
||||
def gender_class_name(gender, wow_class)
|
||||
case gender
|
||||
when 'FEMALE'
|
||||
wow_class.female_name
|
||||
when 'MALE'
|
||||
wow_class.male_name
|
||||
end
|
||||
end
|
||||
end
|
||||
12
app/helpers/wow_races_helper.rb
Normal file
12
app/helpers/wow_races_helper.rb
Normal file
@@ -0,0 +1,12 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module WowRacesHelper
|
||||
def gender_race_name(gender, wow_race)
|
||||
case gender
|
||||
when 'FEMALE'
|
||||
wow_race.female_name
|
||||
when 'MALE'
|
||||
wow_race.male_name
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -12,38 +12,9 @@ class WowCharacter < ApplicationRecord
|
||||
belongs_to :last_position, class_name: 'WowGeoPosition', optional: true
|
||||
belongs_to :bind_position, class_name: 'WowGeoPosition', optional: true
|
||||
has_one :wow_character_medium, dependent: :nullify
|
||||
has_many :wow_standings, dependent: :nullify
|
||||
has_many :wow_reputations, through: :wow_standings
|
||||
|
||||
validates :name, presence: true
|
||||
validates :character_id, presence: true, uniqueness: true
|
||||
|
||||
def gender_class_name
|
||||
case gender
|
||||
when 'FEMALE'
|
||||
wow_class.female_name
|
||||
when 'MALE'
|
||||
wow_class.male_name
|
||||
end
|
||||
end
|
||||
|
||||
def gender_race_name
|
||||
case gender
|
||||
when 'FEMALE'
|
||||
wow_race.female_name
|
||||
when 'MALE'
|
||||
wow_race.male_name
|
||||
end
|
||||
end
|
||||
|
||||
def title_name
|
||||
if wow_character_title
|
||||
case gender
|
||||
when 'FEMALE'
|
||||
wow_character_title.female_name.gsub('{name}', name)
|
||||
when 'MALE'
|
||||
wow_character_title.male_name.gsub('{name}', name)
|
||||
end
|
||||
else
|
||||
name
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
13
app/models/wow_reputation.rb
Normal file
13
app/models/wow_reputation.rb
Normal file
@@ -0,0 +1,13 @@
|
||||
class WowReputation < ApplicationRecord
|
||||
extend Mobility
|
||||
translates :name, :description, :translated_faction
|
||||
|
||||
has_many :wow_standings, dependent: :destroy
|
||||
has_many :wow_characters, through: :wow_standings
|
||||
belongs_to :wow_reputation_tier, optional: true
|
||||
has_many :sub_wow_reputations, class_name: 'WowReputation', foreign_key: 'meta_wow_reputation_id', dependent: :nullify, inverse_of: :meta_wow_reputation
|
||||
belongs_to :meta_wow_reputation, class_name: 'WowReputation', optional: true
|
||||
|
||||
validates :name, presence: true
|
||||
validates :reputation_id, presence: true, uniqueness: true
|
||||
end
|
||||
6
app/models/wow_reputation_tier.rb
Normal file
6
app/models/wow_reputation_tier.rb
Normal file
@@ -0,0 +1,6 @@
|
||||
class WowReputationTier < ApplicationRecord
|
||||
has_many :wow_reputations, dependent: :nullify
|
||||
has_many :wow_reputation_tier_levels, dependent: :destroy
|
||||
|
||||
validates :reputation_tier_id, presence: true, uniqueness: true
|
||||
end
|
||||
9
app/models/wow_reputation_tier_level.rb
Normal file
9
app/models/wow_reputation_tier_level.rb
Normal file
@@ -0,0 +1,9 @@
|
||||
class WowReputationTierLevel < ApplicationRecord
|
||||
extend Mobility
|
||||
translates :name
|
||||
|
||||
belongs_to :wow_reputation_tier
|
||||
|
||||
validates :name, presence: true
|
||||
validates :order, presence: true, uniqueness: { scope: :wow_reputation_tier }
|
||||
end
|
||||
7
app/models/wow_standing.rb
Normal file
7
app/models/wow_standing.rb
Normal file
@@ -0,0 +1,7 @@
|
||||
class WowStanding < ApplicationRecord
|
||||
extend Mobility
|
||||
translates :name
|
||||
|
||||
belongs_to :wow_character
|
||||
belongs_to :wow_reputation
|
||||
end
|
||||
@@ -22,8 +22,8 @@
|
||||
<td><%= link_to character.name, character %></td>
|
||||
<td><%= character.translated_gender %></td>
|
||||
<td><%= character.wow_realm.name %></td>
|
||||
<td><%= character.gender_race_name %></td>
|
||||
<td><%= character.gender_class_name %></td>
|
||||
<td><%= gender_race_name(character.gender, character.wow_race) %></td>
|
||||
<td><%= gender_class_name(character.gender, character.wow_class) %></td>
|
||||
<td><%= character.translated_faction %></td>
|
||||
<td><%= character.level %></td>
|
||||
</tr>
|
||||
|
||||
@@ -5,9 +5,9 @@
|
||||
<% end %>
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title"><%= @wow_character.title_name %></h5>
|
||||
<p class="card-text"><%= @wow_character.gender_race_name %></p>
|
||||
<p class="card-text"><%= @wow_character.gender_class_name %></p>
|
||||
<h5 class="card-title"><%= wow_character_title_name(@wow_character) %></h5>
|
||||
<p class="card-text"><%= gender_race_name(@wow_character.gender, @wow_character.wow_race) %></p>
|
||||
<p class="card-text"><%= gender_class_name(@wow_character.gender, @wow_character.wow_class) %></p>
|
||||
<p class="card-text">Last connection: <%= @wow_character.last_login_timestamp %></p>
|
||||
<p class="card-text">Last position: Map: <%= @wow_character.last_position.wow_geo_map.name %> Zone: <%= @wow_character.last_position.wow_geo_zone.name %></p>
|
||||
<p class="card-text">Bind position: Map: <%= @wow_character.bind_position.wow_geo_map.name %> Zone: <%= @wow_character.bind_position.wow_geo_zone.name %></p>
|
||||
|
||||
@@ -39,6 +39,7 @@ class WowCharactersWorker < WowSidekiqWorker
|
||||
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
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
class WowClassDetailWorker < WowSidekiqWorker
|
||||
def perform(class_id)
|
||||
return unless (wow_class = WowClass.where(class_id: class_id).first)
|
||||
return unless (wow_class = WowClass.find_by(class_id: class_id))
|
||||
|
||||
RBattlenet.set_options(locale: 'all')
|
||||
result = RBattlenet::Wow::PlayableClass.find(class_id)
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
class WowMountDetailWorker < WowSidekiqWorker
|
||||
def perform(mount_id)
|
||||
return unless (mount = WowMount.where(mount_id: mount_id).first)
|
||||
return unless (mount = WowMount.find_by(mount_id: mount_id))
|
||||
|
||||
RBattlenet.set_options(locale: 'all')
|
||||
result = RBattlenet::Wow::Mount.find(mount_id)
|
||||
|
||||
31
app/workers/wow_reputation_detail_worker.rb
Normal file
31
app/workers/wow_reputation_detail_worker.rb
Normal file
@@ -0,0 +1,31 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class WowReputationDetailWorker < WowSidekiqWorker
|
||||
def perform(reputation_id)
|
||||
return unless (wow_reputation = WowReputation.find_by(reputation_id: reputation_id))
|
||||
|
||||
RBattlenet.set_options(locale: 'all')
|
||||
result = RBattlenet::Wow::ReputationFaction.find(reputation_id)
|
||||
|
||||
return unless result.status_code == 200
|
||||
|
||||
# Global data
|
||||
wow_reputation.wow_reputation_tier = WowReputationTier.find_by(reputation_tier_id: result.reputation_tiers.id)
|
||||
wow_reputation.faction = result.player_faction.type if result.player_faction
|
||||
|
||||
# If it's a meta faction
|
||||
result.factions&.each do |faction|
|
||||
wow_reputation.sub_wow_reputations << WowReputation.find_by(reputation_id: faction.id)
|
||||
end
|
||||
|
||||
# Localisation data
|
||||
locales.each do |locale|
|
||||
Mobility.with_locale(locale[0]) do
|
||||
wow_reputation.description = result.description[locale[1]] if result.description
|
||||
wow_reputation.translated_faction = result.player_faction.name[locale[1]] if result.player_faction
|
||||
end
|
||||
end
|
||||
|
||||
wow_reputation.save
|
||||
end
|
||||
end
|
||||
32
app/workers/wow_reputation_tier_detail_worker.rb
Normal file
32
app/workers/wow_reputation_tier_detail_worker.rb
Normal file
@@ -0,0 +1,32 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class WowReputationTierDetailWorker < WowSidekiqWorker
|
||||
def perform(reputation_tier_id)
|
||||
return unless (wow_reputation_tier = WowReputationTier.find_by(reputation_tier_id: reputation_tier_id))
|
||||
|
||||
RBattlenet.set_options(locale: 'all')
|
||||
result = RBattlenet::Wow::ReputationTiers.find(reputation_tier_id)
|
||||
|
||||
return unless result.status_code == 200
|
||||
|
||||
result.tiers.each do |tier|
|
||||
reputation_tier_level = WowReputationTierLevel.where(wow_reputation_tier: wow_reputation_tier, order: tier.id).first_or_initialize
|
||||
|
||||
reputation_tier_level.wow_reputation_tier = wow_reputation_tier
|
||||
reputation_tier_level.order = tier.id
|
||||
reputation_tier_level.min_value = tier.min_value
|
||||
reputation_tier_level.max_value = tier.max_value
|
||||
|
||||
# Localisation data
|
||||
locales.each do |locale|
|
||||
Mobility.with_locale(locale[0]) do
|
||||
reputation_tier_level.name = tier.name[locale[1]]
|
||||
end
|
||||
end
|
||||
|
||||
reputation_tier_level.save
|
||||
end
|
||||
|
||||
wow_reputation_tier.save
|
||||
end
|
||||
end
|
||||
22
app/workers/wow_reputation_tiers_worker.rb
Normal file
22
app/workers/wow_reputation_tiers_worker.rb
Normal file
@@ -0,0 +1,22 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class WowReputationTiersWorker < WowSidekiqWorker
|
||||
def perform
|
||||
RBattlenet.authenticate(client_id: ENV['BLIZZARD_API_CLIENT_ID'], client_secret: ENV['BLIZZARD_API_CLIENT_SECRET'])
|
||||
RBattlenet.set_options(locale: 'en_US')
|
||||
result = RBattlenet::Wow::ReputationTiers.all
|
||||
|
||||
return unless result.status_code == 200
|
||||
|
||||
result.reputation_tiers.each do |reputation_tier|
|
||||
wow_reputation_tier = WowReputationTier.find_or_initialize_by(reputation_tier_id: reputation_tier.id)
|
||||
|
||||
# Global data
|
||||
wow_reputation_tier.href = reputation_tier.key.href
|
||||
|
||||
wow_reputation_tier.save
|
||||
|
||||
WowReputationTierDetailWorker.perform_async(wow_reputation_tier.reputation_tier_id) if wow_reputation_tier.persisted?
|
||||
end
|
||||
end
|
||||
end
|
||||
29
app/workers/wow_reputations_worker.rb
Normal file
29
app/workers/wow_reputations_worker.rb
Normal file
@@ -0,0 +1,29 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class WowReputationsWorker < WowSidekiqWorker
|
||||
def perform
|
||||
RBattlenet.authenticate(client_id: ENV['BLIZZARD_API_CLIENT_ID'], client_secret: ENV['BLIZZARD_API_CLIENT_SECRET'])
|
||||
RBattlenet.set_options(locale: 'all')
|
||||
result = RBattlenet::Wow::ReputationFaction.all
|
||||
|
||||
return unless result.status_code == 200
|
||||
|
||||
result.factions.each do |faction|
|
||||
wow_reputation = WowReputation.find_or_initialize_by(reputation_id: faction.id)
|
||||
|
||||
# Global data
|
||||
wow_reputation.href = faction.key.href
|
||||
|
||||
# Localisation data
|
||||
locales.each do |locale|
|
||||
Mobility.with_locale(locale[0]) do
|
||||
wow_reputation.name = faction.name[locale[1]]
|
||||
end
|
||||
end
|
||||
|
||||
wow_reputation.save
|
||||
|
||||
WowReputationDetailWorker.perform_async(wow_reputation.reputation_id) if wow_reputation.persisted?
|
||||
end
|
||||
end
|
||||
end
|
||||
28
app/workers/wow_standing_worker.rb
Normal file
28
app/workers/wow_standing_worker.rb
Normal 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
|
||||
Reference in New Issue
Block a user