public async Task <League> RetrieveChallengerLeague(CreepScore.Region region, GameConstants.Queue queue) { Url url = UrlConstants.UrlBuilder(region, UrlConstants.leagueAPIVersion, UrlConstants.leaguePart).AppendPathSegment("challenger"); url.SetQueryParams(new { type = GameConstants.GetQueue(queue), api_key = apiKey }); Uri uri = new Uri(url.ToString()); await GetPermission(region); string responseString; try { responseString = await GetWebData(uri); } catch (CreepScoreException) { throw; } return(LoadLeague(JObject.Parse(responseString))); }
public async Task <ChampionListStatic> RetrieveChampionsData(CreepScore.Region region, StaticDataConstants.ChampData champData, string locale = "", string version = "", bool dataById = false) { Url url = UrlConstants.StaticDataUrlBuilder(region, UrlConstants.championPart); url.SetQueryParams(new { locale = locale, version = version, dataById = dataById.ToString(), champData = StaticDataConstants.GetChampData(champData), api_key = apiKey }); Uri uri = new Uri(url.ToString()); string responseString; try { responseString = await GetWebData(uri); } catch (CreepScoreException) { throw; } return(LoadChampionListStatic(JObject.Parse(responseString))); }
public async Task <RuneListStatic> RetrieveRunesData(CreepScore.Region region, StaticDataConstants.RuneListData runeListData, string locale = "", string version = "") { Url url = UrlConstants.StaticDataUrlBuilder(region, UrlConstants.runePart); url.SetQueryParams(new { locale = locale, version = version, runeListData = StaticDataConstants.GetRuneListData(runeListData), api_key = apiKey }); Uri uri = new Uri(url.ToString()); string responseString; try { responseString = await GetWebData(uri); } catch (CreepScoreException) { throw; } return(HelperMethods.LoadRuneListStatic(JObject.Parse(responseString))); }
public static Url UrlBuilder(CreepScore.Region region, string version, string endpoint) { Url url = new Url(GetBaseUrl(region)).AppendPathSegment(apiLolPart).AppendPathSegment(GetRegion(region)).AppendPathSegment(version) .AppendPathSegment(endpoint); return(url); }
public async Task <List <Champion> > RetrieveChampions(CreepScore.Region region, bool freeToPlay = false) { Url url = UrlConstants.UrlBuilder(region, UrlConstants.championAPIVersion, UrlConstants.championPart); url.SetQueryParams(new { freeToPlay = freeToPlay.ToString(), api_key = apiKey }); Uri uri = new Uri(url.ToString()); await GetPermission(region); string responseString; try { responseString = await GetWebData(uri); } catch (CreepScoreException) { throw; } return(LoadChampions(JObject.Parse(responseString))); }
public async Task <SummonerSpellStatic> RetrieveSummonerSpellData(CreepScore.Region region, int id, StaticDataConstants.SpellData spellData, string locale = "", string version = "") { Url url = UrlConstants.StaticDataUrlBuilder(region, UrlConstants.summonerSpellPart).AppendPathSegment(id.ToString()); url.SetQueryParams(new { locale = locale, version = version, spellData = StaticDataConstants.GetSpellData(spellData), api_key = apiKey }); Uri uri = new Uri(url.ToString()); string responseString; try { responseString = await GetWebData(uri); } catch (CreepScoreException) { throw; } return(HelperMethods.LoadSummonerSpellStatic(JObject.Parse(responseString))); }
/// <summary> /// Reads data from a file and returns it. If the file doesn't exist it creates the file and retrieves the data. Doesn't contain data by ID field /// </summary> /// <typeparam name="T1">The object type to return</typeparam> /// <typeparam name="T2">The data section enum</typeparam> /// <param name="region">The region to load information from</param> /// <param name="data">The object we should store the loaded data in</param> /// <param name="staticDataType">The data section we should load</param> /// <param name="localFolder">The folder the file resides in</param> /// <param name="fileName">The filename</param> /// <param name="loadFunction"></param> /// <param name="retrieveFunction"></param> /// <param name="locale">The locale we should use</param> /// <param name="version">The patch number we should load data from</param> /// <returns>Returns the object (T1) with loaded data</returns> async Task <T1> ReadAndLoadData <T1, T2>(CreepScore.Region region, T1 data, T2 staticDataType, StorageFolder localFolder, string fileName, Func <JObject, T1> loadFunction, Func <CreepScore.Region, T2, string, string, Task <T1> > retrieveFunction, string locale = "", string version = "") { StorageFile file; #if WINDOWS_APP file = await localFolder.TryGetItemAsync(fileName) as StorageFile; #endif #if WINDOWS_PHONE_APP file = await AppConstants.TryGetItemAsync(localFolder, fileName); #endif // look for the specified file if (file != null) { // if the file is there read it and load the data from it string fileString = await FileIO.ReadTextAsync(file); JObject fileObject = JObject.Parse(fileString); data = loadFunction(fileObject); return(data); } else { data = await CreateData <T1, T2>(region, data, staticDataType, localFolder, file, fileName, retrieveFunction); return(data); } }
/// <summary> /// Overwrites a file with newly retrieved data. Doesn't contain data by ID field /// </summary> /// <typeparam name="T1">The object type to return</typeparam> /// <typeparam name="T2">The data section enum</typeparam> /// <param name="region">The region to load information from</param> /// <param name="data">The object we should store the loaded data in</param> /// <param name="staticDataType">The data section we should load</param> /// <param name="localFolder">The folder the file resides in</param> /// <param name="fileName">The filename</param> /// <param name="loadFunction"></param> /// <param name="retrieveFunction"></param> /// <param name="locale">The locale we should use</param> /// <param name="version">The patch number we should load data from</param> /// <returns>Returns the object (T1) with loaded data</returns> async Task <T1> ReadAndOverwriteData <T1, T2>(CreepScore.Region region, T1 data, T2 staticDataType, StorageFolder localFolder, string fileName, Func <CreepScore.Region, T2, string, string, Task <T1> > retrieveFunction, string locale = "", string version = "") { StorageFile file; #if WINDOWS_APP file = await localFolder.TryGetItemAsync(fileName) as StorageFile; #endif #if WINDOWS_PHONE_APP file = await AppConstants.TryGetItemAsync(localFolder, fileName); #endif // look for the specified file if (file != null) { data = await OverwriteData <T1, T2>(region, data, staticDataType, localFolder, file, fileName, retrieveFunction); return(data); } else { data = await CreateData <T1, T2>(region, data, staticDataType, localFolder, file, fileName, retrieveFunction); return(data); } }
public async Task <MatchDetailAdvanced> RetrieveMatch(CreepScore.Region region, long matchId, bool includeTimeline = false) { Url url = UrlConstants.UrlBuilder(region, UrlConstants.matchAPIVersion, UrlConstants.matchPart) .AppendPathSegment(matchId.ToString()); url.SetQueryParams(new { includeTimeline = includeTimeline.ToString(), api_key = apiKey }); Uri uri = new Uri(url.ToString()); await GetPermission(region); string responseString; try { responseString = await GetWebData(uri); } catch (CreepScoreException) { throw; } return(HelperMethods.LoadMatchDetailAdvanced(JObject.Parse(responseString))); }
public async Task <List <Summoner> > RetrieveSummoners(CreepScore.Region region, List <long> summonerIds) { string ids = ""; if (summonerIds.Count > 40) { throw new CreepScoreException("Cannot retrieve more than 40 summoners at once."); } for (int i = 0; i < summonerIds.Count; i++) { if (i != summonerIds.Count - 1) { ids += summonerIds[i].ToString() + ","; } else { ids += summonerIds[i].ToString(); } } Uri uri; if (ids != "") { Url url = UrlConstants.UrlBuilder(region, UrlConstants.summonerAPIVersion, UrlConstants.summonerPart) .AppendPathSegment(ids); url.SetQueryParams(new { api_key = apiKey }); uri = new Uri(url.ToString()); } else { throw new CreepScoreException("Cannot have an empty list of summoner IDs."); } await GetPermission(region); string responseString; try { responseString = await GetWebData(uri); } catch (CreepScoreException) { throw; } List <Summoner> summoners = new List <Summoner>(); Dictionary <string, JObject> values = JsonConvert.DeserializeObject <Dictionary <string, JObject> >(responseString); foreach (KeyValuePair <string, JObject> value in values) { summoners.Add(new Summoner(value.Value, region)); } return(summoners); }
private async void summonerSearchBox_KeyDown(object sender, KeyRoutedEventArgs e) { if (e.Key == Windows.System.VirtualKey.Enter) { if (summonerSearchBox.Text == "") { return; } summonerSearchBox.IsEnabled = false; searchingForSummonerRing.IsActive = true; //heroName.Focus(FocusState.Programmatic); string summonerName = summonerSearchBox.Text; CreepScore.Region region = (CreepScore.Region)AppConstants.GetCreepScoreRegion(regionComboBox.SelectedIndex); Summoner summoner = await AppConstants.creepScore.RetrieveSummoner(region, summonerName); if (summoner == null) { searchingForSummonerRing.IsActive = false; if (AppConstants.creepScore.ErrorString == "404") { errorTextBlock.Text = "Cannot find summoner"; errorTextBlock.Visibility = Windows.UI.Xaml.Visibility.Visible; } else if (AppConstants.creepScore.ErrorString == "401") { errorTextBlock.Text = "Unauthorized"; errorTextBlock.Visibility = Windows.UI.Xaml.Visibility.Visible; } else if (AppConstants.creepScore.ErrorString == "429") { errorTextBlock.Text = "Rate limit exceeded"; errorTextBlock.Visibility = Windows.UI.Xaml.Visibility.Visible; } else if (AppConstants.creepScore.ErrorString == "500") { errorTextBlock.Text = "Internal Riot server error"; errorTextBlock.Visibility = Windows.UI.Xaml.Visibility.Visible; } else if (AppConstants.creepScore.ErrorString == "503") { errorTextBlock.Text = "Riot service unavalible"; errorTextBlock.Visibility = Windows.UI.Xaml.Visibility.Visible; } summonerSearchBox.IsEnabled = true; } else { searchingForSummonerRing.IsActive = false; List <object> parameters = new List <object>(); parameters.Add(summoner); Frame.Navigate(typeof(SummonerPage), parameters); } } }
/// <summary> /// Full summoner constructor /// </summary> /// <param name="summonerO">JObject representing summoner</param> public Summoner(JObject summonerO, CreepScore.Region region) { id = (long)summonerO["id"]; name = (string)summonerO["name"]; profileIconId = (int)summonerO["profileIconId"]; revisionDateLong = (long)summonerO["revisionDate"]; SetRevisionDate(revisionDateLong); summonerLevel = (long)summonerO["summonerLevel"]; this.region = region; }
/// <summary> /// Full summoner constructor /// </summary> /// <param name="summonerO">JObject representing summoner</param> public Summoner(JObject summonerO, CreepScore.Region region) { id = (long)summonerO["id"]; name = (string)summonerO["name"]; profileIconId = (int)summonerO["profileIconId"]; revisionDateLong = (long)summonerO["revisionDate"]; SetRevisionDate(revisionDateLong); summonerLevel = (long)summonerO["summonerLevel"]; isLittleSummoner = false; this.region = region; }
public async Task <Dictionary <string, Team> > RetrieveTeam(CreepScore.Region region, List <string> teamIds) { string ids = ""; if (teamIds.Count > 10) { throw new CreepScoreException("Cannot retrieve more than 10 teams at once."); } for (int i = 0; i < teamIds.Count; i++) { if (i != teamIds.Count - 1) { ids += teamIds[i] + ","; } else { ids += teamIds[i]; } } Uri uri; if (ids != "") { Url url = UrlConstants.UrlBuilder(region, UrlConstants.teamAPIVersion, UrlConstants.teamPart) .AppendPathSegment(ids); url.SetQueryParams(new { api_key = apiKey }); uri = new Uri(url.ToString()); } else { throw new CreepScoreException("Cannot have an empty list of team IDs."); } await GetPermission(region); string responseString; try { responseString = await GetWebData(uri); } catch (CreepScoreException) { throw; } return(HelperMethods.LoadTeam(responseString)); }
async Task <T1> CreateData <T1, T2>(CreepScore.Region region, T1 data, T2 staticDataType, StorageFolder localFolder, StorageFile file, string fileName, Func <CreepScore.Region, T2, string, string, Task <T1> > retrieveFunction, string locale = "", string version = "") { // create file file = await CreateFile(fileName, localFolder, file); data = await OverwriteData <T1, T2>(region, data, staticDataType, localFolder, file, fileName, retrieveFunction); return(data); }
public static string GetPlatformId(CreepScore.Region region) { if (region == CreepScore.Region.NA) { return("NA1"); } else if (region == CreepScore.Region.EUW) { return("EUW1"); } else if (region == CreepScore.Region.EUNE) { return("EUN1"); } else if (region == CreepScore.Region.BR) { return("BR1"); } else if (region == CreepScore.Region.LAN) { return("LA1"); } else if (region == CreepScore.Region.LAS) { return("LA2"); } else if (region == CreepScore.Region.OCE) { return("OC1"); } else if (region == CreepScore.Region.KR) { return("KR"); } else if (region == CreepScore.Region.TR) { return("TR1"); } else if (region == CreepScore.Region.RU) { return("RU"); } else { return("NONE"); } }
/// <summary> /// Gets the region /// </summary> /// <param name="region">Region</param> /// <returns>Returns a string representing a region</returns> public static string GetRegion(CreepScore.Region region) { if (region == CreepScore.Region.NA) { return("na"); } else if (region == CreepScore.Region.EUW) { return("euw"); } else if (region == CreepScore.Region.EUNE) { return("eune"); } else if (region == CreepScore.Region.BR) { return("br"); } else if (region == CreepScore.Region.LAN) { return("lan"); } else if (region == CreepScore.Region.LAS) { return("las"); } else if (region == CreepScore.Region.OCE) { return("oce"); } else if (region == CreepScore.Region.KR) { return("kr"); } else if (region == CreepScore.Region.TR) { return("tr"); } else if (region == CreepScore.Region.RU) { return("ru"); } else { return("none"); } }
/// <summary> /// Base url /// </summary> /// <param name="region">Region data is coming from</param> /// <returns>Base url string</returns> public static string GetBaseUrl(CreepScore.Region region) { if (region == CreepScore.Region.NA) { return("https://na.api.pvp.net"); } else if (region == CreepScore.Region.EUW) { return("https://euw.api.pvp.net"); } else if (region == CreepScore.Region.EUNE) { return("https://eune.api.pvp.net"); } else if (region == CreepScore.Region.BR) { return("https://br.api.pvp.net"); } else if (region == CreepScore.Region.LAN) { return("https://lan.api.pvp.net"); } else if (region == CreepScore.Region.LAS) { return("https://las.api.pvp.net"); } else if (region == CreepScore.Region.OCE) { return("https://oce.api.pvp.net"); } else if (region == CreepScore.Region.KR) { return("https://kr.api.pvp.net"); } else if (region == CreepScore.Region.TR) { return("https://tr.api.pvp.net"); } else if (region == CreepScore.Region.RU) { return("https://ru.api.pvp.net"); } else { return("https://global.api.pvp.net"); } }
public async Task <Summoner> RetrieveSummoner(CreepScore.Region region, string summonerName) { List <string> temp = new List <string>(); temp.Add(summonerName); List <Summoner> returnedList; try { returnedList = await RetrieveSummoners(region, temp); } catch (CreepScoreException) { throw; } return(returnedList[0]); }
async Task <T1> OverwriteData <T1, T2>(CreepScore.Region region, T1 data, T2 staticDataType, StorageFolder localFolder, StorageFile file, string fileName, Func <CreepScore.Region, T2, string, string, Task <T1> > retrieveFunction, string locale = "", string version = "") { // load data from API Task task = Task.Run(async() => { data = await retrieveFunction(region, staticDataType, locale, version); }); task.Wait(); // then write it out to file await FileIO.WriteTextAsync(file, data.ToString()); return(data); }
public async Task <Dictionary <long, string> > RetrieveSummonerNames(CreepScore.Region region, List <long> summonerIds) { string summonerIdsPart = ""; if (summonerIds.Count > 40) { throw new CreepScoreException("Cannot retrieve more than 40 summoners at once."); } for (int i = 0; i < summonerIds.Count; i++) { if (i != summonerIds.Count - 1) { summonerIdsPart += summonerIds[i].ToString() + ","; } else { summonerIdsPart += summonerIds[i].ToString(); } } Url url = UrlConstants.UrlBuilder(region, UrlConstants.summonerAPIVersion, UrlConstants.summonerPart) .AppendPathSegments(summonerIdsPart, UrlConstants.namePart); url.SetQueryParams(new { api_key = apiKey }); Uri uri = new Uri(url.ToString()); await GetPermission(region); string responseString; try { responseString = await GetWebData(uri); } catch (CreepScoreException) { throw; } return(JsonConvert.DeserializeObject <Dictionary <long, string> >(responseString)); }
public async Task <RealmStatic> RetrieveRealmData(CreepScore.Region region) { Url url = UrlConstants.StaticDataUrlBuilder(region, UrlConstants.realmPart); url.SetQueryParams(new { api_key = apiKey }); Uri uri = new Uri(url.ToString()); string responseString; try { responseString = await GetWebData(uri); } catch (CreepScoreException) { throw; } return(LoadRealmData(JObject.Parse(responseString))); }
public async Task <List <string> > RetrieveVersions(CreepScore.Region region) { Url url = UrlConstants.StaticDataUrlBuilder(region, UrlConstants.versionsPart); url.SetQueryParams(new { api_key = apiKey }); Uri uri = new Uri(url.ToString()); string responseString; try { responseString = await GetWebData(uri); } catch (CreepScoreException) { throw; } return(HelperMethods.LoadStrings(JArray.Parse(responseString))); }
public async Task <LanguageStringsStatic> RetrieveLanguageStrings(CreepScore.Region region, string locale = "", string version = "") { Url url = UrlConstants.StaticDataUrlBuilder(region, UrlConstants.languageStringsPart); url.SetQueryParams(new { locale = locale, version = version, api_key = apiKey }); Uri uri = new Uri(url.ToString()); string responseString; try { responseString = await GetWebData(uri); } catch (CreepScoreException) { throw; } return(HelperMethods.LoadLanguageStringsStatic(JObject.Parse(responseString))); }
public async Task <Champion> RetrieveChampion(CreepScore.Region region, int id) { Url url = UrlConstants.UrlBuilder(region, UrlConstants.championAPIVersion, UrlConstants.championPart).AppendPathSegment(id.ToString()); url.SetQueryParams(new { api_key = apiKey }); Uri uri = new Uri(url.ToString()); await GetPermission(region); string responseString; try { responseString = await GetWebData(uri); } catch (CreepScoreException) { throw; } return(LoadChampion(JObject.Parse(responseString))); }
public async Task <FeaturedGamesLive> RetrieveFeaturedGames(CreepScore.Region region) { Url url = new Url(UrlConstants.GetBaseUrl(region)).AppendPathSegments(UrlConstants.observerModeRestpart, "/featured"); url.SetQueryParams(new { api_key = apiKey }); Uri uri = new Uri(url.ToString()); await CreepScore.GetPermission(region); string responseString; try { responseString = await GetWebData(uri); } catch (CreepScoreException) { throw; } return(LoadFeaturedGames(JObject.Parse(responseString))); }
/// <summary> /// Little summmoner constructor /// </summary> /// <param name="id">Summoner ID</param> /// <param name="name">Summoner Name</param> public Summoner(long id, string name, CreepScore.Region region) { this.id = id; this.name = name; isLittleSummoner = true; this.region = region; }
async void RefreshStatus(CreepScore.Region region) { shardStatus = await AppConstants.creepScore.RetrieveShardStatus(region); LoadStatus(); }
void LoadVersions(CreepScore.Region region) { Task task = Task.Run(async() => { AppConstants.versions = await AppConstants.creepScore.RetrieveVersions(region); }); task.Wait(); }
public async Task <PlayerHistoryAdvanced> RetrieveMatchHistory(CreepScore.Region region, List <int> championIds = null, List <GameConstants.Queue> rankedQueues = null, int?beginIndex = null, int?endIndex = null) { string url = UrlConstants.GetBaseUrl(region) + UrlConstants.apiLolPart + "/" + UrlConstants.GetRegion(region) + UrlConstants.matchHistoryAPIVersion + UrlConstants.matchHistoryPart + "/" + id.ToString() + "?"; if (championIds != null) { if (championIds.Count != 0) { url += "championIds="; for (int i = 0; i < championIds.Count; i++) { if (i + 1 == championIds.Count) { url += championIds[i].ToString() + "&"; } else { url += championIds[i].ToString() + ","; } } } } if (rankedQueues != null) { if (rankedQueues.Count != 0) { string tmpRankedQueues = ""; for (int i = 0; i < rankedQueues.Count; i++) { if (rankedQueues[i] == GameConstants.Queue.None) { continue; } else { if (i + 1 == rankedQueues.Count) { tmpRankedQueues += GameConstants.GetQueue(rankedQueues[i]); } else { tmpRankedQueues += GameConstants.GetQueue(rankedQueues[i]) + ","; } } } if (tmpRankedQueues != "") { url += "rankedQueues=" + tmpRankedQueues + "&"; } } } if (beginIndex != null) { url += "beginIndex=" + beginIndex.Value.ToString() + "&"; } if (endIndex != null) { url += "endIndex=" + endIndex.Value.ToString() + "&"; } url += "api_key=" + CreepScore.apiKey; Uri uri = new Uri(url); await CreepScore.GetPermission(region); string responseString; try { responseString = await CreepScore.GetWebData(uri); } catch (CreepScoreException) { throw; } return(HelperMethods.LoadPlayerHistoryAdvanced(JObject.Parse(responseString))); }