-
# frozen_string_literal: true
-
-
module ApplicationCable
-
class Channel < ActionCable::Channel::Base
-
end
-
end
-
# frozen_string_literal: true
-
-
module ApplicationCable
-
class Connection < ActionCable::Connection::Base
-
end
-
end
-
# frozen_string_literal: true
-
-
class ApplicationController < ActionController::Base
-
around_action :switch_locale
-
-
def switch_locale(&action)
-
locale = extract_locale
-
I18n.with_locale(locale, &action)
-
end
-
-
def new_session_path(_scope)
-
new_user_session_path
-
end
-
-
def extract_locale
-
if params[:locale]
-
I18n.locale_available?(params[:locale]) ? params[:locale] : I18n.default_locale
-
elsif request.env['HTTP_ACCEPT_LANGUAGE']
-
I18n.locale_available?(request.env['HTTP_ACCEPT_LANGUAGE']) ? request.env['HTTP_ACCEPT_LANGUAGE'] : I18n.default_locale
-
else
-
I18n.default_locale
-
end
-
end
-
-
def default_url_options
-
{ locale: I18n.locale }
-
end
-
end
-
# frozen_string_literal: true
-
-
class HomeController < ApplicationController
-
def index; end
-
end
-
# frozen_string_literal: true
-
-
class ProtectedController < ApplicationController
-
before_action :authenticate_user!
-
include Pagy::Backend
-
end
-
# frozen_string_literal: true
-
-
class RpWorldsController < ApplicationController
-
before_action :set_rp_world, only: [:show, :edit, :update, :destroy]
-
-
# GET /rp_worlds
-
def index
-
@rp_worlds = RpWorld.all
-
end
-
-
# GET /rp_worlds/1
-
def show; end
-
-
# GET /rp_worlds/1/edit
-
def edit; end
-
-
# POST /rp_worlds
-
def create
-
@rp_world = RpWorld.new(rp_world_params)
-
-
if @rp_world.save
-
redirect_to @rp_world, notice: 'Rp world was successfully created.'
-
else
-
render :new
-
end
-
end
-
-
# PATCH/PUT /rp_worlds/1
-
def update
-
if @rp_world.update(rp_world_params)
-
redirect_to @rp_world, notice: 'Rp world was successfully updated.'
-
else
-
render :edit
-
end
-
end
-
-
# DELETE /rp_worlds/1
-
def destroy
-
@rp_world.destroy
-
redirect_to rp_worlds_url, notice: 'Rp world was successfully destroyed.'
-
end
-
-
private
-
-
# Use callbacks to share common setup or constraints between actions.
-
def set_rp_world
-
@rp_world = RpWorld.includes(:wow_characters).find(params[:id])
-
end
-
-
# Only allow a list of trusted parameters through.
-
def rp_world_params
-
params.require(:rp_world).permit(:name, :description)
-
end
-
end
-
# frozen_string_literal: true
-
-
# Controller: Callback
-
#
-
# Description: Callback method for Bnet
-
module Users
-
class OmniauthCallbacksController < Devise::OmniauthCallbacksController
-
skip_before_action :verify_authenticity_token, only: :bnet
-
-
def bnet
-
@user = User.from_omniauth(request.env['omniauth.auth'])
-
-
if @user.persisted?
-
unless ENV['ALLOWED_BNET_USERS'].split(',').include?(@user.battletag)
-
set_flash_message(:alert, :not_authorized)
-
redirect_to root_path
-
return
-
end
-
sign_in_and_redirect @user, event: :authentication
-
WowCharactersWorker.perform_async(@user.id)
-
WowMountsCollectionWorker.perform_async(@user.id)
-
WowPetsCollectionWorker.perform_async(@user.id)
-
set_flash_message(:notice, :success, kind: 'Bnet') if is_navigational_format?
-
else
-
session['devise.bnet_data'] = request.env['omniauth.auth'].except(:extra)
-
redirect_to new_user_registration_url
-
end
-
end
-
-
def failure
-
redirect_to root_path
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
class WowCharactersController < ProtectedController
-
def index
-
@wow_characters = current_user.wow_characters.includes(
-
:wow_realm,
-
:wow_race,
-
:wow_class,
-
:wow_character_medium,
-
:wow_guild,
-
:wow_covenant
-
)
-
end
-
-
def show
-
@wow_character = current_user.wow_characters.includes(
-
wow_standings: {
-
wow_reputation: {
-
wow_reputation_tier: :wow_reputation_tier_levels
-
}
-
}
-
).find(params[:id])
-
meta_reputation_ids = @wow_character.wow_standings.map { |standing| standing.wow_reputation.meta_wow_reputation_id }.uniq
-
@meta_wow_reputations = WowReputation.find(meta_reputation_ids)
-
end
-
end
-
# frozen_string_literal: true
-
-
class WowMountsController < ProtectedController
-
def index
-
@pagy, @wow_mounts = pagy(WowMount.includes(:users), items: 12)
-
end
-
-
def show
-
@wow_mount = WowMount.find(params[:id])
-
end
-
end
-
# frozen_string_literal: true
-
-
class WowPetsController < ProtectedController
-
def index
-
@pagy, @wow_pets = pagy(WowPet.includes(:users), items: 12)
-
end
-
-
def show
-
@wow_pet = WowPet.find(params[:id])
-
end
-
end
-
# frozen_string_literal: true
-
-
class WowReputationsController < ProtectedController
-
def index
-
@pagy, @wow_reputations = pagy(WowReputation.non_meta_reputations, items: 20)
-
end
-
-
def show
-
@wow_reputation = WowReputation.find(params[:id])
-
end
-
end
-
# frozen_string_literal: true
-
-
1
module ApplicationHelper
-
1
include Pagy::Frontend
-
-
1
def bootstrap_class_for_flash(flash_type)
-
case flash_type
-
when 'success'
-
'alert-success'
-
when 'error'
-
'alert-danger'
-
when 'alert'
-
'alert-warning'
-
when 'notice'
-
'alert-primary'
-
else
-
'alert-secondary'
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
module HomeHelper
-
end
-
# frozen_string_literal: true
-
-
1
module ProtectedHelper
-
end
-
# frozen_string_literal: true
-
-
1
module RpWorldHelper
-
end
-
# frozen_string_literal: true
-
-
1
module WelcomeHelper
-
end
-
# frozen_string_literal: true
-
-
1
module WowCharactersHelper
-
1
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
-
# frozen_string_literal: true
-
-
1
module WowClassesHelper
-
1
def gender_class_name(gender, wow_class)
-
case gender
-
when 'FEMALE'
-
wow_class.female_name
-
when 'MALE'
-
wow_class.male_name
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
module WowMountsHelper
-
1
def mount_owned?(mount)
-
mount.users.include? current_user
-
end
-
end
-
# frozen_string_literal: true
-
-
1
module WowPetsHelper
-
1
def pet_owned?(pet)
-
pet.users.include? current_user
-
end
-
end
-
# frozen_string_literal: true
-
-
1
module WowRacesHelper
-
1
def gender_race_name(gender, wow_race)
-
case gender
-
when 'FEMALE'
-
wow_race.female_name
-
when 'MALE'
-
wow_race.male_name
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
1
module WowReputationsHelper
-
end
-
# frozen_string_literal: true
-
-
1
module WowStandingsHelper
-
1
def reput_pourcentage(standing, tier)
-
max = tier.max_value
-
min = tier.min_value
-
value = standing.value
-
-
return 100 if max == min
-
return value * 100 / (max - min) if max.positive? && (min.positive? || min.zero?)
-
return value * -100 / (min - max) if min.negative? && (max.negative? || max.zero?)
-
-
0
-
end
-
end
-
# frozen_string_literal: true
-
-
class ApplicationJob < ActiveJob::Base
-
# Automatically retry jobs that encountered a deadlock
-
# retry_on ActiveRecord::Deadlocked
-
-
# Most jobs are safe to ignore if the underlying records are no longer available
-
# discard_on ActiveJob::DeserializationError
-
end
-
# frozen_string_literal: true
-
-
class ApplicationMailer < ActionMailer::Base
-
default from: 'from@example.com'
-
layout 'mailer'
-
end
-
# frozen_string_literal: true
-
-
1
class ApplicationRecord < ActiveRecord::Base
-
1
self.abstract_class = true
-
end
-
# frozen_string_literal: true
-
-
class LearnedWowPetAbility < ApplicationRecord
-
belongs_to :wow_pet
-
belongs_to :wow_pet_ability
-
end
-
# frozen_string_literal: true
-
-
class RpWorld < ApplicationRecord
-
belongs_to :user
-
alias_attribute :owner, :user
-
has_many :wow_character_play_rp_worlds, dependent: :destroy
-
has_many :wow_characters, through: :wow_character_play_rp_worlds
-
alias_attribute :members, :wow_characters
-
-
validates :name, presence: true
-
end
-
# frozen_string_literal: true
-
-
# Model: User
-
#
-
# Description: Define an application user. the only authentication mecanism
-
# is omniauthable with the BattleNet API
-
1
class User < ApplicationRecord
-
1
devise :rememberable, :omniauthable, omniauth_providers: [:bnet]
-
-
1
has_many :wow_characters, dependent: :destroy
-
1
has_many :user_obtain_wow_mounts, dependent: :destroy
-
1
has_many :wow_mounts, through: :user_obtain_wow_mounts
-
1
has_many :user_obtain_wow_pets, dependent: :destroy
-
1
has_many :wow_pets, through: :user_obtain_wow_pets
-
-
1
validates :battletag, presence: true, uniqueness: true
-
-
1
def self.from_omniauth(auth)
-
user = User.where(provider: auth.provider, uid: auth.uid).first_or_initialize
-
-
user.provider = auth.provider
-
user.uid = auth.uid
-
user.battletag = auth.info.battletag
-
user.token_expires = auth.credentials.expires
-
user.token_expire_at = Time.at(auth.credentials.expires_at).utc
-
user.token = auth.credentials.token
-
-
user.save
-
-
user
-
end
-
-
1
def self.new_with_session(params, session)
-
super.tap do |user|
-
if (data = session['devise.bnet_data']) && session['devise.bnet_data']['extra']['raw_info'] && user.email.blank?
-
user.email = data['email']
-
end
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
class UserObtainWowMount < ApplicationRecord
-
belongs_to :user
-
belongs_to :wow_mount
-
end
-
# frozen_string_literal: true
-
-
class UserObtainWowPet < ApplicationRecord
-
belongs_to :user
-
belongs_to :wow_pet
-
end
-
# frozen_string_literal: true
-
-
class WowCharacter < ApplicationRecord
-
extend Mobility
-
translates :translated_faction, :translated_gender
-
-
belongs_to :user
-
belongs_to :wow_realm
-
belongs_to :wow_class
-
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: :destroy
-
has_many :wow_standings, dependent: :destroy
-
has_many :wow_reputations, through: :wow_standings
-
has_many :wow_character_play_rp_worlds, dependent: :destroy
-
has_many :rp_worlds, through: :wow_character_play_rp_worlds
-
-
validates :name, presence: true
-
validates :character_id, presence: true, uniqueness: true
-
end
-
# frozen_string_literal: true
-
-
class WowCharacterMedium < ApplicationRecord
-
belongs_to :wow_character
-
end
-
# frozen_string_literal: true
-
-
class WowCharacterPlayRpWorld < ApplicationRecord
-
belongs_to :wow_character
-
belongs_to :rp_world
-
-
validates :status, presence: true, format: { with: /(INVITED|PENDING|PLAYING|BANNED)/ }
-
validates :role, presence: true, format: { with: /(PLAYER|MODERATOR|ADMIN)/ }
-
end
-
# frozen_string_literal: true
-
-
class WowCharacterTitle < ApplicationRecord
-
extend Mobility
-
translates :name, :male_name, :female_name
-
-
has_many :wow_characters, dependent: :nullify
-
-
validates :name, presence: true
-
validates :title_id, presence: true, uniqueness: true
-
end
-
# frozen_string_literal: true
-
-
class WowClass < ApplicationRecord
-
extend Mobility
-
translates :name, :power_type, :male_name, :female_name
-
-
has_many :wow_characters, dependent: :nullify
-
-
validates :name, presence: true
-
validates :class_id, presence: true, uniqueness: true
-
end
-
# frozen_string_literal: true
-
-
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
-
# frozen_string_literal: true
-
-
class WowCovenantProgress < ApplicationRecord
-
belongs_to :wow_character
-
belongs_to :wow_covenant
-
end
-
# frozen_string_literal: true
-
-
class WowCreature < ApplicationRecord
-
extend Mobility
-
translates :name
-
-
belongs_to :wow_creature_family, optional: true
-
belongs_to :wow_creature_type, optional: true
-
-
validates :name, presence: true
-
validates :creature_id, presence: true, uniqueness: true
-
end
-
# frozen_string_literal: true
-
-
class WowCreatureFamily < ApplicationRecord
-
extend Mobility
-
translates :name
-
-
has_many :wow_creatures, dependent: :destroy
-
-
validates :name, presence: true
-
validates :creature_family_id, presence: true, uniqueness: true
-
end
-
# frozen_string_literal: true
-
-
class WowCreatureType < ApplicationRecord
-
extend Mobility
-
translates :name
-
-
has_many :wow_creatures, dependent: :destroy
-
-
validates :name, presence: true
-
validates :creature_type_id, presence: true, uniqueness: true
-
end
-
# frozen_string_literal: true
-
-
class WowGeoMap < ApplicationRecord
-
extend Mobility
-
translates :name
-
-
has_many :wow_geo_positions, dependent: :destroy
-
-
validates :name, presence: true
-
validates :map_id, presence: true, uniqueness: true
-
end
-
# frozen_string_literal: true
-
-
class WowGeoPosition < ApplicationRecord
-
belongs_to :wow_geo_map
-
belongs_to :wow_geo_zone
-
-
has_one(
-
:last_position_character,
-
class_name: 'WowCharacter',
-
foreign_key: 'last_position_id',
-
inverse_of: :last_position,
-
dependent: :destroy
-
)
-
has_one(
-
:bind_position_character,
-
class_name: 'WowCharacter',
-
foreign_key: 'bind_position_id',
-
inverse_of: :bind_position,
-
dependent: :destroy
-
)
-
end
-
# frozen_string_literal: true
-
-
class WowGeoZone < ApplicationRecord
-
extend Mobility
-
translates :name
-
-
has_many :wow_geo_positions, dependent: :destroy
-
-
validates :name, presence: true
-
validates :zone_id, presence: true, uniqueness: true
-
end
-
# frozen_string_literal: true
-
-
class WowGuild < ApplicationRecord
-
extend Mobility
-
translates :translated_faction
-
-
belongs_to :wow_realm
-
has_many :wow_characters, dependent: :nullify
-
-
validates :name, presence: true
-
validates :guild_id, presence: true, uniqueness: true
-
end
-
# frozen_string_literal: true
-
-
class WowItem < ApplicationRecord
-
extend Mobility
-
translates :name
-
-
belongs_to :wow_item_class
-
belongs_to :wow_item_sub_class
-
belongs_to :wow_item_inventory_type
-
belongs_to :wow_item_quality
-
-
validates :name, presence: true
-
validates :item_id, presence: true, uniqueness: true
-
end
-
# frozen_string_literal: true
-
-
class WowItemClass < ApplicationRecord
-
extend Mobility
-
translates :name
-
-
has_many :wow_item_sub_classes, dependent: :destroy
-
has_many :wow_items, dependent: :destroy
-
-
validates :name, presence: true
-
validates :item_class_id, presence: true, uniqueness: true
-
end
-
# frozen_string_literal: true
-
-
class WowItemInventoryType < ApplicationRecord
-
extend Mobility
-
translates :name
-
-
has_many :wow_items, dependent: :destroy
-
-
validates :name, presence: true
-
validates :item_inventory_type, presence: true, uniqueness: true
-
end
-
# frozen_string_literal: true
-
-
class WowItemQuality < ApplicationRecord
-
extend Mobility
-
translates :name
-
-
has_many :wow_items, dependent: :destroy
-
-
validates :name, presence: true
-
validates :item_quality_type, presence: true, uniqueness: true
-
end
-
# frozen_string_literal: true
-
-
class WowItemSubClass < ApplicationRecord
-
extend Mobility
-
translates :display_name, :verbose_name
-
-
belongs_to :wow_item_class
-
has_many :wow_items, dependent: :destroy
-
-
validates :item_sub_class_id, presence: true, uniqueness: { scope: :wow_item_class }
-
end
-
# frozen_string_literal: true
-
-
class WowMount < ApplicationRecord
-
extend Mobility
-
translates :name, :description, :translated_faction, :translated_source
-
-
has_many :user_obtain_wow_mounts, dependent: :destroy
-
has_many :users, through: :user_obtain_wow_mounts
-
-
validates :name, presence: true
-
validates :mount_id, presence: true, uniqueness: true
-
end
-
# frozen_string_literal: true
-
-
class WowPet < ApplicationRecord
-
extend Mobility
-
translates :name, :translated_battle_pet_type, :description, :translated_source_type
-
-
has_many :learned_wow_pet_abilities, dependent: :destroy
-
has_many :wow_pet_abilities, through: :learned_wow_pet_abilities
-
has_many :user_obtain_wow_pets, dependent: :destroy
-
has_many :users, through: :user_obtain_wow_pets
-
-
validates :name, presence: true
-
validates :pet_id, presence: true, uniqueness: true
-
end
-
# frozen_string_literal: true
-
-
class WowPetAbility < ApplicationRecord
-
extend Mobility
-
translates :name, :translated_battle_pet_type
-
-
has_many :learned_wow_pet_abilities, dependent: :destroy
-
has_many :wow_pets, through: :learned_wow_pet_abilities
-
-
validates :name, presence: true
-
validates :ability_id, presence: true, uniqueness: true
-
end
-
# frozen_string_literal: true
-
-
1
class WowRace < ApplicationRecord
-
1
extend Mobility
-
1
translates :name, :translated_faction, :male_name, :female_name
-
-
1
has_many :wow_characters, dependent: :nullify
-
-
1
validates :name, presence: true
-
1
validates :race_id, presence: true, uniqueness: true
-
end
-
# frozen_string_literal: true
-
-
class WowRealm < ApplicationRecord
-
extend Mobility
-
translates :name, :category, :realm_type
-
-
has_many :wow_characters, dependent: :nullify
-
-
validates :name, presence: true
-
validates :slug, presence: true
-
validates :realm_id, presence: true, uniqueness: true
-
end
-
# frozen_string_literal: true
-
-
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
-
-
scope :meta_reputations, -> { where(description: nil) }
-
scope :non_meta_reputations, -> { where.not(description: nil) }
-
end
-
# frozen_string_literal: true
-
-
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
-
# frozen_string_literal: true
-
-
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 }
-
-
default_scope { order(:order) }
-
end
-
# frozen_string_literal: true
-
-
class WowSpell < ApplicationRecord
-
extend Mobility
-
translates :name, :description
-
-
validates :name, presence: true
-
validates :spell_id, presence: true, uniqueness: true
-
end
-
# frozen_string_literal: true
-
-
class WowStanding < ApplicationRecord
-
extend Mobility
-
translates :name
-
-
belongs_to :wow_character
-
belongs_to :wow_reputation
-
end
-
# frozen_string_literal: true
-
-
class WowCharacterDetailWorker < WowSidekiqWorker
-
def perform(wow_character_id)
-
return unless (wow_character = WowCharacter.find_by(character_id: wow_character_id))
-
-
RBattlenet.authenticate(client_id: ENV['BLIZZARD_API_CLIENT_ID'], client_secret: ENV['BLIZZARD_API_CLIENT_SECRET'])
-
RBattlenet.set_options(locale: 'en_GB')
-
-
# Public data
-
params = {
-
name: wow_character.name.downcase,
-
realm: wow_character.wow_realm.slug
-
}
-
result = RBattlenet::Wow::Character.find(params)
-
-
return unless result.status_code == 200
-
-
wow_character.achievements_points = result.achievement_points
-
wow_character.last_login_timestamp = Time.at(result.last_login_timestamp.to_s[0..-4].to_i).utc
-
wow_character.average_item_level = result.average_item_level
-
wow_character.equipped_item_level = result.equipped_item_level
-
wow_character.wow_character_title = WowCharacterTitle.find_by(title_id: result.active_title.id) if result.active_title
-
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)
-
wow_guild = WowGuild.find_or_initialize_by(guild_id: guild.id)
-
-
wow_guild.name = guild.name
-
wow_guild.wow_realm = WowRealm.find_by(realm_id: guild.realm.id)
-
-
wow_guild.save
-
-
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
-
# frozen_string_literal: true
-
-
class WowCharacterMediaWorker < WowSidekiqWorker
-
def perform(wow_character_id)
-
return unless (wow_character = WowCharacter.where(character_id: wow_character_id).first)
-
-
RBattlenet.authenticate(client_id: ENV['BLIZZARD_API_CLIENT_ID'], client_secret: ENV['BLIZZARD_API_CLIENT_SECRET'])
-
RBattlenet.set_options(locale: 'en_GB')
-
result = RBattlenet::Wow::Character::Media.find({ name: wow_character.name.downcase, realm: wow_character.wow_realm.slug })
-
-
return unless result.status_code == 200
-
-
return unless (wow_character_media = wow_character.wow_character_medium || WowCharacterMedium.new)
-
-
wow_character_media.wow_character = wow_character
-
wow_character_media.href = result._links.self.href
-
-
return unless result.assets
-
-
result.assets.each do |asset|
-
case asset['key']
-
when 'avatar'
-
wow_character_media.avatar = asset['value']
-
when 'inset'
-
wow_character_media.inset = asset['value']
-
when 'main'
-
wow_character_media.main = asset['value']
-
when 'main-raw'
-
wow_character_media.main_raw = asset['value']
-
end
-
end
-
-
wow_character_media.save
-
end
-
end
-
# frozen_string_literal: true
-
-
class WowCharacterPositionsWorker < WowSidekiqWorker
-
def perform(wow_character_id)
-
return unless (wow_character = WowCharacter.find_by(character_id: wow_character_id))
-
-
# Protected data
-
RBattlenet.set_options(locale: 'all')
-
params = {
-
character_id: wow_character_id,
-
realm_id: wow_character.wow_realm.realm_id,
-
token: wow_character.user.token
-
}
-
result = RBattlenet::Wow::Profile::ProtectedSummary.find(params)
-
-
return unless result.status_code == 200
-
-
if (last_position = result.position)
-
wow_character_last_position = wow_character.last_position || WowGeoPosition.new(last_position_character: wow_character)
-
wow_character_last_position.wow_geo_zone = find_or_create_wow_geo_zone(last_position.zone)
-
wow_character_last_position.wow_geo_map = find_or_create_wow_geo_map(last_position.map)
-
wow_character_last_position.x = last_position.x
-
wow_character_last_position.y = last_position.y
-
wow_character_last_position.z = last_position.z
-
wow_character_last_position.facing = last_position.facing
-
wow_character_last_position.save
-
end
-
-
if (bind_position = result.bind_position)
-
wow_character_bind_position = wow_character.bind_position || WowGeoPosition.new(bind_position_character: wow_character)
-
wow_character_bind_position.wow_geo_zone = find_or_create_wow_geo_zone(bind_position.zone)
-
wow_character_bind_position.wow_geo_map = find_or_create_wow_geo_map(bind_position.map)
-
wow_character_bind_position.x = bind_position.x
-
wow_character_bind_position.y = bind_position.y
-
wow_character_bind_position.z = bind_position.z
-
wow_character_bind_position.facing = bind_position.facing
-
wow_character_bind_position.save
-
end
-
end
-
-
private
-
-
def find_or_create_wow_geo_zone(zone)
-
wow_geo_zone = WowGeoZone.find_or_initialize_by(zone_id: zone.id)
-
locales.each do |locale|
-
Mobility.with_locale(locale[0]) do
-
wow_geo_zone.name = zone.name[locale[1]]
-
end
-
end
-
wow_geo_zone.save
-
-
wow_geo_zone.persisted? ? wow_geo_zone : nil
-
end
-
-
def find_or_create_wow_geo_map(map)
-
wow_geo_map = WowGeoMap.find_or_initialize_by(map_id: map.id)
-
locales.each do |locale|
-
Mobility.with_locale(locale[0]) do
-
wow_geo_map.name = map.name[locale[1]]
-
end
-
end
-
wow_geo_map.save
-
-
wow_geo_map.persisted? ? wow_geo_map : nil
-
end
-
end
-
# frozen_string_literal: true
-
-
class WowCharacterTitleDetailWorker < WowSidekiqWorker
-
def perform(title_id)
-
return unless (title = WowCharacterTitle.where(title_id: title_id).first)
-
-
RBattlenet.set_options(locale: 'all')
-
result = RBattlenet::Wow::Title.find(title_id)
-
-
return unless result.status_code == 200
-
-
# Localisation data
-
locales.each do |locale|
-
Mobility.with_locale(locale[0]) do
-
title.male_name = result.gender_name.male[locale[1]]
-
title.female_name = result.gender_name.female[locale[1]]
-
end
-
end
-
-
title.save
-
end
-
end
-
# frozen_string_literal: true
-
-
class WowCharacterTitlesWorker < 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::Title.all
-
-
return unless result.status_code == 200
-
-
result.titles.each do |title|
-
wow_title = WowCharacterTitle.find_or_initialize_by(title_id: title.id)
-
-
wow_title.href = title.key.href
-
-
# Localisation data
-
locales.each do |locale|
-
Mobility.with_locale(locale[0]) { wow_title.name = title.name[locale[1]] }
-
end
-
-
wow_title.save
-
-
WowCharacterTitleDetailWorker.perform_async(wow_title.title_id) if wow_title.persisted?
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
class WowCharactersWorker < WowSidekiqWorker
-
def perform(user_id)
-
# Update the WoW character list
-
return unless (user = User.find(user_id))
-
-
RBattlenet.set_options(locale: 'all')
-
result = RBattlenet::Wow::Profile::User.find(user.token)
-
-
return unless result.status_code == 200
-
-
result.wow_accounts.each do |account|
-
account.characters.each do |character|
-
wow_char = user.wow_characters.find_or_initialize_by(character_id: character.id)
-
-
wow_char.name = character.name
-
wow_char.gender = character.gender.type
-
wow_char.faction = character.faction.type
-
wow_char.href = character.character.href
-
wow_char.level = character.level
-
wow_char.wow_realm = WowRealm.where(realm_id: character.realm.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.user = user
-
wow_char.account_id = account.id
-
-
locales.each do |locale|
-
Mobility.with_locale(locale[0]) do
-
wow_char.translated_faction = character.faction.name[locale[1]]
-
wow_char.translated_gender = character.gender.name[locale[1]]
-
end
-
end
-
-
wow_char.save
-
-
next unless wow_char.persisted?
-
-
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
-
end
-
# frozen_string_literal: true
-
-
class WowClassDetailWorker < WowSidekiqWorker
-
def perform(class_id)
-
return unless (wow_class = WowClass.find_by(class_id: class_id))
-
-
RBattlenet.set_options(locale: 'all')
-
result = RBattlenet::Wow::PlayableClass.find(class_id)
-
-
return unless result.status_code == 200
-
-
# Localisation data
-
locales.each do |locale|
-
Mobility.with_locale(locale[0]) do
-
wow_class.power_type = result.power_type.name[locale[1]]
-
wow_class.male_name = result.gender_name.male[locale[1]]
-
wow_class.female_name = result.gender_name.female[locale[1]]
-
end
-
end
-
-
wow_class.save
-
end
-
end
-
# frozen_string_literal: true
-
-
class WowClassesWorker < 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::PlayableClass.all
-
-
return unless result.status_code == 200
-
-
result.classes.each do |playable_class|
-
wow_class = WowClass.find_or_initialize_by(class_id: playable_class.id)
-
-
wow_class.href = playable_class.key.href
-
-
# Localisation data
-
locales.each do |locale|
-
Mobility.with_locale(locale[0]) { wow_class.name = playable_class.name[locale[1]] }
-
end
-
-
wow_class.save
-
-
WowClassDetailWorker.perform_async(wow_class.class_id) if wow_class.persisted?
-
end
-
end
-
end
-
# 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
-
# 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
-
# frozen_string_literal: true
-
-
class WowCreatureFamiliesWorker < 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::CreatureFamily.all
-
-
return unless result.status_code == 200
-
-
result.creature_families.each do |creature_family|
-
wow_creature_family = WowCreatureFamily.find_or_initialize_by(creature_family_id: creature_family.id)
-
-
# Localisation data
-
locales.each do |locale|
-
Mobility.with_locale(locale[0]) { wow_creature_family.name = creature_family.name[locale[1]] }
-
end
-
-
wow_creature_family.save
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
class WowCreatureTypesWorker < 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::CreatureType.all
-
-
return unless result.status_code == 200
-
-
result.creature_types.each do |creature_type|
-
wow_creature_type = WowCreatureType.find_or_initialize_by(creature_type_id: creature_type.id)
-
-
# Localisation data
-
locales.each do |locale|
-
Mobility.with_locale(locale[0]) { wow_creature_type.name = creature_type.name[locale[1]] }
-
end
-
-
wow_creature_type.save
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
class WowCreaturesWorker < WowSidekiqWorker
-
def perform(creature_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: "[#{creature_id},]" }
-
}
-
result = RBattlenet::Wow::Search::Creature.find(params)
-
-
return unless result.status_code == 200
-
-
result.results&.each do |creature|
-
wow_creature = WowCreature.find_or_initialize_by(creature_id: creature.data.id)
-
-
wow_creature.display_id = creature.data.creature_displays&.first&.id
-
wow_creature.is_tameable = creature.data&.is_tameable
-
-
wow_creature.wow_creature_family = WowCreatureFamily.find_by(creature_family_id: creature.data.family.id) if creature.data.family
-
wow_creature.wow_creature_type = WowCreatureType.find_by(creature_type_id: creature.data.type.id) if creature.data.type
-
-
# Localisation data
-
locales.each do |locale|
-
Mobility.with_locale(locale[0]) do
-
wow_creature.name = creature.data.name[locale[1]]
-
end
-
end
-
-
wow_creature.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?
-
-
WowCreaturesWorker.perform_async(result.results.last.data.id + 1, batch_size, keep_going_on)
-
end
-
end
-
# frozen_string_literal: true
-
-
class WowGuildDetailWorker < WowSidekiqWorker
-
def perform(wow_guild_id)
-
return unless (wow_guild = WowGuild.find_by(guild_id: wow_guild_id))
-
-
RBattlenet.authenticate(client_id: ENV['BLIZZARD_API_CLIENT_ID'], client_secret: ENV['BLIZZARD_API_CLIENT_SECRET'])
-
RBattlenet.set_options(locale: 'all')
-
-
# Public data
-
params = {
-
name: wow_guild.name.downcase.tr(' ', '-'),
-
realm: wow_guild.wow_realm.slug
-
}
-
result = RBattlenet::Wow::Guild.find(params)
-
-
return unless result.status_code == 200
-
-
wow_guild.achievement_points = result.achievement_points
-
wow_guild.member_count = result.member_count
-
wow_guild.faction = result.faction.type
-
-
# Localisation data
-
locales.each do |locale|
-
Mobility.with_locale(locale[0]) do
-
wow_guild.translated_faction = result.faction.name[locale[1]]
-
end
-
end
-
-
wow_guild.save
-
end
-
end
-
# frozen_string_literal: true
-
-
class WowItemClassDetailWorker < WowSidekiqWorker
-
def perform(item_class_id)
-
return unless (wow_item_class = WowItemClass.find_by(item_class_id: item_class_id))
-
-
RBattlenet.set_options(locale: 'all')
-
result = RBattlenet::Wow::ItemClass.find(item_class_id)
-
-
return unless result.status_code == 200
-
-
result.item_subclasses.each do |item_subclass|
-
wow_item_sub_class = wow_item_class.wow_item_sub_classes.create_with(wow_item_class: wow_item_class).find_or_create_by(item_sub_class_id: item_subclass.id)
-
-
WowItemSubClassDetailWorker.perform_async(wow_item_class.item_class_id, wow_item_sub_class.item_sub_class_id) if wow_item_sub_class.persisted?
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
class WowItemClassesWorker < 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::ItemClass.all
-
-
return unless result.status_code == 200
-
-
result.item_classes.each do |item_class|
-
wow_item_class = WowItemClass.find_or_initialize_by(item_class_id: item_class.id)
-
-
# Localisation data
-
locales.each do |locale|
-
Mobility.with_locale(locale[0]) { wow_item_class.name = item_class.name[locale[1]] }
-
end
-
-
wow_item_class.save
-
-
WowItemClassDetailWorker.perform_async(wow_item_class.item_class_id) if wow_item_class.persisted?
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
class WowItemSubClassDetailWorker < WowSidekiqWorker
-
def perform(item_class_id, item_sub_class_id)
-
return unless (wow_item_sub_class = WowItemSubClass.joins(:wow_item_class).where(item_sub_class_id: item_sub_class_id, wow_item_class: { item_class_id: item_class_id }).first)
-
-
RBattlenet.set_options(locale: 'all')
-
params = {
-
class_id: item_class_id,
-
id: item_sub_class_id
-
}
-
result = RBattlenet::Wow::ItemSubclass.find(params)
-
-
return unless result.status_code == 200
-
-
# Localisation data
-
locales.each do |locale|
-
Mobility.with_locale(locale[0]) do
-
wow_item_sub_class.display_name = result.display_name[locale[1]] if result.display_name
-
wow_item_sub_class.verbose_name = result.verbose_name[locale[1]] if result.verbose_name
-
end
-
end
-
-
wow_item_sub_class.save
-
end
-
end
-
# frozen_string_literal: true
-
-
class WowItemsWorker < WowSidekiqWorker
-
def perform(item_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: "[#{item_id},]" }
-
}
-
result = RBattlenet::Wow::Search::Item.find(params)
-
-
return unless result.status_code == 200
-
-
result.results&.each do |item|
-
wow_item = WowItem.find_or_initialize_by(item_id: item.data.id)
-
-
wow_item.level = item.data.level if item.data.level
-
wow_item.required_level = item.data.required_level if item.data.required_level
-
wow_item.sell_price = item.data.sell_price if item.data.sell_price
-
wow_item.purchase_price = item.data.purchase_price if item.data.purchase_price
-
wow_item.is_equippable = item.data.is_equippable if item.data.is_equippable
-
wow_item.is_stackable = item.data.is_stackable if item.data.is_stackable
-
wow_item.media_id = item.data.media.id if item.data.media.id
-
wow_item.max_count = item.data.max_count if item.data.max_count
-
-
wow_item.wow_item_class = WowItemClass.find_by(item_class_id: item.data.item_class.id)
-
wow_item.wow_item_sub_class = WowItemSubClass.joins(:wow_item_class).where(item_sub_class_id: item.data.item_subclass.id, wow_item_class: { item_class_id: item.data.item_class.id }).first
-
-
wow_item.wow_item_quality = find_or_create_wow_item_quality(item.data.quality)
-
wow_item.wow_item_inventory_type = find_or_create_wow_item_inventory_type(item.data.inventory_type)
-
-
# Localisation data
-
locales.each do |locale|
-
Mobility.with_locale(locale[0]) do
-
wow_item.name = item.data.name[locale[1]]
-
end
-
end
-
-
wow_item.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?
-
-
WowItemsWorker.perform_async(result.results.last.data.id + 1, batch_size, keep_going_on)
-
end
-
-
private
-
-
def find_or_create_wow_item_quality(item_quality)
-
wow_item_quality = WowItemQuality.find_or_initialize_by(item_quality_type: item_quality.type)
-
-
# Localisation data
-
locales.each do |locale|
-
Mobility.with_locale(locale[0]) do
-
wow_item_quality.name = item_quality.name[locale[1]]
-
end
-
end
-
-
wow_item_quality.save
-
-
wow_item_quality.persisted? ? wow_item_quality : nil
-
end
-
-
def find_or_create_wow_item_inventory_type(item_inventory_type)
-
wow_item_inventory_type = WowItemInventoryType.find_or_initialize_by(item_inventory_type: item_inventory_type.type)
-
-
# Localisation data
-
locales.each do |locale|
-
Mobility.with_locale(locale[0]) do
-
wow_item_inventory_type.name = item_inventory_type.name[locale[1]]
-
end
-
end
-
-
wow_item_inventory_type.save
-
-
wow_item_inventory_type.persisted? ? wow_item_inventory_type : nil
-
end
-
end
-
# frozen_string_literal: true
-
-
class WowMountDetailWorker < WowSidekiqWorker
-
def perform(mount_id)
-
return unless (mount = WowMount.find_by(mount_id: mount_id))
-
-
RBattlenet.set_options(locale: 'all')
-
result = RBattlenet::Wow::Mount.find(mount_id)
-
-
return unless result.status_code == 200
-
-
mount.faction = result.faction.type if result.faction
-
-
# Localisation data
-
locales.each do |locale|
-
Mobility.with_locale(locale[0]) do
-
mount.translated_faction = result.faction.name[locale[1]] if result.faction
-
mount.description = result.description[locale[1]]
-
end
-
end
-
-
if result.creature_displays.first
-
mount.creature_display_id = result.creature_displays.first.id
-
-
media = RBattlenet::Wow::CreatureMedia.find(result.creature_displays.first.id)
-
mount.asset_zoom = media.assets.find { |asset| asset['key'] == 'zoom' }.value || nil
-
end
-
-
mount.save
-
end
-
end
-
# frozen_string_literal: true
-
-
class WowMountsCollectionWorker < WowSidekiqWorker
-
def perform(user_id)
-
return unless (user = User.find(user_id))
-
-
RBattlenet.set_options(locale: 'en_US')
-
result = RBattlenet::Wow::Profile::MountsCollection.find(user.token)
-
-
return unless result.status_code == 200
-
-
result.mounts.each do |mount|
-
next unless (local_mount = WowMount.where(mount_id: mount.mount.id).first)
-
-
UserObtainWowMount.where(user: user.id, wow_mount: local_mount.id).first_or_create
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
class WowMountsWorker < 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::Mount.all
-
-
return unless result.status_code == 200
-
-
result.mounts.each do |mount|
-
wow_mount = WowMount.find_or_initialize_by(mount_id: mount.id)
-
-
# Global data
-
wow_mount.href = mount.key.href
-
-
# Localisation data
-
locales.each do |locale|
-
Mobility.with_locale(locale[0]) { wow_mount.name = mount.name[locale[1]] }
-
end
-
-
wow_mount.save
-
-
WowMountDetailWorker.perform_async(wow_mount.mount_id) if wow_mount.persisted?
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
class WowPetAbilitiesWorker < 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::PetAbility.all
-
-
return unless result.status_code == 200
-
-
result.abilities.each do |ability|
-
wow_pet_ability = WowPetAbility.find_or_initialize_by(ability_id: ability.id)
-
-
wow_pet_ability.href = ability.key.href
-
-
# Localisation data
-
locales.each do |locale|
-
Mobility.with_locale(locale[0]) { wow_pet_ability.name = ability.name[locale[1]] }
-
end
-
-
wow_pet_ability.save
-
-
WowPetAbilityDetailWorker.perform_async(wow_pet_ability.ability_id) if wow_pet_ability.persisted?
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
class WowPetAbilityDetailWorker < WowSidekiqWorker
-
def perform(ability_id)
-
return unless (ability = WowPetAbility.find_by(ability_id: ability_id))
-
-
RBattlenet.set_options(locale: 'all')
-
result = RBattlenet::Wow::PetAbility.find(ability_id)
-
-
return unless result.status_code == 200
-
-
ability.battle_pet_type = result.battle_pet_type.type
-
ability.battle_pet_type_id = result.battle_pet_type.id
-
ability.rounds = result.rounds if result.rounds
-
-
# Localisation data
-
locales.each do |locale|
-
Mobility.with_locale(locale[0]) do
-
ability.translated_battle_pet_type = result.battle_pet_type.name[locale[1]]
-
end
-
end
-
-
if result.media
-
media = RBattlenet::Wow::PetAbilityMedia.find(result.media.id)
-
ability.media = media.assets.find { |asset| asset['key'] == 'icon' }.value || nil
-
end
-
-
ability.save
-
end
-
end
-
# frozen_string_literal: true
-
-
class WowPetDetailWorker < WowSidekiqWorker
-
def perform(pet_id)
-
return unless (pet = WowPet.find_by(pet_id: pet_id))
-
-
RBattlenet.set_options(locale: 'all')
-
result = RBattlenet::Wow::Pet.find(pet_id)
-
-
return unless result.status_code == 200
-
-
pet.is_capturable = result.is_capturable
-
pet.is_battlepet = result.is_battlepet
-
pet.is_alliance_only = result.is_alliance_only
-
pet.is_horde_only = result.is_horde_only
-
pet.is_capturable = result.is_capturable
-
pet.is_random_creature_display = result.is_random_creature_display
-
pet.icon = result.icon
-
pet.creature_id = result.creature.id
-
pet.battle_pet_type = result.battle_pet_type.type
-
pet.battle_pet_type_id = result.battle_pet_type.id
-
-
# Localisation data
-
locales.each do |locale|
-
Mobility.with_locale(locale[0]) do
-
pet.translated_battle_pet_type = result.battle_pet_type.name[locale[1]]
-
pet.description = result.description[locale[1]]
-
end
-
end
-
-
unless pet.creature_display_id
-
creature = RBattlenet::Wow::Creature.find(pet.creature_id)
-
pet.creature_display_id = creature.creature_displays.first.id if creature.status_code == 200
-
end
-
-
creature_media = RBattlenet::Wow::CreatureMedia.find(pet.creature_display_id)
-
pet.media_zoom_url = creature_media.assets.first.value if creature_media.status_code == 200
-
-
result.abilities&.each do |ability|
-
next unless (local_ability = WowPetAbility.where(ability_id: ability.ability.id).first)
-
-
LearnedWowPetAbility.where(wow_pet: pet.id, wow_pet_ability: local_ability.id).first_or_create
-
end
-
-
pet.save
-
end
-
end
-
# frozen_string_literal: true
-
-
class WowPetsCollectionWorker < WowSidekiqWorker
-
def perform(user_id)
-
return unless (user = User.find(user_id))
-
-
RBattlenet.set_options(locale: 'en_US')
-
result = RBattlenet::Wow::Profile::PetsCollection.find(user.token)
-
-
return unless result.status_code == 200
-
-
result.pets.each do |pet|
-
next unless (local_pet = WowPet.find_by(pet_id: pet.species.id))
-
-
UserObtainWowPet.where(user: user.id, wow_pet: local_pet.id).first_or_create
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
class WowPetsWorker < 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::Pet.all
-
-
return unless result.status_code == 200
-
-
result.pets.each do |pet|
-
wow_pet = WowPet.find_or_initialize_by(pet_id: pet.id)
-
-
# Global data
-
wow_pet.href = pet.key.href
-
-
# Localisation data
-
locales.each do |locale|
-
Mobility.with_locale(locale[0]) { wow_pet.name = pet.name[locale[1]] }
-
end
-
-
wow_pet.save
-
-
WowPetDetailWorker.perform_async(wow_pet.pet_id) if wow_pet.persisted?
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
class WowRaceDetailWorker < WowSidekiqWorker
-
def perform(race_id)
-
return unless (race = WowRace.find_by(race_id: race_id))
-
-
RBattlenet.set_options(locale: 'all')
-
result = RBattlenet::Wow::PlayableRace.find(race_id)
-
-
return unless result.status_code == 200
-
-
race.faction = result.faction.type
-
race.is_selectable = result.is_selectable
-
race.is_allied_race = result.is_allied_race
-
-
# Localisation data
-
locales.each do |locale|
-
Mobility.with_locale(locale[0]) do
-
race.translated_faction = result.faction.name[locale[1]]
-
race.male_name = result.gender_name.male[locale[1]]
-
race.female_name = result.gender_name.female[locale[1]]
-
end
-
end
-
-
race.save
-
end
-
end
-
# frozen_string_literal: true
-
-
class WowRacesWorker < 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::PlayableRace.all
-
-
return unless result.status_code == 200
-
-
result.races.each do |playable_race|
-
wow_race = WowRace.find_or_initialize_by(race_id: playable_race.id)
-
-
# Global data
-
wow_race.href = playable_race.key.href
-
-
# Localisation data
-
locales.each do |locale|
-
Mobility.with_locale(locale[0]) { wow_race.name = playable_race.name[locale[1]] }
-
end
-
-
wow_race.save
-
-
WowRaceDetailWorker.perform_async(wow_race.race_id) if wow_race.persisted?
-
end
-
end
-
end
-
# frozen_string_literal: true
-
-
class WowRealmDetailWorker < WowSidekiqWorker
-
def perform(realm_id)
-
return unless (realm = WowRealm.find_by(realm_id: realm_id))
-
-
RBattlenet.set_options(locale: 'all')
-
result = RBattlenet::Wow::Realm.find(realm_id)
-
-
return unless result.status_code == 200
-
-
realm.locale = result.locale
-
realm.timezone = result.timezone
-
realm.is_tournament = result.is_tournament
-
-
# Localisation data
-
locales.each do |locale|
-
Mobility.with_locale(locale[0]) do
-
realm.realm_type = result.type.name[locale[1]]
-
realm.category = result.category[locale[1]]
-
end
-
end
-
-
realm.save
-
end
-
end
-
# frozen_string_literal: true
-
-
class WowRealmsWorker < 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::Realm.all
-
-
return unless result.status_code == 200
-
-
result.realms.each do |realm|
-
wow_realm = WowRealm.find_or_initialize_by(realm_id: realm.id)
-
-
wow_realm.slug = realm.slug
-
wow_realm.href = realm.key.href
-
-
# Localisation data
-
locales.each do |locale|
-
Mobility.with_locale(locale[0]) { wow_realm.name = realm.name[locale[1]] }
-
end
-
-
wow_realm.save
-
-
WowRealmDetailWorker.perform_async(wow_realm.realm_id) if wow_realm.persisted?
-
end
-
end
-
end
-
# 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
-
# 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
-
# 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
-
# 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
-
# frozen_string_literal: true
-
-
class WowSidekiqWorker
-
include Sidekiq::Worker
-
-
def locales
-
[
-
['en-us', 'en_US'],
-
['es-mx', 'es_MX'],
-
['pt-br', 'pt_BR'],
-
['de-de', 'de_DE'],
-
['en-gb', 'en_GB'],
-
['es-es', 'es_ES'],
-
['fr-fr', 'fr_FR'],
-
['it', 'it_IT'],
-
['ru-ru', 'ru_RU'],
-
['ko', 'ko_KR'],
-
['zh-tw', 'zh_TW'],
-
['zh-cn', 'zh_CN']
-
]
-
end
-
end
-
# 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
-
# 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