コード例 #1
0
        public static async Task<SunModel> LoadSunInformation()
        {
            string url = "https://api.sunrise-sunset.org/json?lat=48.5829980&lng=7.6954900&date=today";

            using (HttpResponseMessage response = await ApiHelper.ApiClient.GetAsync(url))
            {
                if (response.IsSuccessStatusCode)
                {
                    SunResultModel sunData = await response.Content.ReadAsAsync<SunResultModel>();
                    return sunData.Results;
                }
                else
                {
                    throw new Exception(response.ReasonPhrase);
                }
            }
        }
コード例 #2
0
        public static async Task <SunModel> LoadSunInformation()
        {
            string url = "http://api.sunrise-sunset.org/json?lat=52.18935&lng=-2.22001&date=today";

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

                    return(result.Results);
                }
                else
                {
                    throw new Exception(response.ReasonPhrase);
                }
            }
        }
        // basically a copy and paste from ComicProcessor
        // if you were doing it right, you'd make this generic <T> and pass in the URL


        //https://sunrise-sunset.org/api
        //https://api.sunrise-sunset.org/json?lat=36.7201600&lng=-4.4203400&date=today



        //https://api.sunrise-sunset.org/json?lat=44.928226&lng=--93.254294&date=today

        //44.988391
        //-93.450631



        //https://api.sunrise-sunset.org/json?lat=44.928226&lng=--93.254294&date=today

        //44.928226
        //-93.254294


        public static async Task <SunModel> LoadSunInformation()  // make it async so it doesn't lock up.  It might take a while to get the info
        {
            string url = "https://api.sunrise-sunset.org/json?lat=44.928226&lng=-93.254294&date=today";

            using (HttpResponseMessage response = await ApiHelper.ApiClient.GetAsync(url))                          // open new request and wait for response.
            {
                if (response.IsSuccessStatusCode)                                                                   // if succesful then.
                {
                    SunResultModel result = await response.Content.ReadAsAsync <SunResultModel>();                  // tries to map over the data to our model

                    return(result.Results);
                }
                else
                {
                    throw new Exception(response.ReasonPhrase);
                }
            }   // at end it will close out all thing related to this request.
        }
コード例 #4
0
        public static async Task <SunModel> LoadSunInformation()
        {
            //Latitude: -19.8157 Longitude: -43.9542
            string url = "https://api.sunrise-sunset.org/json?lat=-19.8157&lng=-43.9542&date=today";

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

                    return(result.Results);
                }
                else
                {
                    throw new Exception(response.ReasonPhrase);
                }
            }
        }
コード例 #5
0
        public static async Task <SunModel> LoadSunInformation()
        {
            string url = "https://api.sunrise-sunset.org/json?lat=44.024708&lng=-88.542618&date=today";

            //sharing the same api client as comic
            using (HttpResponseMessage response = await ApiHelper.ApiClient.GetAsync(url))
            {
                if (response.IsSuccessStatusCode)
                {
                    SunResultModel result = await response.Content.ReadAsAsync <SunResultModel>();

                    return(result.Results);
                }
                else
                {
                    throw new Exception(response.ReasonPhrase);
                }
            }
        }
コード例 #6
0
        public static async Task <SunModel> LoadSunInformation()
        {
            string url = "https://api.sunrise-sunset.org/json?lat=50.627600&lng=5.554730&date=today";

            // fais une req sur l'url et attend la réponse
            using (HttpResponseMessage response = await ApiHelper.ApiClient.GetAsync(url))
            {
                if (response.IsSuccessStatusCode)
                {
                    // map le json lu dans la req http dans le model
                    SunResultModel result = await response.Content.ReadAsAsync <SunResultModel>();

                    return(result.Results);
                }
                else
                {
                    throw new Exception(response.ReasonPhrase);
                }
            }
        }
コード例 #7
0
ファイル: SunProcessor.cs プロジェクト: Jasonnx1/DogAPI_MVVM
        public static async Task <SunModel> LoadSunInformation(double latitude = 46.7201600, double longitude = -72.4203400)
        {
            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 result = await response.Content.ReadAsAsync <SunResultModel>();

                    return(result.Results);
                }
                else
                {
                    throw new Exception(response.ReasonPhrase);
                }
            }
        }
コード例 #8
0
        public static async Task <SunModel> LoadSunInformation(int comicNumber = 0)
        {
            string url = "https://api.sunrise-sunset.org/json?lat=41.494804&lng=-75.536852&date=today";

            // this helps us dispose of things properly
            using (HttpResponseMessage response = await ApiHelper.ApiClient.GetAsync(url))
            {
                // when finished, it will close everything down related to "response"
                // because we dont want to leave ports open, and open up ports all the time

                if (response.IsSuccessStatusCode)
                {
                    SunResultModel results = await response.Content.ReadAsAsync <SunResultModel>(); // ReadAsAsync uses the NewtonSoft Json converter which will try and map to our model

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