예제 #1
0
        public void InvalidUserId()
        {
            var api = new SteamApiClient();
            api.Key = Constants.ValidApiKey;

            var results = api.GetFriendList(Constants.InvalidSteamId);
        }
예제 #2
0
        /// <summary>
        /// Initializes instance according to parameter values.
        /// </summary>
        /// <param name="apiKey">Key to get access to Steam service.</param>
        /// <exception cref="ArgumentException">
        /// <paramref name="apiKey" /> is <c>null</c>, presents empty strings or contains only
        /// whitespaces.
        /// </exception>
        public SteamCrawler(string apiKey)
        {
            _apiKey = apiKey.ThrowIfNullOrWhiteSpace(nameof(apiKey));

            _steamApiClient = new SteamApiClient(
                new SteamApiConfig
            {
                ApiKey = _apiKey
            }
                );
        }
        public void InvalidUrl_ThrowsEmptyResponseException()
        {
            var response = SteamApiClient.GetProfilePicBytesAsync("https://www.liibalaaba.com/pic.xf")
                           .Result;

            SleepAfterSendingRequest();

            Assert.False(response.Successful);
            Assert.Null(response.Contents);
            Assert.NotNull(response.ThrownException);
        }
예제 #4
0
        public void PrivateProfileId_ThrowsPrivateResponseException()
        {
            var response = SteamApiClient.GetFriendslistAsync(76561198089305067)
                           .Result;

            SleepAfterSendingRequest();

            Assert.False(response.Successful);
            Assert.NotNull(response.ThrownException);
            Assert.Null(response.Contents);
            Assert.True(response.ThrownException is ApiPrivateContentException);
        }
예제 #5
0
        public Dictionary <long, string> GetAllSteamApps()
        {
            if (_allSteamApps != null && _allSteamAppsCachedOn != null && _allSteamAppsCachedOn > DateTime.Now.AddDays(-1))
            {
                return(_allSteamApps);
            }
            SteamApiClient steamApiClient = _serviceProvider.GetService <SteamApiClient>();

            _allSteamApps         = steamApiClient.GetAppList();
            _allSteamAppsCachedOn = DateTime.Now;
            return(_allSteamApps);
        }
        public void SingleFaultyId_ThrowsEmptyApiResponseException()
        {
            var response = SteamApiClient.GetSteamAccountAsync(0)
                           .Result;

            SleepAfterSendingRequest();

            Assert.False(response.Successful);
            Assert.NotNull(response.ThrownException);
            Assert.True(response.ThrownException is ApiEmptyResultException);
            Assert.Null(response.Contents);
        }
예제 #7
0
        [InlineData(570, 1578495913)] // dota 2, 2020
        public void TimestampDefined_ReturnsNewsItemsWithCorrectTimetamp(uint appId, long timestamp)
        {
            var requestResponse = SteamApiClient.GetAppNewsAsync(appId, endDateTimestamp: timestamp)
                                  .Result;

            SleepAfterSendingRequest();

            Assert.True(requestResponse.Successful);
            Assert.All(requestResponse.Contents.NewsItems, item => {
                Assert.True(timestamp >= (long)item.Date);
            });
        }
예제 #8
0
        [InlineData(203770)] // Crusader Kings II
        public void ValidAppId_ReturnsAppNewsAboutApp(uint appId)
        {
            var response = SteamApiClient.GetAppNewsAsync(appId)
                           .Result;

            SleepAfterSendingRequest();

            Assert.True(response.Successful);
            Assert.Equal(appId, response.Contents.AppId);
            Assert.NotEmpty(response.Contents.NewsItems);
            Assert.True(response.Contents.TotalCount > 0);
        }
        public void SingleId_ReturnsRequestedProfile()
        {
            var response = SteamApiClient.GetSteamAccountAsync(76561197960321706)
                           .Result;

            SleepAfterSendingRequest();

            Assert.True(response.Contents.Id64 == 76561197960321706);
            Assert.NotEmpty(response.Contents.PersonaName);
            Assert.NotEmpty(response.Contents.AvatarMediumURL);
            Assert.NotEmpty(response.Contents.AvatarFullURL);
            Assert.NotEmpty(response.Contents.AvatarSmallURL);
        }
        public void MultipleProductTypes_ReturnsRequestedSteamProducts(IncludeProducts products)
        {
            var response = SteamApiClient.GetSteamProductsAsync(products)
                           .Result;

            SleepAfterSendingRequest();

            Assert.NotEmpty(response.Contents);
            Assert.All(response.Contents, product => {
                Assert.True(product.AppId != 0);
                Assert.True(product.LastModified != 0);
            });
        }
