Exemplo n.º 1
0
        public async Task <List <CatFact> > RefreshDataAsync()
        {
            Facts = new List <CatFact>();



            try
            {
                for (int i = 0; i < 30; i++)
                {
                    var uri      = new Uri(string.Format((Constants.CatFactsUrl + i + '/'), string.Empty));
                    var response = await _client.GetAsync(uri);

                    Debug.WriteLine("XXXX: " + response.ToString());
                    if (response.IsSuccessStatusCode)
                    {
                        var content = await response.Content.ReadAsStringAsync();

                        Debug.WriteLine(content);
                        CatFact catFact = JsonConvert.DeserializeObject <CatFact>(content);
                        Debug.WriteLine(catFact);
                        Facts.Add(catFact);
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(@"\tERROR {0}", ex.Message);
            }

            return(Facts);
        }
Exemplo n.º 2
0
        public ItemDetailPage(CatFact fact)
        {
            InitializeComponent();
            var viewModel = AppContainer.Container.Resolve <ItemDetailViewModel>();

            viewModel.Text = fact.Text;
            BindingContext = viewModel;
        }
        public async Task Execute(SocketUserMessage msg, SocketCommandContext context, IServiceProvider provider)
        {
            CatFact fact = await SimpleApiCall.Call <CatFact>("https://catfact.ninja/fact", provider);

            if (fact != null)
            {
                await context.Channel.SendMessageAsync(fact.fact);
            }
        }
Exemplo n.º 4
0
        public ActionResult <CatCard> GetRandomCard()
        {
            CatFact fact = catFactService.GetFact();
            CatPic  pic  = catPicService.GetPic();

            CatCard card = new CatCard()
            {
                CatFact = fact.Text,
                ImgUrl  = pic.File
            };

            return(card);
        }
Exemplo n.º 5
0
        protected override CustomListObjectElementCollection GetItemsOverride(CustomListData data)
        {
            Int32 maxLength = CheckAndGetMaxLengthProperty(data);

            CatFact myfact = GetRandomCatfact(maxLength).Result;

            var items = new CustomListObjectElementCollection();

            items.Add(new CustomListObjectElement {
                { "Fact", myfact.fact }, { "Length", myfact.length },
            });

            return(items);
        }
Exemplo n.º 6
0
        private async void OnItemSelected(CatFact fact)
        {
            if (fact == null)
            {
                return;
            }

            //Navigate
            var secondPage = new ItemDetailPage(fact);
            await Application.Current.MainPage.Navigation.PushAsync(secondPage);

            //Shell
            //await Shell.Current.GoToAsync($"catdetail?text={fact.Text}");
        }
Exemplo n.º 7
0
        public static async Task <CatFact> GetRandomCatfact(int MaxLength)
        {
            var request              = new HttpRequestMessage(HttpMethod.Get, string.Format("https://catfact.ninja/fact?max_length={0}", MaxLength));
            var httpHandler          = new HttpClientHandler();
            var httpClient           = new HttpClient(httpHandler);
            var responseUserTimeLine = await httpClient.SendAsync(request);

            //JObject dynobj = JObject.Parse(await responseUserTimeLine.Content.ReadAsStringAsync());
            //string myfact = dynobj["fact"].ToString();

            var     json   = Newtonsoft.Json.JsonConvert.DeserializeObject(await responseUserTimeLine.Content.ReadAsStringAsync());
            CatFact myfact = Newtonsoft.Json.JsonConvert.DeserializeObject <CatFact>(await responseUserTimeLine.Content.ReadAsStringAsync());

            return(myfact);
        }
Exemplo n.º 8
0
        public static CatFact GetCatFact()
        {
            string Uri = "https://cat-fact.herokuapp.com/facts/random";
            HttpResponseMessage response = new HttpResponseMessage();

            response = client.GetAsync(Uri).Result;

            if (response.IsSuccessStatusCode)
            {
                CatFact output = response.Content.ReadFromJsonAsync <CatFact>().Result;
                return(output);
            }
            else
            {
                throw new Exception("Application failed to access API at address: " + Uri);
            }
        }
Exemplo n.º 9
0
        public ActionResult <CatCard> CreateRandomCard()
        {
            CatCard c = new CatCard();

            CatPic  pic  = catPicService.GetPic();
            CatFact fact = catFactService.GetFact();

            //create pic and fact objects
            if (fact == null || pic == null)//fact or pic == null; status code 500
            {
                return(StatusCode(500));
            }
            c.CatFact = fact.Text;
            c.ImgUrl  = pic.File;

            return(Ok(c));
        }
Exemplo n.º 10
0
        public CatCard GetRandomCatCard()
        {
            CatFact fact = GetFact();
            CatPic  pic  = GetPic();

            if (fact == null || pic == null)
            {
                return(null);
            }

            CatCard card = new CatCard()
            {
                CatFact = fact.Text,
                ImgUrl  = pic.File
            };

            return(card);
        }
        public ActionResult <CatCard> GetRandomCatCard()
        {
            try
            {
                CatFact fact = catFactService.GetFact();
                CatPic  pic  = catPicService.GetPic();

                CatCard card = new CatCard()
                {
                    CatFact = fact.Text,
                    ImgUrl  = pic.File
                };

                return(Ok(card));
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
        public ActionResult <CatCard> GetRandomCard()
        {
            CatFactService serviceFact = new CatFactService();
            CatPicService  servicePic  = new CatPicService();

            CatCard card = new CatCard();

            CatFact fact = serviceFact.GetFact();
            CatPic  pic  = servicePic.GetPic();

            if (fact == null || pic == null)
            {
                return(StatusCode(500));
            }

            card.CatFact = fact.Text;
            card.ImgUrl  = pic.File;

            return(Ok(card));
        }
Exemplo n.º 13
0
        async void OnItemSelected(object sender, SelectedItemChangedEventArgs e)
        {
            CatFact catFact = (CatFact)e.SelectedItem;

            await DisplayAlert("Worthless Info", catFact.Name + ".", "OK");
        }
Exemplo n.º 14
0
 public void Setup()
 {
     catFact = new CatFact();
 }
Exemplo n.º 15
0
 public Task SaveTodoCatFactAsync(CatFact item, bool isNewItem)
 {
     throw new NotImplementedException();
 }