21 lines
526 B
Ruby
21 lines
526 B
Ruby
# frozen_string_literal: true
|
|
|
|
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
|