public void WhenTheUserDeletesAllGitHubRepositories() { List <string> repoNames = new List <string>(); var repos = RESTHelpers.GETList( ConfigurationManager.AppSettings["URL"], ConfigurationManager.AppSettings["UsersResource"] + ConfigurationManager.AppSettings["UserName"] + ConfigurationManager.AppSettings["ReposResource"], HeaderBuilder.BuildHeader(), ConfigurationManager.AppSettings["UserName"], ConfigurationManager.AppSettings["Password"]).Result; foreach (var repo in repos) { HttpResponseMessage result = RESTHelpers.DELETERequestAsync( ConfigurationManager.AppSettings["URL"], repo.name, ConfigurationManager.AppSettings["ReposResource"], HeaderBuilder.BuildHeader(), ConfigurationManager.AppSettings["UserName"], ConfigurationManager.AppSettings["Password"]).Result; Console.WriteLine(result.StatusCode.ToString()); result.StatusCode.Should().Be(HttpStatusCode.NoContent); } }
public void WhenTheUserEditsARepositoryInGithub() { var repository = RepositoryBuilder.BuildRepository(); var patchRepository = RepositoryBuilder.BuildPatchRepository(); var jobj = JsonConvert.SerializeObject(repository); var patchJobj = JsonConvert.SerializeObject(patchRepository); //Create a new repository var result = RESTHelpers.POSTRequestAsync <RepositoryResponseDTO>( ConfigurationManager.AppSettings["URL"], ConfigurationManager.AppSettings["RepositoryResource"], HeaderBuilder.BuildHeader(), ConfigurationManager.AppSettings["UserName"], ConfigurationManager.AppSettings["Password"], JObject.Parse(jobj)).Result; //PATCH a repository var patchResult = RESTHelpers.PATCHRequestAsync <RepositoryResponseDTO>( ConfigurationManager.AppSettings["URL"], ConfigurationManager.AppSettings["ReposResource"], repository.Name, HeaderBuilder.BuildHeader(), ConfigurationManager.AppSettings["UserName"], ConfigurationManager.AppSettings["Password"], JObject.Parse(patchJobj)).Result; context.Add("PATCHEDRepo", patchResult); context.Add("ExpectedPATCHREPO", patchRepository); }
public void ThenICaptureTheNewPlaylistID() { var jobj = RESTHelpers.GetJObject(ScenarioContext.Current.Get <string>("PlayListJSONResponse")); ScenarioContext.Current.Set <string>(jobj.GetValue("id").ToString(), "NewPlaylistID"); }
public void WhenIExecuteAnOptionsRequest() { IRestResponse response = RESTHelpers.OPTIONSNoAuth ( ConfigurationManager.AppSettings["SpotifyURL"].ToString(), ConfigurationManager.AppSettings["MeURL"].ToString() ); RESTHelpers.Is200OKResponseNoContent(response); }
public void WhenIExecuteAGETTracksRequest() { IRestResponse response = RESTHelpers.GETWithOAUTH(ConfigurationManager.AppSettings["SpotifyURL"].ToString(), ConfigurationManager.AppSettings["TracksResource"].ToString(), ScenarioContext.Current.Get <string>("AccountToken")); RESTHelpers.Is200OKResponse(response); ScenarioContext.Current.Add("TracksJSON", response.Content); }
public void GivenIGetAnOAuthTokenFromTheAccountsAPI() { IRestResponse response = RESTHelpers.GETOAUTH( ConfigurationManager.AppSettings["AccountsAPIURL"].ToString(), ConfigurationManager.AppSettings["AuthorizeResource"].ToString(), ConfigurationManager.AppSettings["ClientID"].ToString()); //var modifyToken = JsonConvert.DeserializeObject<ModifyToken>(response.Content); //ScenarioContext.Current.Set(modifyToken, "ModifyToken"); }
public void ThenTheTrackNoLongerExistsInThePlaylist() { IRestResponse response = RESTHelpers.GETPlaylist( ConfigurationManager.AppSettings["SpotifyURL"].ToString(), ConfigurationManager.AppSettings["PlayListResource"].ToString(), ConfigurationManager.AppSettings["ModifyToken"] ); RESTHelpers.Is200OKResponse(response); response.Content.Contains(ConfigurationManager.AppSettings["DeleteTrackID"]).Should().BeFalse(); }
public void GivenIGetAValidTokenBackFromTheAccountsAPI() { IRestResponse response = RESTHelpers.POST( ConfigurationManager.AppSettings["AccountsAPIURL"].ToString(), ConfigurationManager.AppSettings["TokenResource"].ToString(), ConfigurationManager.AppSettings["ClientID"].ToString(), ConfigurationManager.AppSettings["ClientSecret"].ToString()); var accessToken = JsonConvert.DeserializeObject <AccessToken>(response.Content); ScenarioContext.Current.Set(accessToken.Access_Token, "AccountToken"); }
public void ThenIAddATrackToTheNewPlaylist() { IRestResponse response = RESTHelpers.POSTAddTracksToPlaylist( ConfigurationManager.AppSettings["SpotifyURL"].ToString(), ConfigurationManager.AppSettings["PlayListResource"].ToString(), ConfigurationManager.AppSettings["ModifyToken"] ); RESTHelpers.Is201CreatedResponse(response); ScenarioContext.Current.Add("POSTPlayListTracksJSONResponse", response.Content); }
public void WhenIPOSTANewPlaylistToTheSpotifyAPI() { IRestResponse response = RESTHelpers.POSTOAUTHHeaderToken( ConfigurationManager.AppSettings["SpotifyURL"].ToString(), ConfigurationManager.AppSettings["PlayListResource"].ToString(), ConfigurationManager.AppSettings["ModifyToken"], "POSTPlayListPublicJSON.json" ); RESTHelpers.Is201CreatedResponse(response); ScenarioContext.Current.Add("PlayListJSONResponse", response.Content); }
public void WhenIRunTheDeleteTrackFromPlaylistRequest() { IRestResponse response = RESTHelpers.DELETETrackFromPlaylist( ConfigurationManager.AppSettings["SpotifyURL"].ToString(), ConfigurationManager.AppSettings["PlayListResource"].ToString(), ConfigurationManager.AppSettings["ModifyToken"], "DELETETrackFromPlaylist.json" ); RESTHelpers.Is200OKResponse(response); ScenarioContext.Current.Add("DELETEPlayListTracksJSONResponse", response.Content); }
public void WhenIExecuteAPUTOnPlaylistDetailsOfAnExistingPlaylist() { IRestResponse response = RESTHelpers.PUTPlaylistWithAuthHeader( ConfigurationManager.AppSettings["SpotifyURL"].ToString(), ConfigurationManager.AppSettings["PlayListResource"].ToString(), ConfigurationManager.AppSettings["ModifyToken"], "PUTPlayListPublicJSON.json" ); RESTHelpers.Is201CreatedResponse(response); ScenarioContext.Current.Add("PUTPlayListJSONResponse", response.Content); }
public void ThenTheGithubRepositoriesAreDeletedFromTheSystem() { var repos = RESTHelpers.GETList( ConfigurationManager.AppSettings["URL"], ConfigurationManager.AppSettings["UsersResource"] + ConfigurationManager.AppSettings["UserName"] + ConfigurationManager.AppSettings["ReposResource"], HeaderBuilder.BuildHeader(), ConfigurationManager.AppSettings["UserName"], ConfigurationManager.AppSettings["Password"]).Result; Assert.IsTrue(repos.Length == 0); }
public void ThenThePlaylistDetailsAreUpdated() { var response = ScenarioContext.Current.Get <string>("PUTPlayListJSONResponse"); var updatedPlaylistResponse = RESTHelpers.GetJObject(response); updatedPlaylistResponse.GetValue("id").ToString().Should().NotBe(ScenarioContext.Current.Get <string>("NewPlaylistID")); updatedPlaylistResponse.GetValue("public").ToString().Should().Be("False"); updatedPlaylistResponse.GetValue("description").ToString().Should().Be("Updated playlist description"); updatedPlaylistResponse.GetValue("name").ToString().Should().Be("Updated Playlist Name"); }
public void WhenTheUserExecutesAGETUserCall() { var userDTO = UserBuilder.BuildUser(); var result = RESTHelpers.GETRequestAsync <UserResponseDTO>( ConfigurationManager.AppSettings["URL"], ConfigurationManager.AppSettings["UserResource"], HeaderBuilder.BuildHeader(), ConfigurationManager.AppSettings["UserName"], ConfigurationManager.AppSettings["Password"]).Result; context.Add("UserDTO", userDTO); context.Add("UserResponseDTO", result); }
public void WhenTheUserCreatesANewGitHubRepository() { var repository = RepositoryBuilder.BuildRepository(); var jobj = JsonConvert.SerializeObject(repository); //Create a new repository var result = RESTHelpers.POSTRequestAsync <RepositoryResponseDTO>( ConfigurationManager.AppSettings["URL"], ConfigurationManager.AppSettings["RepositoryResource"], HeaderBuilder.BuildHeader(), ConfigurationManager.AppSettings["UserName"], ConfigurationManager.AppSettings["Password"], JObject.Parse(jobj)).Result; context.Add("RepositoryDTO", repository); context.Add("RepositoryResponseDTO", result); }
static async Task MatchIdScraperAsync(string[] args) { List <string> regions = new List <string>(); regions.Add("na"); regions.Add("euw"); regions.Add("kr"); regions.Add("tr"); regions.Add("lan"); regions.Add("eune"); regions.Add("oce"); regions.Add("las"); regions.Add("br"); regions.Add("ru"); foreach (string region in regions) { for (long i = StartEpochTime; i < CurrentEpochTime; i += Interval) { string fileName = JSONCacheDirectory + region + @"\" + i.ToString() + ".json"; if (!File.Exists(fileName)) { RESTResult <List <long> > gameListResult = await RESTHelpers.RESTRequest <List <long> >( string.Format("{0}{1}/v4.1/game/ids", BaseUrl.Replace("/na.", "/" + region + "."), region), "", DevKey, "beginDate=" + i.ToString(), 4); if (gameListResult.Success) { JavaScriptSerializer jss = new JavaScriptSerializer(); File.WriteAllText(fileName, jss.Serialize(gameListResult.ReturnObject)); Console.WriteLine(string.Format("Region {0}, File {1}", region, fileName)); } } } } }
public void ThenTheTracksAreReturnedInTheJSON() { RESTHelpers.CompareJSON("TracksJSON", "TracksJSON.json"); }
internal static async Task <BraveChampion> Create(string version, int?seed) { BraveChampion braveChampion = new BraveChampion(); braveChampion.Seed = seed ?? (int)DateTime.Now.Ticks; bool champSuccess = false; bool itemSuccess = false; bool summonerSpellSuccess = false; bool hasSmite = false; bool isMelee = false; bool mapSuccess = false; string versionAppend = ""; //If specific version passed get data for that version if (!version.IsNullOrWhiteSpace()) { versionAppend = "&version=" + version; } Random random = new Random(braveChampion.Seed); #region Pull Map Data RESTResult <MapDataDto> mapData; if (HttpRuntime.Cache.Get("MapData" + version ?? "") == null) { mapData = await RESTHelpers.RESTRequest <MapDataDto>( "https://global.api.pvp.net/api/lol/static-data/na/v1.2/map", "", apiKey, versionAppend); if (mapData.Success) { HttpRuntime.Cache.Add ( "MapData" + version ?? "", mapData, null, DateTime.Now.AddDays(1.0), Cache.NoSlidingExpiration, CacheItemPriority.NotRemovable, null ); mapSuccess = true; } } else { mapData = (RESTResult <MapDataDto>)HttpRuntime.Cache.Get("MapData" + version ?? ""); mapSuccess = true; } #endregion Pull Map Data #region Champion Selection RESTResult <ChampionListDto> champs; if (HttpRuntime.Cache.Get("ChampList" + version ?? "") == null) { champs = await RESTHelpers.RESTRequest <ChampionListDto>( "https://global.api.pvp.net/api/lol/static-data/na/v1.2/champion", "", apiKey, "champData=all" + versionAppend); if (champs.Success) { HttpRuntime.Cache.Add ( "ChampList" + version ?? "", champs, null, DateTime.Now.AddDays(1.0), Cache.NoSlidingExpiration, CacheItemPriority.NotRemovable, null ); } } else { champs = (RESTResult <ChampionListDto>)HttpRuntime.Cache.Get("ChampList" + version ?? ""); } if (champs.Success) { ChampionDto selectedChamp = champs.ReturnObject.Data.Values[random.Next(0, champs.ReturnObject.Data.Values.Count - 1)]; braveChampion.Version = champs.ReturnObject.Version; braveChampion.Key = selectedChamp.Key; braveChampion.Champion = new SelectedValue() { Id = selectedChamp.Id, ImageUrl = string.Format("http://ddragon.leagueoflegends.com/cdn/{0}/img/champion/{1}", braveChampion.Version, selectedChamp.Image.Full), Name = selectedChamp.Name }; //Champions with an attack range less than or equal to 200 are melee. This determines if they can have melee or range only items. if (selectedChamp.Stats.AttackRange <= 200) { isMelee = true; } #region Skill Selection int skillNum = random.Next(0, 3); string skillLetter = ""; switch (skillNum) { case 0: skillLetter = "Q"; break; case 1: skillLetter = "W"; break; case 2: skillLetter = "E"; break; default: break; } ChampionSpellDto selectedSkill = selectedChamp.Spells[skillNum]; braveChampion.Skill = new SelectedSkill() { Id = skillNum, ImageUrl = string.Format("http://ddragon.leagueoflegends.com/cdn/{0}/img/spell/{1}", braveChampion.Version, selectedSkill.Image.Full), Name = selectedSkill.Name, Letter = skillLetter }; #endregion Skill Selection champSuccess = true; } #endregion Champion Selection #region Summoner Spell Selection RESTResult <SummonerSpellListDto> summonerSpells; if (HttpRuntime.Cache.Get("SummonerSpellList" + version ?? "") == null) { summonerSpells = await RESTHelpers.RESTRequest <SummonerSpellListDto>( "https://global.api.pvp.net/api/lol/static-data/na/v1.2/summoner-spell", "", apiKey, "spellData=all" + versionAppend); if (summonerSpells.Success) { HttpRuntime.Cache.Add ( "SummonerSpellList" + version ?? "", summonerSpells, null, DateTime.Now.AddDays(1.0), Cache.NoSlidingExpiration, CacheItemPriority.NotRemovable, null ); } } else { summonerSpells = (RESTResult <SummonerSpellListDto>)HttpRuntime.Cache.Get("SummonerSpellList" + version ?? ""); } if (summonerSpells.Success) { List <SummonerSpellDto> possibleSummonerSpells = summonerSpells.ReturnObject.Data.Values.Where(s => s.Modes.Contains("CLASSIC")).ToList(); SummonerSpellDto selectedSummonerSpell = possibleSummonerSpells[random.Next(0, possibleSummonerSpells.Count - 1)]; if (selectedSummonerSpell.Id == 11) { hasSmite = true; } braveChampion.SummonerSpells = new List <SelectedSummonerSpell>(); braveChampion.SummonerSpells.Add(new SelectedSummonerSpell() { Id = selectedSummonerSpell.Id, ImageUrl = string.Format("http://ddragon.leagueoflegends.com/cdn/{0}/img/spell/{1}", braveChampion.Version, selectedSummonerSpell.Image.Full), Name = selectedSummonerSpell.Name, Key = selectedSummonerSpell.Key }); do { selectedSummonerSpell = possibleSummonerSpells[random.Next(0, possibleSummonerSpells.Count - 1)]; } while (braveChampion.SummonerSpells.Any(s => s.Id == selectedSummonerSpell.Id)); if (selectedSummonerSpell.Id == 11) { hasSmite = true; } braveChampion.SummonerSpells.Add(new SelectedSummonerSpell() { Id = selectedSummonerSpell.Id, ImageUrl = string.Format("http://ddragon.leagueoflegends.com/cdn/{0}/img/spell/{1}", braveChampion.Version, selectedSummonerSpell.Image.Full), Name = selectedSummonerSpell.Name, Key = selectedSummonerSpell.Key }); summonerSpellSuccess = true; } #endregion Summoner Spell Selection #region Item Selection List <SelectedItem> itemList = new List <SelectedItem>(); List <ItemDto> selectableItems; List <ItemDto> selectableNonJungleItems; List <ItemDto> selectableJungleItems; List <ItemDto> bootOptions; List <ItemDto> nonJungleBootOptions; List <ItemDto> jungleBootOptions; List <ItemDto> allItems; List <ItemDto> jungleOnlyItems; RESTResult <ItemListDto> itemResult; Dictionary <string, List <ItemDto> > allItemLists = new Dictionary <string, List <ItemDto> >(); if (mapSuccess) { if (HttpRuntime.Cache.Get("ItemLists" + version ?? "") == null) { itemResult = await RESTHelpers.RESTRequest <ItemListDto>( "https://global.api.pvp.net/api/lol/static-data/na/v1.2/item", "", apiKey, "itemListData=all" + versionAppend); if (itemResult.Success) { //Don't include Bilgewater event items and items that are not allowed on the Rift //There might be a better way to exclude Bilgewater items but I can't find it. Is there a flag? allItems = itemResult.ReturnObject.Data.Values.Where( i => (i.Tags == null || !i.Tags.Contains("Bilgewater")) && !mapData.ReturnObject.Data["11"].UnpurchasableItemList.Any(id => id == i.Id)) .ToList(); selectableJungleItems = allItems.Where( i => i.Depth >= 3 && (i.Group == null || !i.Group.StartsWith("Boots")) && !i.Name.ToLower().Contains("hex core") && i.Into == null && i.Gold.Purchasable) .ToList(); //Get all boots but not in group BootsTeleport as not valid for map. //There might be a better way to exclude Bilgewater items but I can't find it. Is there a flag? jungleBootOptions = allItems.Where( i => i.Depth >= 3 && i.Group != null && i.Group.StartsWith("Boots") && i.Group != "BootsTeleport" && !i.Name.ToLower().Contains("hex core") && i.Into == null && i.Gold.Purchasable) .ToList(); selectableNonJungleItems = allItems.Where( i => i.Depth >= 3 && (i.Group == null || !i.Group.StartsWith("Boots")) && i.Group != "JungleItems" && !i.Name.ToLower().Contains("hex core") && i.Into == null && i.Gold.Purchasable) .ToList(); //Get all boots but not in group BootsTeleport as not valid for map. //There might be a better way to exclude Bilgewater items but I can't find it. Is there a flag? nonJungleBootOptions = allItems.Where( i => i.Depth >= 3 && i.Group != null && i.Group.StartsWith("Boots") && i.Group != "BootsTeleport" && i.Group != "JungleItems" && !i.Name.ToLower().Contains("hex core") && i.Into == null && i.Gold.Purchasable) .ToList(); jungleOnlyItems = allItems.Where(i => i.Group == "JungleItems" && i.Gold.Purchasable).ToList(); allItemLists.Add("All", allItems); allItemLists.Add("SelectableJungleItems", selectableJungleItems); allItemLists.Add("JungleBootOptions", jungleBootOptions); allItemLists.Add("SelectableItems", selectableNonJungleItems); allItemLists.Add("BootOptions", nonJungleBootOptions); allItemLists.Add("JungleOnlyItems", jungleOnlyItems); HttpRuntime.Cache.Add ( "ItemLists" + version ?? "", allItemLists, null, DateTime.Now.AddDays(1.0), Cache.NoSlidingExpiration, CacheItemPriority.NotRemovable, null ); itemSuccess = true; } } else { allItemLists = (Dictionary <string, List <ItemDto> >)HttpRuntime.Cache.Get("ItemLists" + version ?? ""); itemSuccess = true; } if (itemSuccess) { if (hasSmite) { selectableItems = allItemLists["SelectableJungleItems"]; bootOptions = allItemLists["JungleBootOptions"]; } else { selectableItems = allItemLists["SelectableItems"]; bootOptions = allItemLists["BootOptions"]; } jungleOnlyItems = allItemLists["JungleOnlyItems"]; allItems = allItemLists["All"]; ItemDto selectedItemDto; ItemDto relatedBoot; //Non-viktor builds get boots if (braveChampion.Champion.Id != 112) { selectedItemDto = bootOptions[random.Next(0, bootOptions.Count - 1)]; relatedBoot = allItems.FirstOrDefault(b => b.Id.ToString() == selectedItemDto.From[0]); itemList.Add(new SelectedItem() { Cost = selectedItemDto.Gold.Total, Id = selectedItemDto.Id, ImageUrl = string.Format("http://ddragon.leagueoflegends.com/cdn/{0}/img/item/{1}", braveChampion.Version, selectedItemDto.Image.Full), Name = string.Format("{0} - {1}", relatedBoot.Name, selectedItemDto.Name), From = new List <int>() { 1001, relatedBoot.Id } }); } //Viktor builds get the Perfect Hex Core else { selectedItemDto = allItems.FirstOrDefault(i => i.Name == "Perfect Hex Core"); itemList.Add(new SelectedItem() { Cost = selectedItemDto.Gold.Total, Id = selectedItemDto.Id, ImageUrl = string.Format("http://ddragon.leagueoflegends.com/cdn/{0}/img/item/{1}", braveChampion.Version, selectedItemDto.Image.Full), Name = selectedItemDto.Name, From = new List <int>() { 3200, 3196, 3197 } }); } bool hasJungleItem = false; for (int i = 0; i < 5; i++) { bool isJungleItem; do { selectedItemDto = selectableItems[random.Next(0, selectableItems.Count - 1)]; if (hasSmite && selectedItemDto.Group == "JungleItems") { isJungleItem = true; } else { isJungleItem = false; } } while ( //Ensure we haven't selected the item already itemList.Any(si => si.Id == selectedItemDto.Id) || //Don't allow melee champions to buy ranged only items. Might be a better way to do this but I don't see it. Is there an actual flag? (isMelee && selectedItemDto.Name.Contains("(Ranged Only)")) || //Don't allow ranged champions to buy melee only items. Might be a better way to do this but I don't see it. Is there an actual flag? (!isMelee && selectedItemDto.Name.Contains("(Melee Only)")) || //Don't allow more than one jungle item to be added (hasJungleItem && isJungleItem) ); string itemName = selectedItemDto.Name; List <int> itemFrom = new List <int>(); //Append base jungle item name to enchantment like we do with boots for jungle items if (isJungleItem) { hasJungleItem = true; ItemDto baseJungleItem; itemFrom.Add(1039); foreach (string itemId in selectedItemDto.From) { baseJungleItem = jungleOnlyItems.FirstOrDefault(ji => ji.Id == Convert.ToInt32(itemId)); if (baseJungleItem != null) { itemName = string.Format("{0} - {1}", baseJungleItem.Name, selectedItemDto.Name); break; } } } if (selectedItemDto.From != null) { itemFrom.AddRange(selectedItemDto.From.Select(si => Convert.ToInt32(si))); } itemList.Add(new SelectedItem() { Cost = selectedItemDto.Gold.Total, Id = selectedItemDto.Id, ImageUrl = string.Format("http://ddragon.leagueoflegends.com/cdn/{0}/img/item/{1}", braveChampion.Version, selectedItemDto.Image.Full), Name = itemName, JungleItem = isJungleItem, From = itemFrom }); } braveChampion.Items = itemList; } } #endregion Item Selection #region Mastery Summary Selection int totalMasteries = 0; int selectedMasteryTotal = 0; braveChampion.MasterySummary = new MasterySummary(); selectedMasteryTotal = random.Next(0, 31); totalMasteries = selectedMasteryTotal; braveChampion.MasterySummary.Offense = selectedMasteryTotal; selectedMasteryTotal = random.Next(0, 31 - totalMasteries); totalMasteries += selectedMasteryTotal; braveChampion.MasterySummary.Defense = selectedMasteryTotal; braveChampion.MasterySummary.Utility = 30 - totalMasteries; #endregion Mastery Summary Selection //Only successful if got champion, item and summoner spell data. braveChampion.Success = mapSuccess && champSuccess && itemSuccess && summonerSpellSuccess; return(braveChampion); }
public void ThenTheAlbumsAreReturnedInTheJSONData() { RESTHelpers.CompareJSON("AlbumsJSON", "AlbumsJSON.json"); }
public void ThenTheNewReleaseJsonIsReturnedFromTheSpotifyAPI() { RESTHelpers.CompareJSON("NewReleaseJSON", "NewReleases.json"); }
public void ThenTheJSONReturnedMatchesWhatIsExpected() { RESTHelpers.CompareJSON("CategoriesJSON", "CategoriesJSON.json"); }
static async Task MatchDetailScraperAsync(String[] args) { /* * For the sake of "Compartimentilization" (or however you spell it...) * I am assigning these local variables from the global ones, so when * this function moves you can easily change what the values are. */ int HttpResponse_RateLimitExceeded = 429; String jsonCacheDirectory = JSONCacheDirectory; String matchInfoDirectory = MatchDetailDirectory; String baseUrl = BaseUrl; String fileSearchPattern = "*.json"; int millisecondsPerRequest = 250; //Stopwatch sw = new Stopwatch(); //====-------------------------------- List <string> regions = new List <string>(); regions.Add("na"); regions.Add("euw"); regions.Add("kr"); regions.Add("tr"); regions.Add("lan"); regions.Add("eune"); regions.Add("oce"); regions.Add("las"); regions.Add("br"); regions.Add("ru"); try { foreach (string region in regions) { String inputDirectory = Path.Combine(jsonCacheDirectory, region); String outputDirectory = Path.Combine(inputDirectory, matchInfoDirectory); if (!Directory.Exists(outputDirectory)) { Directory.CreateDirectory(outputDirectory); } foreach (var file in Directory.GetFiles(inputDirectory, fileSearchPattern)) { using (StreamReader reader = new StreamReader(new FileStream(file, FileMode.Open))) { //Way to drunk to use any sort of JSON craziness String[] matchIds = reader.ReadToEnd() .Replace("[", "") .Replace("]", "") .Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < matchIds.Length; i++) { string outputFileName = Path.Combine(outputDirectory, matchIds[i] + ".json"); if (!File.Exists(outputFileName)) { String apiEndpoint = string.Format( "{0}{1}/v2.2/match/{2}", baseUrl.Replace("/na.", "/" + region + "."), region, matchIds[i]); //sw.Start(); RESTResult <MatchDetail> gameListResult = await RESTHelpers.RESTRequest <MatchDetail>(apiEndpoint, "", DevKey, "includeTimeline=true", 5); //sw.Stop(); if (gameListResult.Success) { //int remainingDelay = millisecondsPerRequest - (int)sw.ElapsedMilliseconds; //if (remainingDelay > 0) //{ // Thread.Sleep(remainingDelay); //} JavaScriptSerializer jss = new JavaScriptSerializer(); File.WriteAllText(outputFileName, jss.Serialize(gameListResult.ReturnObject)); Console.WriteLine(string.Format("Region {0}, File {1}", region, outputFileName)); } else if ((int)gameListResult.StatusCode == HttpResponse_RateLimitExceeded) { Console.WriteLine("Rate Exceeded, waiting {0}ms before trying again.", millisecondsPerRequest); //decrement the iterator and try this file again momentarily i--; Thread.Sleep(millisecondsPerRequest); } else { Console.WriteLine("Fail, Http Resonse: {0}", (int)gameListResult.StatusCode); } } } } } } } catch (Exception e) { Console.WriteLine("Exception thrown: " + e); } }