summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorLuke Shumaker <shumakl@purdue.edu>2014-04-27 22:25:26 -0400
committerLuke Shumaker <shumakl@purdue.edu>2014-04-27 22:25:26 -0400
commit7722baf950085f57bd037f918b81440219a56846 (patch)
treebc661bcd3572d94b3578225f130de45febd9f834 /lib
parent35674c86626981a990e9cbcc3e95a23c5cf61356 (diff)
riot_api: update interface, add matchId detection
Diffstat (limited to 'lib')
-rw-r--r--lib/sampling/riot_api.rb45
1 files changed, 33 insertions, 12 deletions
diff --git a/lib/sampling/riot_api.rb b/lib/sampling/riot_api.rb
index 677749b..333095c 100644
--- a/lib/sampling/riot_api.rb
+++ b/lib/sampling/riot_api.rb
@@ -31,6 +31,11 @@ module Sampling
end
protected
+ def self.stats_available
+ ["win", "numDeaths", "turretsKilled", "championsKilled", "minionsKilled", "assists"]
+ end
+
+ protected
class Job < ThrottledApiRequest
def initialize(request, args={})
@url = Sampling::RiotApi::url(request, args)
@@ -79,6 +84,26 @@ module Sampling
end
##
+ # TODO description
+ public
+ def self.can_get?(user, stat)
+ if user.nil?
+ return 0
+ end
+ summoner = user.get_remote_username(match.tournament_stage.tournament.game)
+ if summoner.nil?
+ return 0
+ end
+ if summoner["id"].nil?
+ return 0
+ end
+ unless stats_available.include?(stat)
+ return 0
+ end
+ return 2
+ end
+
+ ##
# This sampling method uses remote IDs
public
def self.uses_remote?
@@ -105,10 +130,10 @@ module Sampling
user = User.find(@user_id)
game = Game.find(@game_id)
- normalized_summoner_name = data.keys.first
+ standardized_summoner_name = data.keys.first
remote_data = {
- :id => data[normalized_summoner_name]["id"],
- :name => data[normalized_summoner_name]["name"],
+ :id => data[standardized_summoner_name]["id"],
+ :name => data[standardized_summoner_name]["name"],
}
user.set_remote_username(game, remote_data)
@@ -126,18 +151,19 @@ module Sampling
##
# Fetch all the statistics for a match.
public
- def self.sampling_start(match)
+ def self.sampling_start(match, stats)
@match.teams.each do |team|
team.users.each do |user|
- Delayed::Job.enqueue(MatchJob.new(user, match, nil), :queue => api_name)
+ Delayed::Job.enqueue(MatchJob.new(user, match, stats.map{|stat|stat[:name]}, nil), :queue => api_name)
end
end
end
protected
class FetchStatisticsJob < Job
- def initialize(user, match, last_game_id)
+ def initialize(user, match, stats, last_game_id)
@user_id = user.id
@match_id = match.id
+ @stats = stats
@last_game_id = last_game_id
# Get the summoner id
@@ -155,7 +181,7 @@ module Sampling
# 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
+ @stats.each do |stat|
Statistic.create(user: user, match: match, name: stat, value: data["games"][0]["stats"][stat])
end
end
@@ -164,11 +190,6 @@ module Sampling
end
public
- def self.sampling_done?(match)
- # TODO
- end
-
- public
def self.render_user_interaction(match, user)
return ""
end