Exemple #1
0
        /// <summary>
        /// Fetch the Astronomy Picture of the Day for today's date.
        /// </summary>
        /// <remarks>
        /// "Today's date" refers to the current date in the Eastern Time Zone.
        /// Read more: <a href="https://github.com/LeMorrow/APOD.Net#when-do-new-apods-get-published-by-nasa">https://github.com/LeMorrow/APOD.Net#when-do-new-apods-get-published-by-nasa</a>.
        /// </remarks>
        /// <example>
        /// <code language="csharp">
        /// using var client = new ApodClient();
        ///
        /// var response = await client.FetchApodAsync();
        /// if (response.StatusCode != ApodStatusCode.OK) { return; }
        ///
        /// Console.WriteLine(response.Content.Date);
        /// Console.WriteLine(response.Content.Title);
        /// </code>
        /// </example>
        /// <exception cref="ObjectDisposedException">Thrown when the client has been disposed.</exception>
        /// <returns>The response.</returns>
        public async ValueTask <ApodResponse> FetchApodAsync()
        {
            ThrowExceptionIfDisposed();

            var httpResponse = await _httpRequester.SendHttpRequestAsync().ConfigureAwait(false);

            var responseError = await _errorHandler.ValidateHttpResponseAsync(httpResponse).ConfigureAwait(false);

            if (responseError.ErrorCode != ApodErrorCode.None)
            {
                return(responseError.ToApodResponse());
            }

            return(await _httpResponseParser.ParseSingleApodAsync(httpResponse).ConfigureAwait(false));
        }