/// <summary>
        ///    A hourly call provides a global hourly forecast, up to 108 hours (4.5 days) out.
        /// </summary>
        /// <param name="latitude">Latitude to request data for in decimal degrees, -87 to 89.</param>
        /// <param name="longitude">Longitude to request data for in decimal degrees, -180 to 180.</param>
        /// <param name="fields">Fields to request from climacell.</param>
        /// <param name="paramters">Optional request paramaters <see cref="OptionalParamters"/>.</param>
        /// <returns>A climacell <see cref="Hourly"/> response.</returns>
        public async Task <Hourly> GetHourly(double latitude, double longitude, List <string> fields, OptionalParamters paramters = null)
        {
            if (fields.Count <= 0)
            {
                throw new ArgumentException($"{nameof(fields)} cannot be empty.");
            }

            var query    = BuildRequestUri(latitude, longitude, fields, paramters, Endpoint.Hourly);
            var response = await httpClient.HttpRequestAsync($"{baseUri}{query}").ConfigureAwait(false);

            return(await Hourly.Deserialize(response, jsonSerializerService));
        }
Beispiel #2
0
        /// <summary>
        ///     Attempts to initalize a new <see cref="Hourly"/> from the responding <see cref="HttpResponseMessage"/>, and deserializes the response content
        ///     using the <see cref="IJsonSerializerService"/> defined in the calling <see cref="ClimaCellService"/> instance and appends all model objects into the <see cref="ForecastResponse{T}.DataPoints"/> collection.
        /// </summary>
        public static new async Task <Hourly> Deserialize(HttpResponseMessage responseMessage, IJsonSerializerService jsonSerializerService)
        {
            Hourly h = new Hourly()
            {
                Response = new ClimaCellResponse(responseMessage)
            };

            try
            {
                h._dataPoints = await jsonSerializerService.DeserializeJsonAsync <List <Hourly.Model> >(responseMessage.Content?.ReadAsStringAsync()).ConfigureAwait(false);
            }
            catch (FormatException e)
            {
                h.Response.IsSuccessStatus = false;
                h.Response.ReasonPhrase    = $"Error parsing results: {e?.InnerException?.Message ?? e.Message}";
            }
            return(h);
        }