internal static Uri GenerateAPIRequestLink(BlizzardAPIProfiles profile, RequestLocalization requestLocalization, List <KeyValuePair <string, string> > fields, string endPointPart1 = null, string endPointPart2 = null) { string processingUriAddress = string.Empty; processingUriAddress = processingUriAddress.AddToEndPointSampleToUrl(requestLocalization.CoreRegionUrlAddress); processingUriAddress = processingUriAddress.AddToEndPointSampleToUrl(profile.ToString().ToLower()); processingUriAddress = processingUriAddress.AddToEndPointSampleToUrl(endPointPart1 == null ? string.Empty : endPointPart1.ToLower()); processingUriAddress = processingUriAddress.AddToEndPointSampleToUrl(endPointPart2 == null ? string.Empty : endPointPart2.ToLower()); processingUriAddress = processingUriAddress.EndsWith("/") ? processingUriAddress.Remove(processingUriAddress.Length - 1, 1) : processingUriAddress; if (requestLocalization.Realm != null) { fields.Add(new KeyValuePair <string, string>("?locale", requestLocalization.Realm.Locale)); } foreach (KeyValuePair <string, string> parameter in fields) { processingUriAddress = processingUriAddress.AddParameterToUrl(parameter.Key + "=" + parameter.Value); } processingUriAddress = processingUriAddress.EndsWith("&") ? processingUriAddress.Remove(processingUriAddress.Length - 1, 1) : processingUriAddress; return(new Uri(processingUriAddress)); }
internal async Task <BlizzardAPIResponse> GetCharacterAchievements(RequestLocalization requestLocalization) { Uri generatedLink = RequestLinkFormater.GenerateAPIRequestLink(BlizzardAPIProfiles.Data, requestLocalization, new List <KeyValuePair <string, string> >(), BlizzardAPIProfiles.Character.ToString(), EnumDictionaryWrapper.dataResourcesFieldsWrapper[DataResourcesFields.CharacterAchievements]); return(await new APIDataRequestManager(_comparerDatabaseContext).GetDataByHttpRequest <BlizzardAPIResponse>(generatedLink)); }
public void GenerateRaiderIOApiRequestLink_WhenGenerateLink_ShouldGenerateValidLinkForRadierIO() { //Arrange string expectedLink = "https://raider.io/api/v1/characters/profile?region=eu&realm=burning-legion&name=wykminiacz&fields=mythic_plus_best_runs%2Cmythic_plus_ranks"; RequestLocalization requestLocalization = new RequestLocalization() { CoreRegionUrlAddress = APIConf.RaiderIOAdress, Realm = new Realm() { Slug = "burning-legion", Locale = "en_GB", Timezone = "Europe/Paris" } }; List <RaiderIOCharacterFields> characterFields = new List <RaiderIOCharacterFields>() { RaiderIOCharacterFields.MythicPlusBestRuns, RaiderIOCharacterFields.MythicPlusRanks }; string region = requestLocalization.Realm.Timezone == "Europe/Paris" ? "eu" : throw new Exception("Chosen realm is not European"); string localFields = string.Empty; foreach (RaiderIOCharacterFields field in characterFields) { string wrappedField = EnumDictionaryWrapper.rioCharacterFieldWrapper[field]; localFields = localFields.AddFieldToUrl(wrappedField); localFields = localFields.EndsWith("+") ? localFields.Remove(localFields.Length - 1, 1) : localFields; } localFields = localFields.EndsWith("%2C") ? localFields.Remove(localFields.Length - 3, 3) // remove join parameters symbol at ending field : localFields; List <KeyValuePair <string, string> > fields = new List <KeyValuePair <string, string> >() { new KeyValuePair <string, string>("fields", localFields) }; List <KeyValuePair <string, string> > parameters = new List <KeyValuePair <string, string> >() { new KeyValuePair <string, string>(RaiderIOCharacterParams.Region.ToString(), region), new KeyValuePair <string, string>(RaiderIOCharacterParams.Realm.ToString(), requestLocalization.Realm.Slug), new KeyValuePair <string, string>(RaiderIOCharacterParams.Name.ToString(), "Wykminiacz") }; //Act Uri actualLink = RequestLinkFormater.GenerateRaiderIOApiRequestLink(fields, parameters); //Assert Assert.Equal(expectedLink, actualLink.AbsoluteUri); }
public void GenerateAPIRequestLink_WhenGenerateLink_ShouldGenerateValidLinkForCharacter() { // Arrange string expectedLink = "https://eu.api.blizzard.com/wow/character/burning-legion/selectus?locale=en_GB"; // Act RequestLocalization requestLocalization = new RequestLocalization() { CoreRegionUrlAddress = APIConf.BlizzadAPIAddressWrapper[Region.Europe], Realm = new Realm() { Slug = "burning-legion", Locale = "en_GB" } }; Uri actualLink = RequestLinkFormater.GenerateAPIRequestLink(BlizzardAPIProfiles.Character, requestLocalization, new List <KeyValuePair <string, string> >(), requestLocalization.Realm.Slug, "Selectus"); //Assert Assert.Equal(expectedLink, actualLink.AbsoluteUri); }
internal async Task <List <string> > GetRealmListByRegion(Region region) { List <string> realmsNames = new List <string>(); string regionCoreAdress = string.Empty; try { if (APIConf.BlizzadAPIAddressWrapper.TryGetValue(region, out regionCoreAdress) == false) { throw new KeyNotFoundException($"Cannot find region in {APIConf.BlizzadAPIAddressWrapper.GetType().Name} dictionary"); } var requestLocalization = new RequestLocalization() { CoreRegionUrlAddress = regionCoreAdress, }; RealmsRequests realmsRequests = new RealmsRequests(_comparerDatabaseContext); var parameters = new List <KeyValuePair <string, string> >(); Uri uriAddress = RequestLinkFormater.GenerateAPIRequestLink(BlizzardAPIProfiles.Realm, requestLocalization, parameters, "status"); //TODO replace string var realmResponse = await new APIDataRequestManager(_comparerDatabaseContext).GetDataByHttpRequest <BlizzardAPIResponse>(uriAddress); RealmStatus realmStatus = JsonProcessing.DeserializeJsonData <RealmStatus>(realmResponse.Data); foreach (Realm realmsData in realmStatus.Realms) { realmsNames.Add(realmsData.Name); } } catch (Exception) { realmsNames = new List <string>(); } return(realmsNames); }
internal async Task <RaiderIOAPIResponse> GetRaiderIODataAsync(string characterName, RequestLocalization requestLocalization, List <RaiderIOCharacterFields> characterFields) { string region = requestLocalization.Realm.Timezone == "Europe/Paris" ? "eu" : throw new Exception("Choosed realm is not European"); List <KeyValuePair <string, string> > fields = new List <KeyValuePair <string, string> >(); List <KeyValuePair <string, string> > parameters = new List <KeyValuePair <string, string> >() { new KeyValuePair <string, string>(RaiderIOCharacterParams.Region.ToString(), region), new KeyValuePair <string, string>(RaiderIOCharacterParams.Realm.ToString(), requestLocalization.Realm.Slug), new KeyValuePair <string, string>(RaiderIOCharacterParams.Name.ToString(), characterName) }; // check if there is any additional parameters to get. If not - just return basic informations if (characterFields.Any()) { string localFields = string.Empty; foreach (RaiderIOCharacterFields field in characterFields) { string wrappedField = EnumDictionaryWrapper.rioCharacterFieldWrapper[field]; localFields = localFields.AddFieldToUrl(wrappedField); localFields = localFields.EndsWith("+") ? localFields.Remove(localFields.Length - 1, 1) : localFields; } localFields = localFields.EndsWith("%2C") ? localFields.Remove(localFields.Length - 3, 3) // remove join parameters symbol at ending field : localFields; fields.Add(new KeyValuePair <string, string>("fields", localFields)); } Uri uriAddress = RequestLinkFormater.GenerateRaiderIOApiRequestLink(fields, parameters); return(await new APIDataRequestManager(_comparerDatabaseContext).GetDataByHttpRequest <RaiderIOAPIResponse>(uriAddress)); }
internal async Task <BlizzardAPIResponse> GetCharacterDataAsJsonAsync(string characterName, RequestLocalization requestLocalization, List <CharacterFields> characterFields) { List <KeyValuePair <string, string> > characterParams = new List <KeyValuePair <string, string> >(); // check if there is any additional parameters to get. If not - just return basic informations if (characterFields.Any()) { string localFields = string.Empty; foreach (CharacterFields field in characterFields) { string wrappedField = EnumDictionaryWrapper.characterFieldsWrapper[field]; localFields = localFields.AddFieldToUrl(wrappedField); } localFields = localFields.EndsWith("%2C+") ? localFields.Remove(localFields.Length - 4, 4) // remove join parameters symbol at ending field : localFields; characterParams.Add(new KeyValuePair <string, string>("?fields", localFields)); } Uri uriAddress = RequestLinkFormater.GenerateAPIRequestLink(BlizzardAPIProfiles.Character, requestLocalization, characterParams, requestLocalization.Realm.Slug, characterName); // generates link for request return(await _aPIDataRequestManager.GetDataByHttpRequest <BlizzardAPIResponse>(uriAddress)); }