public async Task <TheCat> GetRandomCatAsync()
        {
            var cat = new TheCat();

            try
            {
                using (HttpClient client = new HttpClient())
                {
                    var response = await client.GetStringAsync(APIUrl);

                    var respObject = JArray.Parse(response);

                    foreach (var catObj in respObject)
                    {
                        cat.URL    = (string)catObj["url"];
                        cat.Width  = (int)catObj["width"];
                        cat.Height = (int)catObj["height"];
                    }
                }
            }
            catch
            {
                cat = new TheCat()
                {
                    URL = "https://geek.hellyer.kiwi/files/2017/06/cat-404.jpg", Width = 625, Height = 416
                };
            }

            return(cat);
        }
Exemple #2
0
        public ActionResult SalvarTheCat([FromBody] Gato_Descoberto dto)
        {
            var theCat = new TheCat(dto.DataDescoberta, dto.Sexo, dto.Latitude, dto.Longitude);

            _TheCatsCollection.InsertOne(theCat);

            return(StatusCode(201, "TheCat adicionado com sucesso"));
        }