예제 #11
0
        /// <summary>
        /// Get a list of apps and games listed on the Steam store
        /// </summary>
        /// <param name="client">The <see cref="SteamApiRequest"/> to use</param>
        /// <returns>10,000 apps or games being sold on the Steam store</returns>
        public static SteamStoreListingContainer GetStoreApps(this SteamApiClient client)
        {
            var request = new SteamStoreListingRequest
            {
                IncludeDLC      = false,
                IncludeGames    = true,
                IncludeHardware = false,
                IncludeSoftware = true,
                IncludeVideos   = false
            };

            return(client.Perform <SteamStoreListingResponse>(request).Listing);
        }
예제 #12
0
        public void ValidIds_ReturnsAccountBans(IEnumerable <ulong> id64s)
        {
            var response = SteamApiClient.GetSteamAccountsBansAsync(id64s)
                           .Result;

            SleepAfterSendingRequest();

            Assert.True(response.Successful);
            Assert.Equal(response.Contents.Count, id64s.Count());
            Assert.All(response.Contents, ban =>
            {
                Assert.Contains(id64s, id => id == ban.Id64);
            });
        }
        /// <summary>
        /// Change a server's memo/side-note
        /// </summary>
        /// <param name="client">The <see cref="SteamApiRequest"/> to use</param>
        /// <param name="serverId">The Steam Id of the game server</param>
        /// <param name="newMemo">The new memo to set</param>
        public static void ChangeServerMemo(this SteamApiClient client, ulong serverId, string newMemo)
        {
            HttpResponseMessage response = null;

            try
            {
                var request = new SteamGameServerMemoChangeRequest(serverId, newMemo);
                response = client.Perform(request);
            }
            finally
            {
                response?.Dispose();
            }
        }
예제 #14
0
        private static async Task Examples()
        {
            var steamApiClient = new SteamApiClient();

            // Get full list of SteamApps.
            SteamAppBriefInfoList steamAppList = await steamApiClient.GetAppListAsync();

            Console.WriteLine($"Got {steamAppList.Apps.Length.ToString()} items.");

            // Get details for SteamApp with ID 292030 (The Witcher 3: Wild Hunt).
            SteamApp steamApp1 = await steamApiClient.GetSteamAppAsync(292030);

            Console.WriteLine($"Got response for {steamApp1.Name}.");

            // Get details for SteamApp with same ID for region US.
            SteamApp steamApp2 = await steamApiClient.GetSteamAppAsync(292030, CountryCode.USA);

            Console.WriteLine($"Got response for {steamApp2.Name}.");

            // Get details for Package with ID 68179 (Don't Starve Together).
            PackageInfo package1 = await steamApiClient.GetPackageInfoAsync(68179);

            Console.WriteLine($"Got response for {package1.Name}.");

            // Get details for Package with same ID for region JP.
            PackageInfo package2 = await steamApiClient.GetPackageInfoAsync(68179, CountryCode.Japan);

            Console.WriteLine($"Got response for {package2.Name}.");

            // Get a list of featured games.
            FeaturedApps featured1 = await steamApiClient.GetFeaturedAppsAsync();

            Console.WriteLine($"Got {featured1.FeaturedWin.Length.ToString()} items for Windows.");

            // Get a list of featured games for region DE.
            FeaturedApps featured2 = await steamApiClient.GetFeaturedAppsAsync(CountryCode.Germany);

            Console.WriteLine($"Got {featured2.FeaturedWin.Length.ToString()} items for Windows.");

            // Get a list of featured games grouped by category.
            FeaturedCategories featuredCategories1 = await steamApiClient.GetFeaturedCategoriesAsync();

            Console.WriteLine($"Got {featuredCategories1.TopSellers.Items.Length.ToString()} top sellers items.");

            // Get a list of featured games grouped by category for region US.
            FeaturedCategories featuredCategories2 = await steamApiClient.GetFeaturedCategoriesAsync(CountryCode.USA);

            Console.WriteLine($"Got {featuredCategories2.TopSellers.Items.Length.ToString()} top sellers items.");
        }
