add covenant
This commit is contained in:
2
Gemfile
2
Gemfile
@@ -35,7 +35,7 @@ gem 'omniauth-bnet', '~> 2.0.0'
|
|||||||
# This gem provides a mitigation against CVE-2015-9284
|
# This gem provides a mitigation against CVE-2015-9284
|
||||||
gem 'omniauth-rails_csrf_protection', '~> 0.1.2'
|
gem 'omniauth-rails_csrf_protection', '~> 0.1.2'
|
||||||
# A Ruby wrapper around Blizzard's Game Data and Profile APIs
|
# 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
|
# A gem that provides Rails integration for the Sentry error logger
|
||||||
gem 'sentry-rails', '~> 4.4.0'
|
gem 'sentry-rails', '~> 4.4.0'
|
||||||
gem 'sentry-ruby', '~> 4.4.1'
|
gem 'sentry-ruby', '~> 4.4.1'
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
GIT
|
GIT
|
||||||
remote: https://github.com/Dainii/rbattlenet
|
remote: https://github.com/Dainii/rbattlenet
|
||||||
revision: 52c159e1418350247c2f928f08930e0881bc6827
|
revision: 6fc990a743b1cec56e95820aec9222b5ff2e843a
|
||||||
specs:
|
specs:
|
||||||
rbattlenet (2.2.6)
|
rbattlenet (2.2.7)
|
||||||
require_all
|
require_all
|
||||||
typhoeus (~> 1.1)
|
typhoeus (~> 1.1)
|
||||||
|
|
||||||
@@ -411,7 +411,7 @@ DEPENDENCIES
|
|||||||
rails (~> 6.1.3, >= 6.1.3.1)
|
rails (~> 6.1.3, >= 6.1.3.1)
|
||||||
rails-erd
|
rails-erd
|
||||||
rails-i18n (~> 6.0.0)
|
rails-i18n (~> 6.0.0)
|
||||||
rbattlenet (~> 2.2.6)!
|
rbattlenet (~> 2.2.7)!
|
||||||
redis (~> 4.2.5)
|
redis (~> 4.2.5)
|
||||||
rspec-rails
|
rspec-rails
|
||||||
rubocop
|
rubocop
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
class WowCharactersController < ProtectedController
|
class WowCharactersController < ProtectedController
|
||||||
def index
|
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
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
|
|||||||
@@ -10,10 +10,12 @@ class WowCharacter < ApplicationRecord
|
|||||||
belongs_to :wow_race
|
belongs_to :wow_race
|
||||||
belongs_to :wow_character_title, optional: true
|
belongs_to :wow_character_title, optional: true
|
||||||
belongs_to :wow_guild, 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 :last_position, class_name: 'WowGeoPosition', optional: true
|
||||||
belongs_to :bind_position, class_name: 'WowGeoPosition', optional: true
|
belongs_to :bind_position, class_name: 'WowGeoPosition', optional: true
|
||||||
has_one :wow_character_medium, dependent: :nullify
|
has_one :wow_character_medium, dependent: :destroy
|
||||||
has_many :wow_standings, dependent: :nullify
|
has_many :wow_standings, dependent: :destroy
|
||||||
has_many :wow_reputations, through: :wow_standings
|
has_many :wow_reputations, through: :wow_standings
|
||||||
|
|
||||||
validates :name, presence: true
|
validates :name, presence: true
|
||||||
|
|||||||
10
app/models/wow_covenant.rb
Normal file
10
app/models/wow_covenant.rb
Normal 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
|
||||||
4
app/models/wow_covenant_progress.rb
Normal file
4
app/models/wow_covenant_progress.rb
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
class WowCovenantProgress < ApplicationRecord
|
||||||
|
belongs_to :wow_character
|
||||||
|
belongs_to :wow_covenant
|
||||||
|
end
|
||||||
@@ -10,6 +10,7 @@
|
|||||||
<th scope="col"><%= t('wow_characters.character_list.race') %></th>
|
<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.class') %></th>
|
||||||
<th scope="col"><%= t('wow_characters.character_list.faction') %></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>
|
<th scope="col"><%= t('wow_characters.character_list.level') %></th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
@@ -25,6 +26,7 @@
|
|||||||
<td><%= gender_race_name(character.gender, character.wow_race) %></td>
|
<td><%= gender_race_name(character.gender, character.wow_race) %></td>
|
||||||
<td><%= gender_class_name(character.gender, character.wow_class) %></td>
|
<td><%= gender_class_name(character.gender, character.wow_class) %></td>
|
||||||
<td><%= character.translated_faction %></td>
|
<td><%= character.translated_faction %></td>
|
||||||
|
<td><%= character.wow_covenant&.name %></td>
|
||||||
<td><%= character.level %></td>
|
<td><%= character.level %></td>
|
||||||
</tr>
|
</tr>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
@@ -24,6 +24,8 @@ class WowCharacterDetailWorker < WowSidekiqWorker
|
|||||||
wow_character.wow_guild = find_or_create_wow_guild(result.guild) if result.guild
|
wow_character.wow_guild = find_or_create_wow_guild(result.guild) if result.guild
|
||||||
|
|
||||||
wow_character.save
|
wow_character.save
|
||||||
|
|
||||||
|
update_covenant_progress(wow_character, result.covenant_progress) if result.covenant_progress
|
||||||
end
|
end
|
||||||
|
|
||||||
def find_or_create_wow_guild(guild)
|
def find_or_create_wow_guild(guild)
|
||||||
@@ -36,4 +38,13 @@ class WowCharacterDetailWorker < WowSidekiqWorker
|
|||||||
|
|
||||||
wow_guild.persisted? ? wow_guild : nil
|
wow_guild.persisted? ? wow_guild : nil
|
||||||
end
|
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
|
end
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ class WowCharactersWorker < WowSidekiqWorker
|
|||||||
wow_char.wow_class = WowClass.where(class_id: character.playable_class.id).first
|
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.wow_race = WowRace.where(race_id: character.playable_race.id).first
|
||||||
wow_char.user = user
|
wow_char.user = user
|
||||||
wow_char.account_id = account.map_id
|
wow_char.account_id = account.id
|
||||||
|
|
||||||
locales.each do |locale|
|
locales.each do |locale|
|
||||||
Mobility.with_locale(locale[0]) do
|
Mobility.with_locale(locale[0]) do
|
||||||
|
|||||||
23
app/workers/wow_covenant_detail_worker.rb
Normal file
23
app/workers/wow_covenant_detail_worker.rb
Normal 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
|
||||||
24
app/workers/wow_covenants_worker.rb
Normal file
24
app/workers/wow_covenants_worker.rb
Normal 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
|
||||||
@@ -9,3 +9,4 @@ de-de:
|
|||||||
faction: "Fraktion"
|
faction: "Fraktion"
|
||||||
level: "Niveau"
|
level: "Niveau"
|
||||||
guild: "Gilde"
|
guild: "Gilde"
|
||||||
|
covenant: "Pakte"
|
||||||
|
|||||||
@@ -9,3 +9,4 @@ en-gb:
|
|||||||
faction: "Faction"
|
faction: "Faction"
|
||||||
level: "Level"
|
level: "Level"
|
||||||
guild: "Guild"
|
guild: "Guild"
|
||||||
|
covenant: "Covenant"
|
||||||
|
|||||||
@@ -9,3 +9,4 @@ en-us:
|
|||||||
faction: "Faction"
|
faction: "Faction"
|
||||||
level: "Level"
|
level: "Level"
|
||||||
guild: "Guild"
|
guild: "Guild"
|
||||||
|
covenant: "Covenant"
|
||||||
|
|||||||
@@ -9,3 +9,4 @@ es-es:
|
|||||||
faction: "Facción"
|
faction: "Facción"
|
||||||
level: "Nivel"
|
level: "Nivel"
|
||||||
guild: "Gremio"
|
guild: "Gremio"
|
||||||
|
covenant: "Curia"
|
||||||
|
|||||||
@@ -9,3 +9,4 @@ es-mx:
|
|||||||
faction: "Facción"
|
faction: "Facción"
|
||||||
level: "Nivel"
|
level: "Nivel"
|
||||||
guild: "Gremio"
|
guild: "Gremio"
|
||||||
|
covenant: "Pacto"
|
||||||
|
|||||||
@@ -9,3 +9,4 @@ fr-fr:
|
|||||||
faction: "Faction"
|
faction: "Faction"
|
||||||
level: "Niveau"
|
level: "Niveau"
|
||||||
guild: "Guilde"
|
guild: "Guilde"
|
||||||
|
covenant: "Congrégation"
|
||||||
|
|||||||
@@ -9,3 +9,4 @@ it:
|
|||||||
faction: "Fazione"
|
faction: "Fazione"
|
||||||
level: "Livello"
|
level: "Livello"
|
||||||
guild: "Gilda"
|
guild: "Gilda"
|
||||||
|
covenant: "Congregazione"
|
||||||
|
|||||||
@@ -9,3 +9,4 @@ ko:
|
|||||||
faction: "파벌"
|
faction: "파벌"
|
||||||
level: "수평"
|
level: "수평"
|
||||||
guild: "동업 조합"
|
guild: "동업 조합"
|
||||||
|
covenant: "계약"
|
||||||
|
|||||||
@@ -9,3 +9,4 @@ pt-br:
|
|||||||
faction: "Facção"
|
faction: "Facção"
|
||||||
level: "Nível"
|
level: "Nível"
|
||||||
guild: "Guilda"
|
guild: "Guilda"
|
||||||
|
covenant: "Pacto"
|
||||||
|
|||||||
@@ -9,3 +9,4 @@ ru-ru:
|
|||||||
faction: "Фракция"
|
faction: "Фракция"
|
||||||
level: "Уровень"
|
level: "Уровень"
|
||||||
guild: "Гильдия"
|
guild: "Гильдия"
|
||||||
|
covenant: "Ковенанты"
|
||||||
|
|||||||
@@ -9,3 +9,4 @@ zh-cn:
|
|||||||
faction: "派"
|
faction: "派"
|
||||||
level: "水平"
|
level: "水平"
|
||||||
guild: "公会"
|
guild: "公会"
|
||||||
|
covenant: "盟约"
|
||||||
|
|||||||
@@ -9,3 +9,4 @@ zh-tw:
|
|||||||
faction: "派"
|
faction: "派"
|
||||||
level: "水平"
|
level: "水平"
|
||||||
guild: "公会"
|
guild: "公会"
|
||||||
|
covenant: "盟约"
|
||||||
|
|||||||
14
db/migrate/20210530135118_create_wow_covenants.rb
Normal file
14
db/migrate/20210530135118_create_wow_covenants.rb
Normal 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
|
||||||
11
db/migrate/20210530135651_create_wow_covenant_progresses.rb
Normal file
11
db/migrate/20210530135651_create_wow_covenant_progresses.rb
Normal 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
|
||||||
@@ -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
22
db/schema.rb
generated
@@ -10,7 +10,7 @@
|
|||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# 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
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "plpgsql"
|
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
|
t.index ["class_id"], name: "index_wow_classes_on_class_id", unique: true
|
||||||
end
|
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|
|
create_table "wow_geo_maps", force: :cascade do |t|
|
||||||
t.integer "map_id"
|
t.integer "map_id"
|
||||||
t.jsonb "name"
|
t.jsonb "name"
|
||||||
|
|||||||
5
spec/models/wow_covenant_progress_spec.rb
Normal file
5
spec/models/wow_covenant_progress_spec.rb
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
RSpec.describe WowCovenantProgress, type: :model do
|
||||||
|
pending "add some examples to (or delete) #{__FILE__}"
|
||||||
|
end
|
||||||
5
spec/models/wow_covenant_spec.rb
Normal file
5
spec/models/wow_covenant_spec.rb
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
RSpec.describe WowCovenant, type: :model do
|
||||||
|
pending "add some examples to (or delete) #{__FILE__}"
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user