summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorLuke Shumaker <shumakl@purdue.edu>2014-04-27 22:11:45 -0400
committerLuke Shumaker <shumakl@purdue.edu>2014-04-27 22:11:45 -0400
commit105612b151eced803238a24180c29f92e9685dc8 (patch)
tree9c50728d5b4bd58c0caf423f8157d026abe2563c /lib
parentd4d97f40deff86134944b340433619dff76ac896 (diff)
riot_api: add detecting when a match is done
Diffstat (limited to 'lib')
-rw-r--r--lib/sampling/riot_api.rb22
1 files changed, 16 insertions, 6 deletions
diff --git a/lib/sampling/riot_api.rb b/lib/sampling/riot_api.rb
index d5e9c72..677749b 100644
--- a/lib/sampling/riot_api.rb
+++ b/lib/sampling/riot_api.rb
@@ -129,27 +129,37 @@ module Sampling
def self.sampling_start(match)
@match.teams.each do |team|
team.users.each do |user|
- Delayed::Job.enqueue(MatchJob.new(user, match), :queue => api_name)
+ Delayed::Job.enqueue(MatchJob.new(user, match, nil), :queue => api_name)
end
end
end
protected
class FetchStatisticsJob < Job
- def initialize(user, match)
+ def initialize(user, match, last_game_id)
@user_id = user.id
@match_id = match.id
+ @last_game_id = last_game_id
+
# Get the summoner id
summoner = user.get_remote_username(match.tournament_stage.tournament.game)
- if summoner.nil?
- raise "Someone didn't enter their summoner name"
- end
# Generate the request
super("v1.3/game/by-summoner/%{summonerId}/recent", { :summonerId => summoner["id"] })
end
def handle(data)
user = User.find(@user_id)
match = Match.find(@match_id)
- Statistic.create(user: user, match: match, value: TODO)
+ if @last_game_id.nil?
+ Delayed::Job.enqueue(MatchJob.new(user, match, data["games"][0]["gameId"]), :queue => api_name)
+ else
+ if @last_game_id == data["games"][0]["gameId"]
+ # TODO: perhaps insert a delay here?
+ Delayed::Job.enqueue(MatchJob.new(user, match, @last_game_id), :queue => api_name)
+ else
+ for stat in ["win", "numDeaths", "turretsKilled", "championsKilled", "minionsKilled", "assists"] do
+ Statistic.create(user: user, match: match, name: stat, value: data["games"][0]["stats"][stat])
+ end
+ end
+ end
end
end