Ejemplo n.º 1
0
        public static async Task <SunModel> LoadSunInformation()
        {
            string url = "https://api.sunrise-sunset.org/json?lat=41.49&lng=-75.53&date=today";

            //memory managment, clean up, dispose
            using (HttpResponseMessage response = await ApiHelper.ApiClinet.GetAsync(url))
            {
                if (response.IsSuccessStatusCode)
                {
                    SunResultModel result = await response.Content.ReadAsAsync <SunResultModel>();

                    return(result.Results);
                }
                else
                {
                    throw new Exception(response.ReasonPhrase);
                }
            }
        }
        public static async Task <SunModel> GetDayLengthSeconds(double lat, double lon, string date)
        {
            string url = "https://api.sunrise-sunset.org/json?lat=" + lat + "&lng=" + lon + "&date=" + date + "&formatted=0";


            using (HttpResponseMessage response = await client.GetAsync(url))
            {
                if (response.IsSuccessStatusCode)
                {
                    SunResultModel result = await response.Content.ReadAsAsync <SunResultModel>();

                    return(result.Results);
                }
                else
                {
                    throw new Exception(response.ReasonPhrase);
                }
            }
        }
Ejemplo n.º 3
0
        public static async Task <SunModel> LoadSunInfo(float latitude, float longitude)
        {
            string url;

            url = $"https://api.sunrise-sunset.org/json?lat={latitude}&lng={longitude}&date=today";


            using (HttpResponseMessage response = await ApiHelper.ApiClient.GetAsync(url))
            {
                if (response.IsSuccessStatusCode)
                {
                    SunResultModel sun = await response.Content.ReadAsAsync <SunResultModel>();

                    return(sun.Results);
                }
                else
                {
                    throw new Exception(response.ReasonPhrase);
                }
            }
        }