19 lines
514 B
Ruby
19 lines
514 B
Ruby
# 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
|