コード例 #1
0
        /// <summary>
        /// Sends GET request for supported Api list. Request can
        /// be cancelled providing CancellationToken.
        /// </summary>
        /// <param name="version">API method version</param>
        /// <param name="cToken">Cancellation token</param>
        /// <returns>ApiListResponse object</returns>
        public async Task <ApiListResponse> GetApiListAsync(string version = "v1", CToken cToken = default)
        {
            UrlBuilder.Host = HOST;
            UrlBuilder.AppendPath(ISTEAM_WEB_API, "GetSupportedAPIList", version);

            string          url       = UrlBuilder.PopEncodedUrl(false);
            ApiListResponse result    = null;
            Exception       exception = null;

            try
            {
                var response = await GetModelAsync <ApiListResponseParent>(url, cToken)
                               .ConfigureAwait(false);

                result = new ApiListResponse()
                {
                    Contents = response.Apilist.Interfaces
                };
            }
            catch (Exception ex)
            {
                exception = ex;
            }
            return(WrapResponse(result, url, exception));
        }
コード例 #2
0
        /// <summary>
        /// Sends GET request for Steam serverinfo. Request can be
        /// cancelled providing CancellationToken.
        /// </summary>
        /// <param name="version">API method version</param>
        /// <param name="cToken">Cancellation token</param>
        /// <returns>SteamServerInfo object.</returns>
        public async Task <SteamServerInfoResponse> GetSteamServerInfoAsync(string version = "v1", CToken cToken = default)
        {
            UrlBuilder.Host = HOST;
            UrlBuilder.AppendPath(ISTEAM_WEB_API, "GetServerInfo", version);

            string url = UrlBuilder.PopEncodedUrl(false);
            SteamServerInfoResponse result = null;
            Exception exception            = null;

            try
            {
                var response = await GetModelAsync <SteamServerInfo>(url, cToken)
                               .ConfigureAwait(false);

                result = new SteamServerInfoResponse()
                {
                    Contents = response
                };
            }
            catch (Exception ex)
            {
                exception = ex;
            }
            return(WrapResponse(result, url, exception));
        }
コード例 #3
0
        /// <summary>
        /// Sends http GET request to api.steampowered.com
        /// for steam application news.
        /// </summary>
        /// <returns>AppNewsCollection object</returns>
        public async Task <AppNewsResponse> GetAppNewsAsync(uint appId, uint count = 20,
                                                            long endDateTimestamp  = -1, CToken cToken = default, params string[] tags)
        {
            UrlBuilder.Host = HOST;
            UrlBuilder.AppendPath(ISTEAM_NEWS, "GetNewsForApp", "v2");
            UrlBuilder.AppendQuery("appid", appId.ToString())
            .AppendQuery("count", count.ToString())
            .AppendQuery("enddate", ValidateTimestamp(endDateTimestamp).ToString())
            .AppendQuery("tags", string.Join(",", tags));

            string          url       = UrlBuilder.PopEncodedUrl(false);
            AppNewsResponse result    = null;
            Exception       exception = null;

            try
            {
                var response = await GetModelAsync <AppNewsResponseParent>(url, cToken)
                               .ConfigureAwait(false);

                result = new AppNewsResponse()
                {
                    Contents = response.AppNews
                };
            }
            catch (Exception ex)
            {
                // API creators did really excellet job, invalid id results to Forbidden HTTP status code
                if (ex is ApiException apiEx && apiEx.HttpStatusCode == 403)
                {
                    exception = new ApiEmptyResultException($"App id is propably invalid: {appId}", apiEx);
                }
コード例 #4
0
        public void AppendPath(string url, string path, string expected)
        {
            var builder = new UrlBuilder(url);

            builder.Should().NotBeNull();

            builder.AppendPath(path);
            builder.Path.Should().NotBeEmpty();
            builder.ToString().Should().Be(expected);
        }
コード例 #5
0
 /// <summary>
 /// Creates URL for GetSteamProducts-method.
 /// </summary>
 /// <returns>UrlBuilder object</returns>
 private void CreateProductUrl(IncludeProducts products, string count)
 {
     UrlBuilder.Host = HOST;
     UrlBuilder.AppendPath(ISTORE_SERVICE, "GetAppList", "v1");
     UrlBuilder.AppendQuery("key", ApiKey)
     .AppendQuery("max_results", count)
     .AppendQuery("include_games", products.HasFlag(IncludeProducts.Games) ? "1" : "0")
     .AppendQuery("include_dlc", products.HasFlag(IncludeProducts.DLC) ? "1" : "0")
     .AppendQuery("include_software", products.HasFlag(IncludeProducts.Software) ? "1" : "0")
     .AppendQuery("include_hardware", products.HasFlag(IncludeProducts.Harware) ? "1" : "0")
     .AppendQuery("include_videos", products.HasFlag(IncludeProducts.Videos) ? "1" : "0");
 }
コード例 #6
0
        /// <summary>
        /// Sends http GET request to api.steampowered.com for
        /// CSGO server status info. Request can be cancelled by
        /// providing cancellation token.
        /// </summary>
        /// <param name="version">API method version</param>
        /// <param name="cToken">Cancellation token</param>
        /// <returns>CSGO server status model</returns>
        public async Task <CsGoServerStatusResponse> GetCsGoServerStatusAsync(string version = "v1",
                                                                              Ctoken cToken  = default)
        {
            UrlBuilder.Host = HOST;
            UrlBuilder.AppendPath("ICSGOServers_730", "GetGameServersStatus", version);
            UrlBuilder.AppendQuery("key", ApiKey);

            string url = UrlBuilder.PopEncodedUrl(false);
            CsGoServerStatusResponse result = null;
            Exception exception             = null;

            try
            {
                var response = await GetModelAsync <CsGoServerStatusResponse>(url, cToken)
                               .ConfigureAwait(false);

                result = response;
            }
            catch (Exception ex)
            {
                exception = ex;
            }
            return(WrapResponse(result, url, exception));
        }