private static void FillClubsFields(MatchListDto dto, Club homeClub, Club awayClub) { dto.HomeClubId = homeClub.Id; dto.HomeClubName = homeClub.Name; dto.HomeClubLogo = homeClub.Logo; dto.AwayClubId = awayClub.Id; dto.AwayClubName = awayClub.Name; dto.AwayClubLogo = awayClub.Logo; }
public async Task <ActionResult> MatchList() { MatchListDto matchList = await _matchService.GetRecentMatchListAsync(RegionDto.euw, "Bommerhond"); MatchDto matchDto = await _matchService.GetMatchAsync(RegionDto.euw, matchList.Matches.First().GameId); await _matchService.Test(); return(View("Index")); }
/// <summary> /// GETs a MatchList object from Riot's API and then deserializes it into a MatchListModel object. /// </summary> /// <param name="endIndex">Optional parameter determining how many games back to end the request. /// Default is 5. Cannot be less than beginIndex parameter. /// Difference between endIndex and beginIndex cannot be greater than 100.</param> /// <param name="beginIndex">Optional parameter determining how many games back to begin the request. /// Default is 0 (most recent game). Cannot be higher than endIndex parameter. /// Difference between beginIndex and endIndex cannot be greater than 100.</param> /// <param name="queueId">Optional parameter that filters games to a specific queue type.</param> /// <returns>Returns a Task for a MatchListModel object.</returns> public async Task <MatchListModel> GetMatchListModelAsync (int endIndex = 5, int beginIndex = 0, int?queueId = null) { var parameters = GetQueryParameters(endIndex, beginIndex, queueId); var uri = GetUriFromAccountIdAndParameters(parameters); var json = await _httpClient.GetStringAsync(uri).ConfigureAwait(false); var contract = JsonConvert.DeserializeObject <MatchListDto>(json); _matchListContract = contract; return(contract.ToMatchListModel());
public async Task <Summoner> GetSummoner(string summonerName) { try { using (CancellationTokenSource cts = new CancellationTokenSource(_timeout)) { if (summonerName.Length > 16) { return(new Summoner(summonerName, SummonerNameAvailability.TooLong)); } // Fetch Summoner SummonerDto summonerDto = null; try { summonerDto = await ApiRequestAsync <SummonerDto>($"summoner/v4/summoners/by-name/{summonerName}?api_key={_apiKey}", cts.Token); } catch (ApiRequestException e) { if (e.StatusCode == HttpStatusCode.NotFound) { // 404 = summoner does not exist return(new Summoner(summonerName, SummonerNameAvailability.AvailableNotFound)); } throw; } if (summonerDto == null) { return(new Summoner(summonerName, SummonerNameAvailability.Unknown)); } // Fetch Summoner's match history MatchListDto matchListDto = null; try { matchListDto = await ApiRequestAsync <MatchListDto>($"match/v4/matchlists/by-account/{summonerDto.AccountId}?api_key={_apiKey}", cts.Token); } catch (ApiRequestException e) { if (e.StatusCode == HttpStatusCode.NotFound) { // 404 = no matches played return(new Summoner(summonerName, SummonerNameAvailability.UnknownNeverPlayed)); } throw; } if (matchListDto == null || !matchListDto.Matches.Any()) { return(new Summoner(summonerName, SummonerNameAvailability.UnknownNeverPlayed)); } return(new Summoner( summonerDto.Name, summonerDto.SummonerLevel, summonerDto.Id, summonerDto.AccountId, DateTimeOffset.FromUnixTimeMilliseconds(matchListDto.Matches.First().Timestamp).UtcDateTime)); } } catch (Exception e) when(e is ApiRequestException || e is OperationCanceledException) { return(new Summoner(summonerName, SummonerNameAvailability.Unknown)); } }