import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;


public class Main {
	public static String sendRequest(String url)
	{
		String response = "";
		try
		{
		URL obj = new URL(url);
		HttpURLConnection con = (HttpURLConnection) obj.openConnection();
		con.setRequestMethod("GET");
		BufferedReader in = new BufferedReader(
				new InputStreamReader(con.getInputStream()));
		String inputLine;
		while ((inputLine = in.readLine()) != null) {
			response += inputLine;
		}
		in.close();
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
		return response;
	}
	public static String getIDfromName(String name)
	{
		String url = "https://euw.api.pvp.net";
		url += "/api/lol/euw/v1.4/summoner/by-name/";
		url += name;
		url += "?api_key=d64abb1e-98da-442c-b406-ea45409217ae";
		try {
			String response = sendRequest(url);
			int i = 0;
			while(!response.substring(i, i+2).equals("id"))
				i++;
			i+=3;
			String todo = "";
			while(response.charAt(++i) != ',') todo += response.charAt(i);
			return todo;
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return "";
	}
	public static String[] getGens(String id)
	{
		String[] autres = new String[9];
		String url = "https://euw.api.pvp.net";
		url += "/observer-mode/rest/consumer/getSpectatorGameInfo/EUW1/" + id;
		url += "?api_key=d64abb1e-98da-442c-b406-ea45409217ae";
		String response = sendRequest(url);
		int i = 0;
		int count = 0;
		for(int j = 0 ; j < 10 ; j++)
		{
			while(!response.substring(i, i+10).equals("summonerId"))
				i++;
			i += 11;
			String todo = "";
			while(response.charAt(++i) != ',') todo += response.charAt(i);
			if(!todo.equals(id))
				autres[count++] = todo;
		}
		return autres;
	}
	
	public static void main(String[] args) 
	{
		String id = getIDfromName("Bloody Bloop");
		for(String s : getGens(id))
		{
			String url = "https://euw.api.pvp.net";
			url += "/api/lol/euw/v2.5/league/by-summoner/" + id;
			url += "?api_key=d64abb1e-98da-442c-b406-ea45409217ae";
			String response = sendRequest(url);
			
			System.out.println(response);
		}
	}
}
