private async Task <OWCurrentWeaterModel> doCurrentWeatherCall()
        {
            using (HttpResponseMessage response = await ApiHelper.ApiClient.GetAsync(longUrl))
            {
                if (response.IsSuccessStatusCode)
                {
                    OWCurrentWeaterModel result = await response.Content.ReadAsAsync <OWCurrentWeaterModel>();

                    return(result);
                }
                //error bubbling...
                //https://social.technet.microsoft.com/wiki/contents/articles/36836.exception-bubbling-in-c.aspx
                else if (response.StatusCode == System.Net.HttpStatusCode.Unauthorized)
                {
                    throw new Exception("invalid API key");
                }
                else if (response.StatusCode == System.Net.HttpStatusCode.NotFound)
                {
                    throw new Exception("City not found");
                }
                else if (String.IsNullOrEmpty(City))
                {
                    throw new Exception("Location/City is empty, please enter a City name");
                }
                return(null);
            }
        }
Пример #2
0
        private async Task <OWCurrentWeaterModel> doCurrentWeatherCall()
        {
            using (HttpResponseMessage response = await ApiHelper.ApiClient.GetAsync(longUrl))
            {
                if (response.IsSuccessStatusCode)
                {
                    OWCurrentWeaterModel result = await response.Content.ReadAsAsync <OWCurrentWeaterModel>();

                    return(result);
                }

                else if (response.StatusCode == System.Net.HttpStatusCode.Unauthorized)
                {
                    OWCurrentWeaterModel result = await response.Content.ReadAsAsync <OWCurrentWeaterModel>();

                    return(result);
                }

                else if (response.StatusCode == System.Net.HttpStatusCode.NotFound)
                {
                    OWCurrentWeaterModel result = await response.Content.ReadAsAsync <OWCurrentWeaterModel>();

                    return(result);
                }

                return(null);
            }
        }
        private async Task <OWCurrentWeaterModel> doCurrentWeatherCall()
        {
            using (HttpResponseMessage response = await ApiHelper.ApiClient.GetAsync(longUrl))
            {
                if (response.IsSuccessStatusCode)
                {
                    OWCurrentWeaterModel result = await response.Content.ReadAsAsync <OWCurrentWeaterModel>();

                    return(result);
                }
                else if (response.StatusCode == System.Net.HttpStatusCode.Unauthorized)
                {
                    throw new Exception("invalid API key");
                }
                else if (response.StatusCode == System.Net.HttpStatusCode.NotFound)
                {
                    throw new Exception("City not found");
                }
                else if (String.IsNullOrEmpty(City))
                {
                    throw new Exception("Location/City is empty, please enter a City name");
                }
                return(null);
            }
        }
        private async Task <OWCurrentWeaterModel> doCurrentWeatherCall()
        {
            if (ApiHelper.ApiClient != null)
            {
                if (ApiKey == null || ApiKey == String.Empty)
                {
                    String message = "ApiKey null ou vide";
                    Debug.WriteLine(message);
                    throw new ArgumentException(message);
                }
                else
                {
                    using (HttpResponseMessage response = await ApiHelper.ApiClient.GetAsync(longUrl))
                    {
                        if (response.IsSuccessStatusCode)
                        {
                            OWCurrentWeaterModel result = await response.Content.ReadAsAsync <OWCurrentWeaterModel>();

                            return(result);
                        }

                        return(null);
                    }
                }
            }
            else
            {
                String message = "API Helper Non initialized";
                Debug.WriteLine(message);
                throw new ArgumentException(message);
            }
        }
Пример #5
0
        private async Task <OWCurrentWeaterModel> doCurrentWeatherCall()
        {
            if (ApiHelper.ApiClient == null)
            {
                throw new ArgumentException("API Helper Client not initialized");
            }
            else
            {
                if (ApiKey == null || ApiKey == String.Empty)
                {
                    throw new ArgumentException("OWApiKey null or empty");
                }
                else
                {
                    using (HttpResponseMessage response = await ApiHelper.ApiClient.GetAsync(longUrl))
                    {
                        if (response.IsSuccessStatusCode)
                        {
                            OWCurrentWeaterModel result = await response.Content.ReadAsAsync <OWCurrentWeaterModel>();

                            return(result);
                        }
                        return(null);
                    }
                }
            }
        }
Пример #6
0
        private async Task <OWCurrentWeaterModel> doCurrentWeatherCall()
        {
            using (HttpResponseMessage response = await ApiHelper.ApiClient.GetAsync(longUrl))
            {
                OWCurrentWeaterModel result = await response.Content.ReadAsAsync <OWCurrentWeaterModel>();

                return(result);
            }
        }
Пример #7
0
        private async Task <OWCurrentWeaterModel> doCurrentWeatherCall()
        {
            using (HttpResponseMessage response = await ApiHelper.ApiClient.GetAsync(longUrl))
            {
                if (response == null)
                {
                    throw new ArgumentException("Le client http n'a pas été initialisé");
                }
                if (response.IsSuccessStatusCode)
                {
                    OWCurrentWeaterModel result = await response.Content.ReadAsAsync <OWCurrentWeaterModel>();

                    return(result);
                }

                return(null);
            }
        }
        private async Task <OWCurrentWeaterModel> doCurrentWeatherCall()
        {
            using (HttpResponseMessage response = await ApiHelper.ApiClient.GetAsync(longUrl))
            {
                if (response.IsSuccessStatusCode)
                {
                    OWCurrentWeaterModel result = await response.Content.ReadAsAsync <OWCurrentWeaterModel>();

                    return(result);
                }
                if (response.StatusCode.ToString() == "Unautorized")
                {
                    throw new Exception("Clé invalide");
                }
                else if (response.StatusCode.ToString() == "Not Found")
                {
                    throw new Exception("Ville introuvable");
                }
                return(null);
            }
        }
        private async Task <OWCurrentWeaterModel> doCurrentWeatherCall()
        {
            using (HttpResponseMessage response = await ApiHelper.ApiClient.GetAsync(longUrl))
            {
                if (response.IsSuccessStatusCode)
                {
                    OWCurrentWeaterModel result = await response.Content.ReadAsAsync <OWCurrentWeaterModel>();

                    return(result);
                }
                if (response.StatusCode.ToString() == "Unautorized")
                {
                    throw new Exception("La clé API est invalide");
                }
                else if (response.StatusCode.ToString() == "Not Found")
                {
                    throw new Exception("La ville entrée n'existe pas, vérifiez l'orthographe");
                }
                return(null);
            }
        }