예제 #1
0
        async Task DownloadAllCountriesTopHeadlines()
        {
            var client    = NewsApiClient.FromResource();
            var countries = (NewsApiCountry[])Enum.GetValues(typeof(NewsApiCountry));

            foreach (var country in countries)
            {
                var response = await client.GetTopHeadlines(new NewsApiTopHeadlinesRequest
                {
                    Language = NewsApiLanguage.EN,
                    Country  = country,
                    Page     = 0,
                    PageSize = 10,
                });

                if (CatchError(response))
                {
                    return;
                }

                var articles = response.Articles;
                var io       = new NewsApiOfflineCopyWriter(_fileName);
                io.WriteArticles(country.ToString(), articles);

                Debug.Log($"Finished downloading {country}");
            }

            Debug.Log("Finished downloading");
        }
예제 #2
0
        async Task DownloadSources()
        {
            var client   = NewsApiClient.FromResource();
            var response = await client.GetSources();

            if (CatchError(response))
            {
                return;
            }

            var sources = response.Sources;
            var io      = new NewsApiOfflineCopyWriter(_fileName);

            io.WriteSources(sources);
            AssetDatabase.Refresh();

            Debug.Log("Finished downloading");
        }
예제 #3
0
        async Task DownloadUsTopHeadlines()
        {
            var client   = NewsApiClient.FromResource();
            var response = await client.GetTopHeadlines(new NewsApiTopHeadlinesRequest
            {
                Language = NewsApiLanguage.EN,
                Country  = NewsApiCountry.US,
                Page     = 0,
                PageSize = 10,
            });

            if (CatchError(response))
            {
                return;
            }

            var articles = response.Articles;
            var io       = new NewsApiOfflineCopyWriter(_fileName);

            io.WriteArticles("ustop", articles);

            Debug.Log("Finished downloading");
        }