add covenant

This commit is contained in:
2021-05-30 17:49:54 +02:00
parent d0e5824d40
commit 5b3da08707
29 changed files with 157 additions and 9 deletions

View File

@@ -35,7 +35,7 @@ gem 'omniauth-bnet', '~> 2.0.0'
# This gem provides a mitigation against CVE-2015-9284
gem 'omniauth-rails_csrf_protection', '~> 0.1.2'
# A Ruby wrapper around Blizzard's Game Data and Profile APIs
gem 'rbattlenet', '~> 2.2.6', git: 'https://github.com/Dainii/rbattlenet'
gem 'rbattlenet', '~> 2.2.7', git: 'https://github.com/Dainii/rbattlenet'
# A gem that provides Rails integration for the Sentry error logger
gem 'sentry-rails', '~> 4.4.0'
gem 'sentry-ruby', '~> 4.4.1'

View File

@@ -1,8 +1,8 @@
GIT
remote: https://github.com/Dainii/rbattlenet
revision: 52c159e1418350247c2f928f08930e0881bc6827
revision: 6fc990a743b1cec56e95820aec9222b5ff2e843a
specs:
rbattlenet (2.2.6)
rbattlenet (2.2.7)
require_all
typhoeus (~> 1.1)
@@ -411,7 +411,7 @@ DEPENDENCIES
rails (~> 6.1.3, >= 6.1.3.1)
rails-erd
rails-i18n (~> 6.0.0)
rbattlenet (~> 2.2.6)!
rbattlenet (~> 2.2.7)!
redis (~> 4.2.5)
rspec-rails
rubocop

View File

@@ -2,7 +2,7 @@
class WowCharactersController < ProtectedController
def index
@wow_characters = current_user.wow_characters.includes(:wow_realm, :wow_race, :wow_class, :wow_character_medium, :wow_guild)
@wow_characters = current_user.wow_characters.includes(:wow_realm, :wow_race, :wow_class, :wow_character_medium, :wow_guild, :wow_covenant)
end
def show

View File

@@ -10,10 +10,12 @@ class WowCharacter < ApplicationRecord
belongs_to :wow_race
belongs_to :wow_character_title, optional: true
belongs_to :wow_guild, optional: true
has_one :wow_covenant_progress, dependent: :destroy
has_one :wow_covenant, through: :wow_covenant_progress
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_one :wow_character_medium, dependent: :destroy
has_many :wow_standings, dependent: :destroy
has_many :wow_reputations, through: :wow_standings
validates :name, presence: true

View File

@@ -0,0 +1,10 @@
class WowCovenant < ApplicationRecord
extend Mobility
translates :name, :description
has_many :wow_covenant_progresses, dependent: :nullify
has_many :wow_characters, through: :wow_covenant_progresses
validates :name, presence: true
validates :covenant_id, presence: true, uniqueness: true
end

View File

@@ -0,0 +1,4 @@
class WowCovenantProgress < ApplicationRecord
belongs_to :wow_character
belongs_to :wow_covenant
end

View File

@@ -10,6 +10,7 @@
<th scope="col"><%= t('wow_characters.character_list.race') %></th>
<th scope="col"><%= t('wow_characters.character_list.class') %></th>
<th scope="col"><%= t('wow_characters.character_list.faction') %></th>
<th scope="col"><%= t('wow_characters.character_list.covenant') %></th>
<th scope="col"><%= t('wow_characters.character_list.level') %></th>
</tr>
</thead>
@@ -25,6 +26,7 @@
<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.wow_covenant&.name %></td>
<td><%= character.level %></td>
</tr>
<% end %>

View File

@@ -24,6 +24,8 @@ class WowCharacterDetailWorker < WowSidekiqWorker
wow_character.wow_guild = find_or_create_wow_guild(result.guild) if result.guild
wow_character.save
update_covenant_progress(wow_character, result.covenant_progress) if result.covenant_progress
end
def find_or_create_wow_guild(guild)
@@ -36,4 +38,13 @@ class WowCharacterDetailWorker < WowSidekiqWorker
wow_guild.persisted? ? wow_guild : nil
end
def update_covenant_progress(wow_character, covenant_progress)
wow_covenant_progress = wow_character.wow_covenant_progress || WowCovenantProgress.new(wow_character: wow_character)
wow_covenant_progress.renown_level = covenant_progress.renown_level
wow_covenant_progress.wow_covenant = WowCovenant.find_by(covenant_id: covenant_progress.chosen_covenant.id)
wow_covenant_progress.save
end
end

View File

@@ -23,7 +23,7 @@ class WowCharactersWorker < WowSidekiqWorker
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
wow_char.account_id = account.id
locales.each do |locale|
Mobility.with_locale(locale[0]) do

View File

@@ -0,0 +1,23 @@
# frozen_string_literal: true
class WowCovenantDetailWorker < WowSidekiqWorker
def perform(covenant_id)
return unless (wow_covenant = WowCovenant.find_by(covenant_id: covenant_id))
RBattlenet.set_options(locale: 'all')
result = RBattlenet::Wow::Covenant.find(covenant_id)
return unless result.status_code == 200
wow_covenant.media_id = result.media.id
# Localisation data
locales.each do |locale|
Mobility.with_locale(locale[0]) do
wow_covenant.description = result.description[locale[1]]
end
end
wow_covenant.save
end
end

