public async Task <GetStatusImageResponse> GetStatusImageAsync(int statusCode, GetStatusImageOptions options = null, CancellationToken cancellationToken = default)
        {
            var httpStatusCode = HttpStatusCode.CreateFromCode(statusCode);

            var giphyClient = new GiphyApiClient(_httpClient, new GiphyApiClientSettings());


            var response = await giphyClient.SearchAsync(CreateSearchRequest(httpStatusCode, options), cancellationToken);

            GifResponse gif;

            if (options != null && options.UseRandomFromSet)
            {
                var rnd    = new Random();
                int number = rnd.Next(0, LimitForRandom);

                gif = response.Gifs.Skip(number).Take(1).Single();
            }
            else
            {
                gif = response.Gifs.SingleOrDefault();
            }


            var imageUrl = GetSmallestImage(gif);

            return(new GetStatusImageResponse
            {
                Code = httpStatusCode.Code,
                Name = httpStatusCode.Name,
                ImageUrl = imageUrl
            });
        }
Exemple #2
0
            public void WhenExists_ThenReturnsObject()
            {
                var result = HttpStatusCode.CreateFromCode(100);

                Assert.That(result.Code, Is.EqualTo(100));
                Assert.That(result.Name, Is.EqualTo("Continue"));
                Assert.That(result.Category.Code, Is.EqualTo(1));
            }
Exemple #3
0
 public void WhenDoesNotExist_ThenThrowException()
 {
     Assert.Throws <ArgumentException>(() => HttpStatusCode.CreateFromCode(999));
 }