29 lines
773 B
Ruby
29 lines
773 B
Ruby
# 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.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
|