View File

@@ -0,0 +1,24 @@
# frozen_string_literal: true
class WowCovenantsWorker < 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::Covenant.all
return unless result.status_code == 200
result.covenants.each do |covenant|
wow_covenant = WowCovenant.find_or_initialize_by(covenant_id: covenant.id)
# Localisation data
locales.each do |locale|
Mobility.with_locale(locale[0]) { wow_covenant.name = covenant.name[locale[1]] }
end
wow_covenant.save
WowCovenantDetailWorker.perform_async(wow_covenant.covenant_id) if wow_covenant.persisted?
end
end
end

View File

@@ -9,3 +9,4 @@ de-de:
faction: "Fraktion"
level: "Niveau"
guild: "Gilde"
covenant: "Pakte"

View File

@@ -9,3 +9,4 @@ en-gb:
faction: "Faction"
level: "Level"
guild: "Guild"
covenant: "Covenant"

View File

@@ -9,3 +9,4 @@ en-us:
faction: "Faction"
level: "Level"
guild: "Guild"
covenant: "Covenant"

View File

@@ -9,3 +9,4 @@ es-es:
faction: "Facción"
level: "Nivel"
guild: "Gremio"
covenant: "Curia"

View File

@@ -9,3 +9,4 @@ es-mx:
faction: "Facción"
level: "Nivel"
guild: "Gremio"
covenant: "Pacto"

View File

@@ -9,3 +9,4 @@ fr-fr:
faction: "Faction"
level: "Niveau"
guild: "Guilde"
covenant: "Congrégation"

View File

@@ -9,3 +9,4 @@ it:
faction: "Fazione"
level: "Livello"
guild: "Gilda"
covenant: "Congregazione"

View File

@@ -9,3 +9,4 @@ ko:
faction: "파벌"
level: "수평"
guild: "동업 조합"
covenant: "계약"

View File

@@ -9,3 +9,4 @@ pt-br:
faction: "Facção"
level: "Nível"
guild: "Guilda"
covenant: "Pacto"

View File

@@ -9,3 +9,4 @@ ru-ru:
faction: "Фракция"
level: "Уровень"
guild: "Гильдия"
covenant: "Ковенанты"

View File

@@ -9,3 +9,4 @@ zh-cn:
faction: "派"
level: "水平"
guild: "公会"
covenant: "盟约"

View File

@@ -9,3 +9,4 @@ zh-tw:
faction: "派"
level: "水平"
guild: "公会"
covenant: "盟约"

View File

@@ -0,0 +1,14 @@
class CreateWowCovenants < ActiveRecord::Migration[6.1]
def change
create_table :wow_covenants do |t|
t.integer :covenant_id
t.jsonb :name
t.jsonb :description
t.integer :media_id
t.timestamps
end
add_index :wow_covenants, :covenant_id, unique: true
end
end

View File

@@ -0,0 +1,11 @@
class CreateWowCovenantProgresses < ActiveRecord::Migration[6.1]
def change
create_table :wow_covenant_progresses do |t|
t.integer :renown_level
t.belongs_to :wow_characters
t.belongs_to :wow_covenant
t.timestamps
end
end
end

View File

@@ -0,0 +1,5 @@
class RenameCovenantProgressBelongToWowCharacter < ActiveRecord::Migration[6.1]
def change
rename_column :wow_covenant_progresses, :wow_characters_id, :wow_character_id
end
end

22
db/schema.rb generated
View File

@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2021_05_30_121125) do
ActiveRecord::Schema.define(version: 2021_05_30_151735) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@@ -151,6 +151,26 @@ ActiveRecord::Schema.define(version: 2021_05_30_121125) do
t.index ["class_id"], name: "index_wow_classes_on_class_id", unique: true
end
create_table "wow_covenant_progresses", force: :cascade do |t|
t.integer "renown_level"
t.bigint "wow_character_id"
t.bigint "wow_covenant_id"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.index ["wow_character_id"], name: "index_wow_covenant_progresses_on_wow_character_id"
t.index ["wow_covenant_id"], name: "index_wow_covenant_progresses_on_wow_covenant_id"
end
create_table "wow_covenants", force: :cascade do |t|
t.integer "covenant_id"
t.jsonb "name"
t.jsonb "description"
t.integer "media_id"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.index ["covenant_id"], name: "index_wow_covenants_on_covenant_id", unique: true
end
create_table "wow_geo_maps", force: :cascade do |t|
t.integer "map_id"
t.jsonb "name"

View File

@@ -0,0 +1,5 @@
require 'rails_helper'
RSpec.describe WowCovenantProgress, type: :model do
pending "add some examples to (or delete) #{__FILE__}"
end

View File

@@ -0,0 +1,5 @@
require 'rails_helper'
RSpec.describe WowCovenant, type: :model do
pending "add some examples to (or delete) #{__FILE__}"
end