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));
        }
Beispiel #2
0
        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 <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));
        }