add WowSpell

This commit is contained in:
2021-05-30 14:32:34 +02:00
parent df26a9ca6f
commit d0e5824d40
7 changed files with 79 additions and 5 deletions

View File

@@ -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.5', git: 'https://github.com/Dainii/rbattlenet' gem 'rbattlenet', '~> 2.2.6', 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'

View File

@@ -1,8 +1,8 @@
GIT GIT
remote: https://github.com/Dainii/rbattlenet remote: https://github.com/Dainii/rbattlenet
revision: 0b430de01052dd66430c50cd391570ba81d6d699 revision: 52c159e1418350247c2f928f08930e0881bc6827
specs: specs:
rbattlenet (2.2.5) rbattlenet (2.2.6)
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.5)! rbattlenet (~> 2.2.6)!
redis (~> 4.2.5) redis (~> 4.2.5)
rspec-rails rspec-rails
rubocop rubocop

7
app/models/wow_spell.rb Normal file
View File

@@ -0,0 +1,7 @@
class WowSpell < ApplicationRecord
extend Mobility
translates :name, :description
validates :name, presence: true
validates :spell_id, presence: true, uniqueness: true
end

View File

@@ -0,0 +1,38 @@
# frozen_string_literal: true
class WowSpellsWorker < WowSidekiqWorker
def perform(spell_id, batch_size, keep_going_on)
RBattlenet.authenticate(client_id: ENV['BLIZZARD_API_CLIENT_ID'], client_secret: ENV['BLIZZARD_API_CLIENT_SECRET'])
RBattlenet.set_options(locale: 'all')
params = {
_page: 1,
_pageSize: batch_size,
orderby: 'id',
filters: { id: "[#{spell_id},]" }
}
result = RBattlenet::Wow::Search::Spell.find(params)
return unless result.status_code == 200
result.results&.each do |spell|
wow_spell = WowSpell.find_or_initialize_by(spell_id: spell.data.id)
wow_spell.media_id = spell.data.media.id if spell.data.media.id
# Localisation data
locales.each do |locale|
Mobility.with_locale(locale[0]) do
wow_spell.name = spell.data.name[locale[1]]
end
end
wow_spell.save
end
# Create a new job for the next batch if keep_going_on is true
return unless keep_going_on && !result.results.count.zero?
WowSpellsWorker.perform_async(result.results.last.data.id + 1, batch_size, keep_going_on)
end
end

View File

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

12
db/schema.rb generated
View File

@@ -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_28_214602) do ActiveRecord::Schema.define(version: 2021_05_30_121125) 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"
@@ -374,6 +374,16 @@ ActiveRecord::Schema.define(version: 2021_05_28_214602) do
t.index ["wow_reputation_tier_id"], name: "index_wow_reputations_on_wow_reputation_tier_id" t.index ["wow_reputation_tier_id"], name: "index_wow_reputations_on_wow_reputation_tier_id"
end end
create_table "wow_spells", force: :cascade do |t|
t.integer "spell_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 ["spell_id"], name: "index_wow_spells_on_spell_id", unique: true
end
create_table "wow_standings", force: :cascade do |t| create_table "wow_standings", force: :cascade do |t|
t.bigint "wow_character_id" t.bigint "wow_character_id"
t.bigint "wow_reputation_id" t.bigint "wow_reputation_id"

View File

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