/// <summary> /// Used example on stack overflow as reference /// https://stackoverflow.com/questions/630803/associating-enums-with-strings-in-c-sharp /// </summary> /// <param name="type"></param> /// <returns>A string description value assigned to enum</returns> public static string GetLiveDataTypeDescription(this LiveDataType type) { DescriptionAttribute[] attributes = (DescriptionAttribute[])type .GetType() .GetField(type.ToString()) .GetCustomAttributes(typeof(DescriptionAttribute), false); return(attributes.Length > 0 ? attributes[0].Description : String.Empty); }
/// <summary> /// Get list of story items for data type provided /// </summary> /// <param name="dataType">Live data type of story to get</param> /// <returns>Stories, which is a list of ids</returns> public async Task <Stories> GetStoryIds(LiveDataType dataType) { var response = await _httpService.GetStringAsync(_configuration["HackerNewsBaseUrl"] + dataType.GetLiveDataTypeDescription() + ".json"); var stories = JsonConvert.DeserializeObject <List <int> >(response); return(new Stories { StoryIds = stories }); }