예제 #15
0
        public void HappyPath()
        {
            var api = new SteamApiClient();
            api.Key = Constants.ValidApiKey;

            var response = api.GetFriendList(Constants.ValidSteamId);

            Assert.IsNotNull(response);
            Assert.AreNotEqual(0, response.Length);

            foreach (var friend in response)
            {
                Assert.IsNotNull(friend);
                Assert.IsNotNull(friend.SteamId);
            }
        }
        public void ProductTypeUsedAsSet_ReturnsRequestedSteamProducts()
        {
            var response1 = SteamApiClient.GetSteamProductsAsync(IncludeProducts.GameProducs)
                            .Result;

            SleepAfterSendingRequest();
            var response2 = SteamApiClient.GetSteamProductsAsync(IncludeProducts.DLC | IncludeProducts.Games)
                            .Result;

            SleepAfterSendingRequest();

            for (int i = 0; i < response1.Contents.Count; i++)
            {
                Assert.True(response1.Contents[i].AppId == response2.Contents[i].AppId);
            }
        }
        public void MultipleIds_ReturnsAllRequestedProfiles(IEnumerable <ulong> id64s, int count)
        {
            var response = SteamApiClient.GetSteamAccountsAsync(id64s)
                           .Result;

            SleepAfterSendingRequest();

            Assert.True(response.Contents.Count == count);
            Assert.All(response.Contents, p =>
            {
                Assert.Contains(id64s, id => id == p.Id64);
                Assert.NotEmpty(p.AvatarMediumURL);
                Assert.NotEmpty(p.AvatarFullURL);
                Assert.NotEmpty(p.AvatarSmallURL);
            });
        }
예제 #18
0
        /// <summary>
        /// Get a list of apps and games listed on the Steam store. Picks up from where the last request left off
        /// </summary>
        /// <param name="client">The <see cref="SteamApiRequest"/> to use</param>
        /// <param name="maxItems">Max number of entries to be returned</param>
        /// <returns>Up-to <see cref="maxItems"/> games and apps being sold on the Steam store</returns>
        public static SteamStoreListingContainer GetStoreApps(this SteamApiClient client, uint maxItems, SteamStoreListingContainer lastItem)
        {
            var request = new SteamStoreListingRequest
            {
                IncludeDLC      = false,
                IncludeGames    = true,
                IncludeHardware = false,
                IncludeSoftware = true,
                IncludeVideos   = false,

                LastAppId  = lastItem.LastApp,
                MaxEntries = maxItems
            };

            return(client.Perform <SteamStoreListingResponse>(request).Listing);
        }
        /// <summary>
        /// Cancel a trade offer the API Key owner has made
        /// </summary>
        /// <param name="client">The <see cref="SteamApiClient"/> to use</param>
        /// <param name="offerId">The id of the offer to cancel</param>
        public static void CancelTrade(this SteamApiClient client, ulong offerId)
        {
            var request = new SteamUserTradeCancelRequest(offerId);
            HttpResponseMessage result = null;

            try
            {
                result = client.Perform(request);

                if (!result.IsSuccessStatusCode)
                {
                    throw new SteamRequestFailedException();
                }
            }
            finally
            {
                result?.Dispose();
            }
        }
        public void DefaultConditions_ReturnsApiList()
        {
            var requestResult = SteamApiClient.GetApiListAsync()
                                .Result;

            SleepAfterSendingRequest();

            Assert.True(requestResult.Successful);
            Assert.NotEmpty(requestResult.Contents);
            Assert.All(requestResult.Contents, resp => {
                Assert.NotNull(resp.Methods);
                Assert.NotEmpty(resp.Methods);
                Assert.NotEmpty(resp.Name);
                Assert.All(resp.Methods, method => {
                    Assert.NotEmpty(method.Name);
                    Assert.True(method.Version != 0);
                    Assert.NotEmpty(method.HttpMethod);
                });
            });
        }
예제 #21
0
        /// <summary>
        /// Resolves a user-customized profile url to a <see cref="SteamUserProfile"/>
        /// </summary>
        /// <param name="client">The <see cref="SteamApiClient"/> to use</param>
        /// <param name="steamUrl">The user's steam link, with or without the domain</param>
        /// <returns>The user's <see cref="SteamUserProfile"/>, providing the url was valid</returns>
        public static SteamUserProfile GetUserProfile(this SteamApiClient client, string steamUrl)
        {
            ulong?steamId = null;

            if (steamUrl.Contains("id"))
            {
                steamId = client.ResolveVanityUrl(steamUrl.TrimEnd('/').Split('/').Last());
            }
            else if (steamUrl.Contains("profiles"))
            {
                steamId = Convert.ToUInt64(steamUrl.TrimEnd('/').Split('/').Last());
            }

            //todo custom exception
            if (!steamId.HasValue)
            {
                throw new SteamRequestFailedException();
            }

            return(GetUserProfile(client, steamId.Value));
        }
        /// <summary>
        /// Get a summary of trade offers for the API Key owners' account
        /// </summary>
        /// <param name="client">The <see cref="SteamApiClient"/> to use</param>
        /// <returns>A summary of the user's trade offers</returns>
        public static SteamUserTradeOffersSummary GetTradeOffersSummary(this SteamApiClient client)
        {
            var request = new SteamUserTradeOffersSummaryRequest();

            return(client.Perform <SteamUserTradeOffersSummaryResponse>(request).Summary);
        }
