From 7b5bf825a8174712f3ef6e9ea7f6180e7d230f99 Mon Sep 17 00:00:00 2001 From: nfoy Date: Sun, 6 Apr 2014 20:18:17 -0400 Subject: Auto-Checking for a match's end is implemented. --- app/controllers/matches_controller.rb | 32 +++++++++++++++++++++++++++++++- app/views/matches/show.html.erb | 2 +- 2 files changed, 32 insertions(+), 2 deletions(-) (limited to 'app') diff --git a/app/controllers/matches_controller.rb b/app/controllers/matches_controller.rb index e773667..c369717 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]) diff --git a/app/views/matches/show.html.erb b/app/views/matches/show.html.erb index 20860e2..44fe9ee 100644 --- a/app/views/matches/show.html.erb +++ b/app/views/matches/show.html.erb @@ -61,7 +61,7 @@ Players see the Peer Review Page Host see the Game Status --> -<% if @match.status == 0 %> +if (@match.status==0) %> <% if @tournament.players.include?(current_user) %> <% @match.teams.each do |team| %>