コード例 #1
0
        public async Task <SummonerWithRankedInfoDTO> GetSummonerByNameAsync(string region, string summonerName)
        {
            Enum.TryParse(region, out RiotRegionEnum regionEnum);
            var urlToSummonerDTO = RiotApiUrlHelper.GetUrl(regionEnum, "summoner/v4/summoners/by-name", summonerName);
            var riotSummonerDTO  = await _httpClient.GetFromJsonAsync <RiotSummonerDTO>(urlToSummonerDTO);

            var summonerInfoDTO = _mapper.Map <SummonerInfoDTO>(riotSummonerDTO);

            var urlToLeagueEntryDTO = RiotApiUrlHelper.GetUrl(regionEnum, "league/v4/entries/by-summoner", riotSummonerDTO.Id);
            var rankedInfoDTO       = _mapper.Map <List <RankedInfoDTO> >(await _httpClient.GetFromJsonAsync <List <RiotLeagueEntryDTO> >(urlToLeagueEntryDTO));

            var summonerWithRankedInfoDTO = _mapper.MergeInto <SummonerWithRankedInfoDTO>(summonerInfoDTO, rankedInfoDTO);

            return(summonerWithRankedInfoDTO);
        }
コード例 #2
0
        public async Task <List <MatchInfoDTO> > GetMatchesForSummoner(string region, string accountId, int beginIndex, int endIndex)
        {
            Enum.TryParse(region, out RiotRegionEnum regionEnum);
            var url = RiotApiUrlHelper.GetUrl(regionEnum, "match/v4/matchlists/by-account", accountId,
                                              new KeyValuePair <string, string>(nameof(beginIndex), beginIndex.ToString()), new KeyValuePair <string, string>(nameof(endIndex), endIndex.ToString()));

            var riotMatchlist = await _httpClient.GetFromJsonAsync <RiotMatchlistDTO>(url);

            List <RiotMatchDTO> matches = new List <RiotMatchDTO>();
            var riotMatchTasks          = new List <Task <RiotMatchDTO> >();

            foreach (var item in riotMatchlist.Matches)
            {
                riotMatchTasks.Add(_httpClient.GetFromJsonAsync <RiotMatchDTO>(
                                       RiotApiUrlHelper.GetUrl(regionEnum, "match/v4/matches", $"{item.GameId}")));
            }
            await Task.WhenAll(riotMatchTasks);

            matches.AddRange(riotMatchTasks.Select(async t => await t).Select(t => t.Result));

            var matchInfoDtos = _mapper.Map <List <RiotMatchDTO>, List <MatchInfoDTO> >(matches, opts => opts.Items["AccountId"] = accountId);

            return(matchInfoDtos);
        }