add creature and base rp_world
This commit is contained in:
22
app/workers/wow_creature_families_worker.rb
Normal file
22
app/workers/wow_creature_families_worker.rb
Normal file
@@ -0,0 +1,22 @@
|
||||
# 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
|
||||
22
app/workers/wow_creature_types_worker.rb
Normal file
22
app/workers/wow_creature_types_worker.rb
Normal file
@@ -0,0 +1,22 @@
|
||||
# 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
|
||||
42
app/workers/wow_creatures_worker.rb
Normal file
42
app/workers/wow_creatures_worker.rb
Normal file
@@ -0,0 +1,42 @@
|
||||
# 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
|
||||
Reference in New Issue
Block a user