예제 #1
0
        public static async Task <List <String> > GetImageUrl(string breed, int number = 1)
        {
            /// TODO : GetImageUrl()
            /// TODO : Compléter le modèle manquant
            ///

            string url;

            url = $"https://dog.ceo/api/breed/{breed}/images/random/{number}";


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

                    return(result.Dogs);
                }
                else
                {
                    throw new Exception(response.ReasonPhrase);
                }
            }
        }
예제 #2
0
        public static async Task <string> GetImageUrl(string breed)
        {
            string url = $"https://dog.ceo/api/breed/{breed}/images/random";

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

                    return(res.message);
                }
                else
                {
                    throw new Exception(response.ReasonPhrase);
                }
            }
        }
예제 #3
0
        public static async Task <List <DogModel> > LoadBreedList()
        {
            ///TODO : À compléter LoadBreedList
            /// Attention le type de retour n'est pas nécessairement bon
            /// J'ai mis quelque chose pour avoir une base
            /// TODO : Compléter le modèle manquant
            ///


            string url;

            url = $"https://dog.ceo/api/breeds/list/all";

            using (HttpResponseMessage response = await ApiHelper.ApiClient.GetAsync(url))
            {
                if (response.IsSuccessStatusCode)
                {
                    List <DogModel> dog_model = new List <DogModel>();

                    RaceModel result = await response.Content.ReadAsAsync <RaceModel>();

                    var famile = result.Races.Keys.ToList();

                    foreach (var race in famile)
                    {
                        DogModel breed = new DogModel();
                        breed.Name = race;
                        dog_model.Add(breed);
                    }
                    return(dog_model);
                }
                else
                {
                    throw new Exception(response.ReasonPhrase);
                }
            }



            return(new List <DogModel>());
        }
예제 #4
0
        public static async Task <DogModel> GetImageUrl(string breed)
        {
            /// TODO : GetImageUrl()
            string url = $"https://dog.ceo/api/breed/" + breed + "/images/random";

            using (HttpResponseMessage response = await ApiHelper.ApiClient.GetAsync(url))
            {
                // Debug.WriteLine(response.Content.);
                if (response.IsSuccessStatusCode)
                {
                    var message = await response.Content.ReadAsStringAsync();

                    DogModel dogs = JsonConvert.DeserializeObject <DogModel>(message);
                    return(dogs);
                }
                else
                {
                    throw new Exception(response.ReasonPhrase);
                }
            }
        }
        public static async Task <List <string> > LoadBreedList()
        {
            ///TODO : À compléter LoadBreedList
            /// Attention le type de retour n'est pas nécessairement bon
            /// J'ai mis quelque chose pour avoir une base
            /// TODO : Compléter le modèle manquant

            string url = "https://dog.ceo/api/breeds/list";

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

                    Console.WriteLine(result);
                    return(result.Message);
                }
                else
                {
                    throw new Exception(response.ReasonPhrase);
                }
            }
        }