continue to backport old code
This commit is contained in:
33
app/workers/wow_mount_detail_worker.rb
Normal file
33
app/workers/wow_mount_detail_worker.rb
Normal file
@@ -0,0 +1,33 @@
|
||||
class WowMountDetailWorker < WowSidekiqWorker
|
||||
def locales
|
||||
super
|
||||
end
|
||||
|
||||
def perform(mount_id)
|
||||
return unless (mount = WowMount.where(mount_id: mount_id).first)
|
||||
|
||||
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
|
||||
19
app/workers/wow_mounts_collection_worker.rb
Normal file
19
app/workers/wow_mounts_collection_worker.rb
Normal file
@@ -0,0 +1,19 @@
|
||||
class WowMountsCollectionWorker
|
||||
include Sidekiq::Worker
|
||||
|
||||
def perform(user_id)
|
||||
# Update the WoW character list
|
||||
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
|
||||
30
app/workers/wow_mounts_worker.rb
Normal file
30
app/workers/wow_mounts_worker.rb
Normal file
@@ -0,0 +1,30 @@
|
||||
class WowMountsWorker < WowSidekiqWorker
|
||||
def locales
|
||||
super
|
||||
end
|
||||
|
||||
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.where(mount_id: mount.id).first_or_initialize
|
||||
|
||||
# Global data
|
||||
wow_mount.mount_id = mount.id
|
||||
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
|
||||
30
app/workers/wow_pet_abilities_worker.rb
Normal file
30
app/workers/wow_pet_abilities_worker.rb
Normal file
@@ -0,0 +1,30 @@
|
||||
class WowPetAbilitiesWorker < WowSidekiqWorker
|
||||
def locales
|
||||
super
|
||||
end
|
||||
|
||||
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.where(ability_id: ability.id).first_or_initialize
|
||||
|
||||
# Global data
|
||||
wow_pet_ability.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
|
||||
33
app/workers/wow_pet_ability_detail_worker.rb
Normal file
33
app/workers/wow_pet_ability_detail_worker.rb
Normal file
@@ -0,0 +1,33 @@
|
||||
class WowPetAbilityDetailWorker < WowSidekiqWorker
|
||||
def locales
|
||||
super
|
||||
end
|
||||
|
||||
def perform(ability_id)
|
||||
|
||||
return unless (ability = WowPetAbility.where(ability_id: ability_id).first)
|
||||
|
||||
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
|
||||
44
app/workers/wow_pet_detail_worker.rb
Normal file
44
app/workers/wow_pet_detail_worker.rb
Normal file
@@ -0,0 +1,44 @@
|
||||
class WowPetDetailWorker < WowSidekiqWorker
|
||||
def locales
|
||||
super
|
||||
end
|
||||
|
||||
def perform(pet_id)
|
||||
|
||||
return unless (pet = WowPet.where(pet_id: pet_id).first)
|
||||
|
||||
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
|
||||
|
||||
if result.abilities
|
||||
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
|
||||
end
|
||||
|
||||
pet.save
|
||||
end
|
||||
end
|
||||
18
app/workers/wow_pets_collection_worker.rb
Normal file
18
app/workers/wow_pets_collection_worker.rb
Normal file
@@ -0,0 +1,18 @@
|
||||
class WowPetsCollectionWorker
|
||||
include Sidekiq::Worker
|
||||
|
||||
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.where(pet_id: pet.species.id).first)
|
||||
|
||||
UserObtainWowPet.where(user: user.id, wow_pet: local_pet.id).first_or_create
|
||||
end
|
||||
end
|
||||
end
|
||||
30
app/workers/wow_pets_worker.rb
Normal file
30
app/workers/wow_pets_worker.rb
Normal file
@@ -0,0 +1,30 @@
|
||||
class WowPetsWorker < WowSidekiqWorker
|
||||
def locales
|
||||
super
|
||||
end
|
||||
|
||||
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.where(pet_id: pet.id).first_or_initialize
|
||||
|
||||
# Global data
|
||||
wow_pet.pet_id = pet.id
|
||||
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
|
||||
20
app/workers/wow_sidekiq_worker.rb
Normal file
20
app/workers/wow_sidekiq_worker.rb
Normal file
@@ -0,0 +1,20 @@
|
||||
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
|
||||
Reference in New Issue
Block a user