add WowGuild model
This commit is contained in:
32
app/workers/wow_guild_detail_worker.rb
Normal file
32
app/workers/wow_guild_detail_worker.rb
Normal file
@@ -0,0 +1,32 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class WowGuildDetailWorker < WowSidekiqWorker
|
||||
def perform(wow_guild_id)
|
||||
return unless (wow_guild = WowGuild.find_by(guild_id: wow_guild_id))
|
||||
|
||||
RBattlenet.authenticate(client_id: ENV['BLIZZARD_API_CLIENT_ID'], client_secret: ENV['BLIZZARD_API_CLIENT_SECRET'])
|
||||
RBattlenet.set_options(locale: 'all')
|
||||
|
||||
# Public data
|
||||
params = {
|
||||
name: wow_guild.name.downcase.tr(' ', '-'),
|
||||
realm: wow_guild.wow_realm.slug
|
||||
}
|
||||
result = RBattlenet::Wow::Guild.find(params)
|
||||
|
||||
return unless result.status_code == 200
|
||||
|
||||
wow_guild.achievement_points = result.achievement_points
|
||||
wow_guild.member_count = result.member_count
|
||||
wow_guild.faction = result.faction.type
|
||||
|
||||
# Localisation data
|
||||
locales.each do |locale|
|
||||
Mobility.with_locale(locale[0]) do
|
||||
wow_guild.translated_faction = result.faction.name[locale[1]]
|
||||
end
|
||||
end
|
||||
|
||||
wow_guild.save
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user