コード例 #1
0
ファイル: Program.cs プロジェクト: fossabot/SteamWebApiLib
        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.");
        }
コード例 #2
0
        /// <inheritdoc />
        public override async Task <bool> GetResponse(BufferBlock <string> entitiesQueue,
                                                      BufferBlock <BasicInfo> responsesQueue, bool outputResults)
        {
            if (SteamAppsStorage.IsEmpty)
            {
                SteamAppBriefInfoList steamAppsList = await _steamApiClient.GetAppListAsync();

                SteamAppsStorage.FillStorage(steamAppsList);
            }

            // Use HashSet to avoid duplicated data which can produce errors in further work.
            var searchResults = new HashSet <BasicInfo>();

            while (await entitiesQueue.OutputAvailableAsync())
            {
                string game = await entitiesQueue.ReceiveAsync();

                SteamApp response;
                try
                {
                    int appId = SteamAppsStorage.GetAppIdByName(game);
                    response = await _steamApiClient.GetSteamAppAsync(
                        appId, CountryCode.Russia, Language.English
                        );
                }
                catch (Exception ex)
                {
                    _logger.Warn(ex, $"{game} wasn't processed.");
                    GlobalMessageHandler.OutputMessage($"{game} wasn't processed.");
                    continue;
                }

                if (outputResults)
                {
                    GlobalMessageHandler.OutputMessage($"Got {response} from {Tag}");
                }

                SteamGameInfo extractedInfo = _dataMapper.Transform(response);
                if (searchResults.Add(extractedInfo))
                {
                    await responsesQueue.SendAsync(extractedInfo);
                }
            }
            return(searchResults.Count != 0);
        }
コード例 #3
0
        public async Task TestGetSteamApp(int appId, CountryCode countryCode, Language language)
        {
            var steamApp = await _steamApiClient.GetSteamAppAsync(
                appId, countryCode, language
                );

            Assert.NotNull(steamApp);
            Assert.NotNull(steamApp.AboutTheGame);
            Assert.NotNull(steamApp.Achievements);
            Assert.NotNull(steamApp.Background);
            Assert.NotNull(steamApp.Categories);
            Assert.NotEmpty(steamApp.Categories);
            Assert.NotNull(steamApp.DetailedDescription);
            Assert.NotNull(steamApp.Developers);
            Assert.NotEmpty(steamApp.Developers);
            Assert.NotNull(steamApp.DLC);
            Assert.NotNull(steamApp.Genres);
            Assert.NotEmpty(steamApp.Genres);
            Assert.NotNull(steamApp.HeaderImage);
            Assert.NotNull(steamApp.Movies);
            Assert.NotEmpty(steamApp.Movies);
            Assert.NotNull(steamApp.Name);
            Assert.NotNull(steamApp.PackageGroups);
            Assert.NotNull(steamApp.Packages);
            Assert.NotNull(steamApp.PcRequirements);
            Assert.NotNull(steamApp.Platforms);
            Assert.NotNull(steamApp.Publishers);
            Assert.NotEmpty(steamApp.Publishers);
            Assert.NotNull(steamApp.Recommendations);
            Assert.NotNull(steamApp.ReleaseDate);
            Assert.True(steamApp.RequiredAge >= 0);
            Assert.NotNull(steamApp.Screenshots);
            Assert.NotEmpty(steamApp.Screenshots);
            Assert.NotNull(steamApp.ShortDescription);
            Assert.Equal(appId, steamApp.SteamAppId);
            Assert.NotNull(steamApp.SupportedLanguages);
            Assert.NotNull(steamApp.SupportInfo);
            Assert.NotNull(steamApp.Type);
            Assert.NotNull(steamApp.Website);
        }
コード例 #4
0
        /// <inheritdoc />
        public override List <BasicInfo> GetResponse(List <string> entities, bool outputResults)
        {
            if (SteamAppsStorage.IsEmpty)
            {
                SteamAppBriefInfoList steamAppsList = _steamApiClient.GetAppListAsync().Result;
                SteamAppsStorage.FillStorage(steamAppsList);
            }

            // Use HashSet to avoid duplicated data which can produce errors in further work.
            var searchResults = new HashSet <BasicInfo>();

            foreach (string game in entities)
            {
                SteamApp response;
                try
                {
                    int appId = SteamAppsStorage.GetAppIdByName(game);
                    response = _steamApiClient.GetSteamAppAsync(
                        appId, CountryCode.Russia, Language.English
                        ).Result;
                }
                catch (Exception ex)
                {
                    _logger.Warn(ex, $"{game} wasn't processed.");
                    GlobalMessageHandler.OutputMessage($"{game} wasn't processed.");
                    continue;
                }

                if (outputResults)
                {
                    GlobalMessageHandler.OutputMessage($"Got {response} from {Tag}");
                }

                SteamGameInfo extractedInfo = _dataMapper.Transform(response);
                searchResults.Add(extractedInfo);
            }
            return(searchResults.ToList());
        }