Example #1
0
        /// <summary>
        /// Sends GET request for any kinds of products in Steam store.
        /// Request can be cancelled by providing cancellation token.
        /// </summary>
        /// <param name="products">What products to include</param>
        /// <param name="callSize">Call size</param>
        /// <param name="cToken">Cancellation token</param>
        /// <returns>SteamProductResponse object</returns>
        public async Task <SteamProductsResponse> GetSteamProductsAsync(IncludeProducts products,
                                                                        ProductCallSize callSize = ProductCallSize.Default, CToken cToken = default)
        {
            if (products.Equals(IncludeProducts.None))
            {
                return(new SteamProductsResponse()
                {
                    Successful = false
                });
            }
            else
            {
                bool callAll = CallSizeToString(callSize, out string size);
                CreateProductUrl(products, size);

                string originalUrl              = UrlBuilder.GetEncodedUrl();
                SteamProductsResponse result    = null;
                Exception             exception = null;

                if (callAll)
                {
                    (result, exception) = await GetAllProducts(result, exception, cToken);
                }
                else
                {
                    (result, exception) = await GetProducts(result, exception, cToken);
                }
                return(WrapResponse(result, originalUrl, exception));
            }
        }
Example #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="result"></param>
        /// <param name="thrown"></param>
        /// <param name="cToken"></param>
        /// <returns></returns>
        private async Task <(SteamProductsResponse, Exception)> GetProducts(
            SteamProductsResponse result, Exception thrown, CToken cToken)
        {
            try
            {
                var response = await GetModelAsync <SteamProductsResponseParent>(UrlBuilder.PopEncodedUrl(false), cToken)
                               .ConfigureAwait(false);

                result = new SteamProductsResponse()
                {
                    Contents    = response.Content.ProductList,
                    LastAppId   = response.Content.LastId,
                    MoreResults = response.Content.MoreResults
                };
            }
            catch (Exception ex)
            {
                thrown = ex;
            }
            return(result, thrown);
        }
Example #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="result"></param>
        /// <param name="thrown"></param>
        /// <param name="cToken"></param>
        /// <returns></returns>
        private async Task <(SteamProductsResponse, Exception)> GetAllProducts(
            SteamProductsResponse result, Exception thrown, CToken cToken)
        {
            try
            {
                SteamProductsResponseParent chunk       = null;
                SteamProductsResponseParent allProducts =
                    await GetModelAsync <SteamProductsResponseParent>(UrlBuilder.GetEncodedUrl(), cToken : cToken)
                    .ConfigureAwait(false);

                while (allProducts.Content.MoreResults)
                {
                    UrlBuilder.AppendQuery("last_appid", allProducts.Content.LastId.ToString());
                    chunk = await GetModelAsync <SteamProductsResponseParent>(UrlBuilder.GetEncodedUrl(), cToken : cToken)
                            .ConfigureAwait(false);

                    allProducts.Content.LastId = chunk.Content.LastId;
                    allProducts.Content.ProductList.AddRange(chunk.Content.ProductList);
                    allProducts.Content.MoreResults = chunk.Content.MoreResults;
                }
                result = new SteamProductsResponse()
                {
                    Contents    = allProducts.Content.ProductList,
                    LastAppId   = chunk.Content.LastId,
                    MoreResults = chunk.Content.MoreResults
                };
            }
            catch (Exception ex)
            {
                thrown = ex;
            }
            finally
            {
                UrlBuilder.PopEncodedUrl(false);
            }
            return(result, thrown);
        }