/// <summary> /// Returns the list of matches for a given tournament. /// </summary> /// <param name="tournamentId">The ID of the tournament.</param> /// <returns></returns> public async Task <List <ChallongeMatch> > GetMatches(ulong tournamentId, string state = "all") { var p = new Dictionary <string, string>(); p.Add("state", state); var res = await httpGet($"tournaments/{tournamentId}/matches.json", p); // convert received format into the proper format List <ChallongeMatch> returns = new List <ChallongeMatch>(); try { List <Dictionary <string, ChallongeMatch> > des = JsonConvert.DeserializeObject <List <Dictionary <string, ChallongeMatch> > >(res); foreach (var dict in des) { returns.Add(dict["match"]); } return(returns); } catch (JsonException) { ChallongeError err = JsonConvert.DeserializeObject <ChallongeError>(res); throw new ChallongeException(err.Errors); } }
/// <summary> /// Returns the list of participants for a given tournament. /// </summary> /// <param name="tournamentId">The ID of the tournament.</param> /// <returns></returns> public async Task <List <ChallongeParticipant> > GetParticipants(ulong tournamentId) { var res = await httpGet($"tournaments/{tournamentId}/participants.json"); // convert received format into the proper format List <ChallongeParticipant> returns = new List <ChallongeParticipant>(); try { List <Dictionary <string, ChallongeParticipant> > des = JsonConvert.DeserializeObject <List <Dictionary <string, ChallongeParticipant> > >(res); foreach (var dict in des) { returns.Add(dict["participant"]); } return(returns); } catch (JsonException) { ChallongeError err = JsonConvert.DeserializeObject <ChallongeError>(res); throw new ChallongeException(err.Errors); } }
/// <summary> /// Gets the list of tournaments of the current user. /// </summary> /// <returns>The list of tournaments.</returns> public async Task <List <ChallongeTournament> > GetTournaments() { var res = await httpGet("tournaments.json"); // Console.WriteLine(res); List <ChallongeTournament> returns = new List <ChallongeTournament>(); try { List <Dictionary <string, ChallongeTournament> > des = JsonConvert.DeserializeObject <List <Dictionary <string, ChallongeTournament> > >(res); foreach (var dict in des) { returns.Add(dict["tournament"]); } return(returns); } catch (JsonException) { ChallongeError err = JsonConvert.DeserializeObject <ChallongeError>(res); throw new ChallongeException(err.Errors); } }