Beispiel #1
0
        public virtual async Task <WeatherReturnCode> GetWeather(string postalCode)
        {
            WeatherReturnCode result = null;

            try
            {
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                var resultString = await client.GetStringAsync(RequestUrl(postalCode));

                result = WeatherReturnCode.FromJson(resultString);

                if (!result.CallSuccess)
                {
                    result.Success = false;
                }
                return(result);
            }
            catch (Exception e)
            {
                var code = WeatherReturnCode.GetFailedCode(e.Message);
                return(code);
            }
        }
Beispiel #2
0
 public static string ToJson(this WeatherReturnCode self) => JsonConvert.SerializeObject(self, WeatherSdk.Converter.Settings);