예제 #23
0
 /// <summary>
 /// Instantiates SteamApiDataAccess object.
 /// </summary>
 public SteamApiDataAccess()
 {
     _client = new SteamApiClient();
 }
예제 #24
0
        /// <summary>
        /// List the apps/games recently opened by the user
        /// </summary>
        /// <param name="client">The <see cref="SteamApiClient"/> to use</param>
        /// <param name="steamId">The user's SteamID64</param>
        /// <param name="maxEntries">The maximum number of items to return</param>
        /// <returns>An <see cref="IEnumerable{T}"/> of <see cref="SteamApp"/>s, representing the games/apps recently used</returns>
        public static IEnumerable <SteamApp> GetUserRecentApps(this SteamApiClient client, ulong steamId, ushort maxEntries)
        {
            var request = new SteamUserRecentsRequest(steamId, maxEntries);

            return(client.Perform <SteamUserLibraryResponse>(request).Library.Apps);
        }
예제 #25
0
 public SteamLogic(UnitOfWork uow, SteamApiClient steamApi, MemoryCacheService memoryCache)
 {
     _uow         = uow;
     _steamApi    = steamApi;
     _memoryCache = memoryCache;
 }
예제 #26
0
 public SteamApiClientTests()
 {
     _steamApiClient = new SteamApiClient();
 }
        /// <summary>
        /// Get the community market prices for all items offered by a specific app
        /// </summary>
        /// <param name="client">The <see cref="SteamApiClient"/> to use</param>
        /// <param name="appId">The App Id to get market info for</param>
        /// <returns>A list of all the items and their prices in various currencies</returns>
        public static IEnumerable <SteamGameEconomyAssetPriceInfo> GetMarketPricesForApp(this SteamApiClient client, uint appId)
        {
            var request = new SteamGameEconomyAssetPriceRequest(appId);

            return(client.Perform <SteamGameEconomyAssetPriceResponse>(request).PriceInfo.Assets);
        }
예제 #28
0
        /// <summary>
        /// Get achievement and stats information for a specified game.
        /// </summary>
        /// <param name="client">The <see cref="SteamApiClient"/> to use</param>
        /// <param name="appId">The App Id to get the schema for</param>
        /// <returns></returns>
        public static SteamGameSchemaContainer GetSchemaForGame(this SteamApiClient client, uint appId)
        {
            var request = new SteamGameSchemaRequest(appId);

            return(client.Perform <SteamGameSchemaResponse>(request).Schema);
        }
예제 #29
0
 public SteamMetadataProvider(SteamServicesClient playniteServices, SteamLibrary library, SteamApiClient apiClient)
 {
     this.library          = library;
     this.playniteServices = playniteServices;
     this.apiClient        = apiClient;
 }
예제 #30
0
 public CustomSteamClient(Bot bot)
 {
     _bot    = bot;
     _client = new SteamApiClient(RestClient.For <ISteamApi>(SteamCommunityUrl));
 }
        /// <summary>
        /// Get the estimated trade hold between the API key owner and another user
        /// </summary>
        /// <param name="client">The <see cref="SteamApiClient"/> to use</param>
        /// <param name="targetUser">The SteamID of the target</param>
        /// <param name="targetToken">The `token` parameter of the user's Trade URL</param>
        /// <returns>The info of all parties' hold durations and a final one that will be used in the real trade</returns>
        public static SteamUserTradeHoldDurationContainer GetTradeHoldDurations(this SteamApiClient client, ulong targetUser, string targetToken)
        {
            var request = new SteamUserTradeHoldDurationRequest(targetUser, targetToken);

            return(client.Perform <SteamUserTradeHoldDurationResponse>(request).HoldDurations);
        }
예제 #32
0
        /// <summary>
        /// Get the trade history for the API key owner's account
        /// </summary>
        /// <param name="client">The <see cref="SteamApiClient"/> to use</param>
        /// <param name="maxEntries">Max number of trades to return</param>
        /// <returns>Returns up-to the <see cref="maxEntries"/> of trades and descriptions of the items in referenced trades</returns>
        public static SteamUserTradeHistoryContainer GetTradeHistory(this SteamApiClient client, uint maxEntries)
        {
            var request = new SteamUserTradeHistoryRequest(maxEntries);

            return(client.Perform <SteamUserTradeHistoryResponse>(request).History);
        }