/// <summary> /// Retrieves a list of featured items. Some of the data in response may vary for a given /// country code and language. /// </summary> /// <param name="countryCode"> /// Two letter country code to customise currency and date values. /// </param> /// <param name="language"> /// Full name of the language in english used for string localization e.g. name, /// description. /// </param> /// <param name="token">Propogates notification that operation should be cancelled.</param> /// <returns>A list of featured items in the steam store.</returns> public async Task <FeaturedApps> GetFeaturedAppsAsync(CountryCode countryCode, Language language, CancellationToken token = default) { var queryParameters = new QueryParametersBuilder(); if (countryCode != CountryCode.Unknown) { queryParameters.AppendParameter( "cc", CountryCodeConverter.GetCountryCodeStringValue(countryCode) ); } if (language != Language.Unknown) { queryParameters.AppendParameter("l", language.ToString().ToLower()); } using (var response = await GetRetryPolicy().ExecuteAsync( () => _httpClient.GetAsync(_config.SteamStoreBaseUrl + "/api/featured" + queryParameters.ToString(), token))) { response.EnsureSuccessStatusCode(); var result = await response.Content.ReadAsStringAsync(); var jsonData = JToken.Parse(result); if (jsonData["status"].ToString() != "1") { throw new SteamApiBadRequestException( "Bad request status. Check if you specified right parameters." ); } return(FeaturedApps.FromJson(result)); } }
/// <summary> /// Retrieves a list of featured items via an asynchronous operation.</summary> /// <param name="CountryCode">Two letter country code to customise currency and date values.</param> /// <param name="Language">Full name of the language in english used for string localization e.g. name, description.</param> public static async Task <FeaturedApps> GetAsync(string CountryCode, string Language) { string steamUri = steamBaseUri; steamUri = string.IsNullOrWhiteSpace(CountryCode) ? steamUri : $"{steamUri}?cc={CountryCode}"; if (!string.IsNullOrWhiteSpace(Language)) { steamUri += string.IsNullOrWhiteSpace(CountryCode) ? "?" : "&"; steamUri += $"l={Language.ToLower()}"; } var response = await client.GetAsync(steamUri); if (!response.IsSuccessStatusCode) { return(null); } var result = await response.Content.ReadAsStringAsync(); var jsonData = JToken.Parse(result); if (jsonData["status"].ToString() != "1") { return(null); } return(FeaturedApps.FromJson(result)); }