예제 #1
0
        public static async Task <LeagueEntityResponse> FetchSummonerRank(string summonerId)
        {
            string path = $"league/v4/entries/by-summoner/{summonerId}?api_key={ApiHelper.API_KEY}";

            try
            {
                using (HttpResponseMessage response = await ApiHelper.RiotApiClient.GetAsync(path))
                {
                    if (response.IsSuccessStatusCode)
                    {
                        LeagueEntityResponse[] leaguesResponse = await response.Content.ReadAsAsync <LeagueEntityResponse[]>();

                        var le = from LeagueEntityResponse entity
                                 in leaguesResponse
                                 where entity.QueueType == "RANKED_SOLO_5x5"
                                 select entity;

                        SessionController.getInstance().leagueEntityResponse = le.FirstOrDefault();

                        return(le.FirstOrDefault());
                    }
                    else
                    {
                        Console.WriteLine("error getting summoner leauge");
                        return(null);
                    }
                }
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
        public static async Task FetchAndSaveChampions()
        {
            string version = SessionController.getInstance().metaData.localVersion;
            string path    = $"cdn/{version}/data/en_US/champion.json";

            try
            {
                using (HttpResponseMessage response = await ApiHelper.DDApiClient.GetAsync(path))
                {
                    if (response.IsSuccessStatusCode)
                    {
                        var championResponse = await response.Content.ReadAsAsync <ChampionsResponse>();

                        List <Champion> champions = new List <Champion>();
                        foreach (Champion c in championResponse.Data.Values)
                        {
                            champions.Add(c);
                        }
                        RealmController.createOrUpdateChampions(champions);
                    }
                    else
                    {
                        Console.WriteLine("Error?");
                        //throw new Exception(response.ReasonPhrase);
                    }
                }
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
예제 #3
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 static async Task CheckForUpdates()
        {
            string path = "api/versions.json";

            try
            {
                using (HttpResponseMessage response = await ApiHelper.DDApiClient.GetAsync(path))
                {
                    var localVersion = RealmController.getMetaData().localVersion;
                    if (response.IsSuccessStatusCode)
                    {
                        //var formatters = new MediaTypeFormatter[] { new JsonMediaTypeFormatter() };
                        //string[] versions = await response.Content.ReadAsAsync<string[]>(formatters);

                        var asString = await response.Content.ReadAsStringAsync();

                        string[] versions = JsonConvert.DeserializeObject <string[]>(asString);

                        var newestVersion = versions[0];

                        if (versionShouldUpdate(localVersion, newestVersion))
                        {
                            // save newest verison local and update
                            Console.WriteLine("save newest verison local and update");
                            MetaData md = new MetaData(newestVersion.ToString());
                            SessionController.getInstance().metaData = md;
                            RealmController.createOrUpdateMetaData(md); // TODO: remember to use this
                            // update champions
                            await FetchAndSaveChampions();
                        }
                        else
                        {
                            SessionController.getInstance().metaData = RealmController.getMetaData();

                            if (RealmController.getChampions() == null)
                            {
                                await FetchAndSaveChampions();
                            }
                            // everything up to date
                            Console.WriteLine("everything up to date");
                        }
                    }
                    else
                    {
                        Console.WriteLine("error getting version");
                        //throw new Exception(response.ReasonPhrase);
                    }
                }
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }