summaryrefslogtreecommitdiff
path: root/app/controllers/matches_controller.rb
diff options
context:
space:
mode:
authortkimia <tkimia@purdue.edu>2014-04-06 21:16:24 -0400
committertkimia <tkimia@purdue.edu>2014-04-06 21:16:24 -0400
commit0afd45939facfc9bdbc7481e649af0ab89b7b029 (patch)
tree435229467dd4adfd0612d081cce8ef75b6a4644b /app/controllers/matches_controller.rb
parent0f982ba511d4f38322f69a6aaed768181b4e2852 (diff)
parentf06e7769ec201f17adc87251da63075a86ce1a94 (diff)
Merge branch 'master' of https://github.com/LukeShu/leaguer
Conflicts: app/assets/stylesheets/matches.css.scss
Diffstat (limited to 'app/controllers/matches_controller.rb')
-rw-r--r--app/controllers/matches_controller.rb32
1 files changed, 31 insertions, 1 deletions
diff --git a/app/controllers/matches_controller.rb b/app/controllers/matches_controller.rb
index 28bc512..e9fe727 100644
--- a/app/controllers/matches_controller.rb
+++ b/app/controllers/matches_controller.rb
@@ -5,6 +5,7 @@ class MatchesController < ApplicationController
# GET /matches.json
require 'httparty'
require 'json'
+ require 'delayed_job'
def index
@matches = @tournament.matches
@@ -14,6 +15,8 @@ class MatchesController < ApplicationController
@height = 200 * 2**Math.log2(@matches.count).floor + 100;
end
+
+
def get_riot_info
if signed_in?
@@ -118,14 +121,41 @@ class MatchesController < ApplicationController
end #end def
# GET /matches/1
# GET /matches/1.json
+
+ def is_match_over
+ response = HTTParty.get("https://prod.api.pvp.net/api/lol/na/v1.3/summoner/by-name/#{@first}?api_key=ad539f86-22fd-474d-9279-79a7a296ac38")
+ riot_id = response["#{@first}"]['id']
+ #recent game information
+ game_info = HTTParty.get("https://prod.api.pvp.net/api/lol/na/v1.3/game/by-summoner/#{riot_id}/recent?api_key=ad539f86-22fd-474d-9279-79a7a296ac38")
+ first_id = game_info["games"][0]["gameId"]
+
+ while true do
+ sleep(240) #wait four minutes
+
+ recent = HTTParty.get("https://prod.api.pvp.net/api/lol/na/v1.3/game/by-summoner/#{riot_id}/recent?api_key=ad539f86-22fd-474d-9279-79a7a296ac38")
+ current_id = recent["games"][0]["gameId"]
+
+ if current_id != first_id
+ @match.status = 2
+ end
+ end #while
+ end
+ handle_asynchronously :is_match_over
+
def show
+ if @match.id == 1
+ is_match_over
+ end
+
+
end
private
# Use callbacks to share common setup or constraints between actions.
def set_match
set_tournament
- @match = @tournament.matches.find(params[:id]);
+ @match = @tournament.matches.find(params[:id])
+ @first = @match.teams.first.users.first.user_name.downcase
end
def set_tournament
@tournament = Tournament.find(params[:tournament_id])