예제 #1
0
        public async Task <Meme> GetMemeAsync()
        {
            var responce = await _worker.GetDeserializedAsync <Meme>(MEMES_PROVIDER_URL);

            // TODO: Add logging
            // if(responce.Exception != null)
            // {
            //     Logger.Log(responce.Exception);
            // }

            return(responce.DesirializedContent);
        }
예제 #2
0
        public async Task <Stream> GetCatPictureAsync()
        {
            var queryEndpoint = $"https://api.thecatapi.com/v1/images/search/?api_key={_config.Config.CatApiKey}";

            #region Expected json responce type

            /*
             *  Expected json responce type:
             *  [
             *  {
             *      "breeds": [],
             *      "id": "avh",
             *      "url": "https://cdn2.thecatapi.com/images/avh.jpg",
             *      "width": 500,
             *      "height": 313
             *  }
             *  ]
             */
            #endregion

            var type = new[]
            {
                new
                {
                    url = "",
                }
            };

            // get responce from an api, then go to picture page and get it

            var apiResponce = await _worker.GetDeserializedAsync(queryEndpoint, type);


            Stream result = null;
            if (apiResponce.HttpResponseMessage.IsSuccessStatusCode)
            {
                var imgStream = await(
                    await _worker.GetAsync(apiResponce.DesirializedContent.FirstOrDefault().url)
                    ).Content.ReadAsStreamAsync();

                result = imgStream;
            }

            return(result);
        }