Skip to content

Instantly share code, notes, and snippets.

@kenrick
Forked from Theminijohn/team_ranked_stat_job.rb
Last active August 29, 2015 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kenrick/2d2623ad2b29cff4b090 to your computer and use it in GitHub Desktop.
Save kenrick/2d2623ad2b29cff4b090 to your computer and use it in GitHub Desktop.
require 'perseus'
class TeamRankedStatJob < ActiveJob::Base
attr_reader :team
queue_as :default
def perform(team) #rename team here
@team = team
## Get ready
client = Perseus::Client.new(Settings.rito.api_key, region: team.server)
## Get Info
entries = client.league.entries_by_team(team.full_id).values.flatten
## Create
entries.each do |e|
create_ranked_statistic(e)
end
end
def create_ranked_statistic(e)
RankedStatistic.create(
tier: e.tier,
wins: e.entries.first.wins,
queue: e.queue,
losses: e.entries.first.losses,
team_id: team.id,
division: e.entries.first.division,
is_veteran: e.entries.first.is_veteran,
is_inactive: e.entries.first.is_inactive,
is_hot_streak: e.entries.first.is_hot_streak,
league_points: e.entries.first.league_points,
is_fresh_blood: e.entries.first.is_fresh_blood,
)
end
end
@Theminijohn
Copy link

OP as always <3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment