Example #1
0
        public static async Task <SummonerData> SearchSummoner(string summonerName)
        {
            string path = $"summoner/v4/summoners/by-name/{summonerName}?api_key={ApiHelper.API_KEY}";

            try
            {
                using (HttpResponseMessage response = await ApiHelper.RiotApiClient.GetAsync(path))
                {
                    if (response.IsSuccessStatusCode)
                    {
                        SummonerResponse summonerResponse = await response.Content.ReadAsAsync <SummonerResponse>();

                        SummonerData sd = new SummonerData(summonerResponse.Id,
                                                           summonerResponse.AccountId,
                                                           summonerResponse.Name,
                                                           summonerResponse.SummonerLevel,
                                                           summonerResponse.ProfileIconId);
                        SessionController.getInstance().summonerData = sd;
                        //RealmController.createOrUpdateSummonerData(sd); // TODO use this to save fetched summoner
                        return(sd);
                    }
                    else
                    {
                        Console.WriteLine("error getting summoner");
                        Console.WriteLine(response);
                        return(null);
                    }
                }
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
        public async Task <float> getAverageScore(string userId)
        {
            _repository = new AmIGoodRepository(_clientFactory);
            SummonerResponse summonerData = await _repository.getSummonerResponse(userId);

            MatchResponse matchResponse = await _repository.getMatchesResponse(summonerData.accountId);

            List <MatchDetail> listMatchDetail = new List <MatchDetail>();

            if (matchResponse.matches == null)
            {
                return(0f);
            }
            foreach (MatchResume resume in matchResponse.matches)
            {
                try
                {
                    MatchDetail match = await _repository.getMatchInformation(resume.gameId);

                    listMatchDetail.Add(match);
                } catch (Exception e)
                {
                    Console.WriteLine(e);
                }

                Thread.Sleep(100);
            }

            return(getScoreFromList(summonerData.accountId, listMatchDetail));
        }