Exemplo n.º 1
0
        public List <LeagueEntry> GetLeagueEntriesOfSummoner(string summonerId, string region)
        {
            var pathBuilder   = new UrlPathBuilder();
            var leagueEntries = new List <LeagueEntry>();

            using (var client = new HttpClient())
            {
                try
                {
                    client.DefaultRequestHeaders.Add("X-Riot-Token", ConfigWrapper.ApiKey);
                    var response = client.GetAsync(new Uri(pathBuilder.GetLeagueEntriesBySummonerIdUrl(summonerId, region)));
                    response.Wait();

                    var result = response.Result;
                    if (result.IsSuccessStatusCode)
                    {
                        var readData = result.Content.ReadAsStringAsync();
                        readData.Wait();

                        leagueEntries = JsonConvert.DeserializeObject <List <LeagueEntry> >(readData.Result);
                    }
                }
                catch (Exception) {}
            }

            SummonerInfoUtils.SetLeagueEntriesWinRates(leagueEntries);
            return(leagueEntries);
        }
Exemplo n.º 2
0
        public MatchBreakdown GetMatch(long gameId, string region, string accountId)
        {
            var pathBuilder = new UrlPathBuilder();

            using (var client = new HttpClient())
            {
                try
                {
                    client.DefaultRequestHeaders.Add("X-Riot-Token", ConfigWrapper.ApiKey);
                    var response = client.GetAsync(new Uri(pathBuilder.GetMatchByGameIdUrl(gameId, region)));
                    response.Wait();

                    if (response.Result.IsSuccessStatusCode)
                    {
                        var readData = response.Result.Content.ReadAsStringAsync();
                        readData.Wait();

                        var match     = JsonConvert.DeserializeObject <Match>(readData.Result);
                        var breakdown = SummonerInfoUtils.GetMatchBreakdown(match, region, accountId);

                        return(breakdown);
                    }
                }
                catch (Exception) { return(new MatchBreakdown()); }
            }
            return(new MatchBreakdown());
        }
Exemplo n.º 3
0
        private MatchHistory GetMatchHistoryOfSummoner(string accountId, string region, int?startIndex = null, int?endIndex = null)
        {
            var pathBuilder  = new UrlPathBuilder();
            var matchHistory = new MatchHistory();
            var matchList    = new MatchList();

            if (startIndex.HasValue && endIndex.HasValue)
            {
                matchList = GetMatchListOfSummoner(accountId, region, startIndex.Value, endIndex.Value);
            }
            else
            {
                matchList = GetMatchListOfSummoner(accountId, region);
            }

            using (var client = new HttpClient())
            {
                try
                {
                    client.DefaultRequestHeaders.Add("X-Riot-Token", ConfigWrapper.ApiKey);
                    foreach (var matchRef in matchList.Matches)
                    {
                        var response = client.GetAsync(new Uri(pathBuilder.GetMatchByGameIdUrl(matchRef.GameId, region)));
                        response.Wait();

                        var result = response.Result;
                        if (result.IsSuccessStatusCode)
                        {
                            var readData = result.Content.ReadAsStringAsync();
                            readData.Wait();

                            var match = JsonConvert.DeserializeObject <Match>(readData.Result);
                            foreach (var participant in match.Participants)
                            {
                                SummonerInfoUtils.SetParticipantCustomFields(participant, match, readData.Result);
                            }

                            SummonerInfoUtils.SetMatchCustomFields(match, accountId, matchRef);
                            matchHistory.Matches.Add(match);
                        }
                    }
                }
                catch (Exception) {}
            }
            return(matchHistory);
        }
Exemplo n.º 4
0
        public SummonerInfo GetSummoner(string name, string region)
        {
            var pathBuilder  = new UrlPathBuilder();
            var summonerInfo = new SummonerInfo();

            summonerInfo.Summoner = GetSummonerByName(name, region);
            if (summonerInfo.Summoner.AccountId == null)
            {
                return(null);
            }

            summonerInfo.MatchHistory   = GetMatchHistoryOfSummoner(summonerInfo.Summoner.AccountId, region);
            summonerInfo.LeagueEntries  = GetLeagueEntriesOfSummoner(summonerInfo.Summoner.Id, region);
            summonerInfo.ProfileIconUrl = pathBuilder.GetProfileIconUrl(summonerInfo.Summoner.ProfileIconId);
            summonerInfo.LastPlayed     = SummonerInfoUtils.GetLastTimePlayedStr(summonerInfo.MatchHistory);
            summonerInfo.Region         = region;

            return(summonerInfo);
        }