static async Task <bool> StartNeoWsAsync(string apiKey, int resultCount, string[] args, AsteroidRequest asteroidRequest) { if (args.Length == 2) { asteroidRequest.ResultCount = resultCount; } else if (args.Length == 1) { asteroidRequest.ResultCount = -1; } var neoWsClient = new NeoWsClient(apiKey); var asteroid = await neoWsClient.GetAsync(asteroidRequest); if (asteroid != null) { DisplayAsteroid(asteroid); return(false); } return(true); }
public static async Task Main(string[] args) { CultureInfo.CurrentCulture = new CultureInfo("en-GB", false); try { if (args.Length < 1 || (args[0] != "apod" && args[0] != "neows")) { ThrowOnInvalidInput(); } _config = new ConfigurationBuilder() .AddJsonFile(ConfigFile) .Build(); string apiKey = _config["ApiKey"]; if (args[0] == "apod") { if (args.Length < 2) { ThrowOnInvalidInput(); } if (!int.TryParse(args[1], out int count)) { ThrowOnInvalidInput(); } var nasaClient = new ApodClient(apiKey); MediaOfToday[] res = await nasaClient.GetAsync(count); foreach (MediaOfToday media in res) { Console.WriteLine($"{media}{Environment.NewLine}"); } } else { string startDate = _config["NeoWs:StartDate"]; string endDate = _config["NeoWs:EndDate"]; AsteroidRequest request; if (args.Length < 2 || !int.TryParse(args[1], out int count)) { request = new AsteroidRequest(startDate, endDate); } else { request = new AsteroidRequest(startDate, endDate, count); } var nasaClient = new NeoWsClient(apiKey); AsteroidLookup[] res = await nasaClient.GetAsync(request); foreach (AsteroidLookup asteroid in res) { Console.WriteLine($"- {asteroid}{Environment.NewLine}"); } } } catch (Exception e) { Console.WriteLine(e.Message); } }