Image related actions.
Inheritance: EndpointBase, IImageEndpoint
Example #1
0
        public async Task UpdateImageAsync_WithImage_AreEqual(IImage actualImage)
        {
            var client = new ImgurClient(ClientId, ClientSecret);
            var endpoint = new ImageEndpoint(client);

            var expected = await endpoint.UpdateImageAsync(actualImage.DeleteHash, "Ti", "De");

            Assert.IsTrue(expected);
        }
Example #2
0
        public async Task DeleteImageAsync_WithImage_IsTrue(IImage actualImage)
        {
            var client = new ImgurClient(ClientId, ClientSecret);
            var endpoint = new ImageEndpoint(client);

            var expected = await endpoint.DeleteImageAsync(actualImage.DeleteHash);

            Assert.IsTrue(expected);
        }
        public async Task FavoriteImageAsync_WithIdNull_ThrowsArgumentNullException()
        {
            var client = new ImgurClient("123", "1234");
            var endpoint = new ImageEndpoint(client);

            var exception =
                await
                    Record.ExceptionAsync(
                        async () => await endpoint.FavoriteImageAsync(null).ConfigureAwait(false))
                        .ConfigureAwait(false);
            Assert.NotNull(exception);
            Assert.IsType<ArgumentNullException>(exception);
        }
        public async Task FavoriteImageAsync_WithImgurClient_IsFalse()
        {
            var mockUrl = "https://api.imgur.com/3/image/zVpyzhW/favorite";
            var mockResponse = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(MockImageEndpointResponses.Imgur.FavoriteImageFalse)
            };

            var client = new ImgurClient("123", "1234", MockOAuth2Token);
            var endpoint = new ImageEndpoint(client, new HttpClient(new MockHttpMessageHandler(mockUrl, mockResponse)));
            var favorited = await endpoint.FavoriteImageAsync("zVpyzhW").ConfigureAwait(false);

            Assert.False(favorited);
        }
        public async Task DeleteImageAsync_Equal()
        {
            var mockUrl = "https://api.imgur.com/3/image/123xyj";
            var mockResponse = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(MockImageEndpointResponses.Imgur.DeleteImage)
            };

            var client = new ImgurClient("123", "1234");
            var endpoint = new ImageEndpoint(client, new HttpClient(new MockHttpMessageHandler(mockUrl, mockResponse)));
            var deleted = await endpoint.DeleteImageAsync("123xyj").ConfigureAwait(false);

            Assert.Equal(true, deleted);
        }
Example #6
0
        public async Task UploadImageBinaryAsync_WithImage_AreEqual()
        {
            var client = new ImgurClient(ClientId, ClientSecret);
            var endpoint = new ImageEndpoint(client);

            var file = File.ReadAllBytes("banana.gif");
            var image = await endpoint.UploadImageBinaryAsync(file, null, "binary test title!", "binary test desc!");

            Assert.IsFalse(string.IsNullOrEmpty(image.Id));
            Assert.AreEqual("binary test title!", image.Title);
            Assert.AreEqual("binary test desc!", image.Description);

            await GetImageAsync_WithImage_AreEqual(image);
            await UpdateImageAsync_WithImage_AreEqual(image);
            await DeleteImageAsync_WithImage_IsTrue(image);
        }
Example #7
0
        public async Task UploadImageStreamAsync_WithImage_AreEqual()
        {
            var client = new ImgurClient(ClientId, ClientSecret);
            var endpoint = new ImageEndpoint(client);
            IImage image = null;

            using (var fs = new FileStream("banana.gif", FileMode.Open))
            {
                image = await endpoint.UploadImageStreamAsync(fs, null, "stream test title!", "stream test desc!");
            }

            Assert.IsFalse(string.IsNullOrEmpty(image.Id));
            Assert.AreEqual("stream test title!", image.Title);
            Assert.AreEqual("stream test desc!", image.Description);

            await GetImageAsync_WithImage_AreEqual(image);
            await UpdateImageAsync_WithImage_AreEqual(image);
            await DeleteImageAsync_WithImage_IsTrue(image);
        }
Example #8
0
        public async Task GetImageAsync_WithImage_AreEqual(IImage actualImage)
        {
            var client = new ImgurClient(ClientId, ClientSecret);
            var endpoint = new ImageEndpoint(client);

            var expectedImage = await endpoint.GetImageAsync(actualImage.Id);

            Assert.AreEqual(actualImage.Id, expectedImage.Id);
            Assert.AreEqual(actualImage.Title, expectedImage.Title);
            Assert.AreEqual(actualImage.Description, expectedImage.Description);
            Assert.AreEqual(actualImage.DateTime, expectedImage.DateTime);
            Assert.AreEqual(actualImage.Type, expectedImage.Type);
            Assert.AreEqual(actualImage.Animated, expectedImage.Animated);
            Assert.AreEqual(actualImage.Width, expectedImage.Width);
            Assert.AreEqual(actualImage.Height, expectedImage.Height);
            Assert.AreEqual(actualImage.Size, expectedImage.Size);
            Assert.AreEqual(actualImage.Link, expectedImage.Link);
            Assert.AreEqual(actualImage.Gifv, expectedImage.Gifv);
            Assert.AreEqual(actualImage.Mp4, expectedImage.Mp4);
            Assert.AreEqual(actualImage.Webm, expectedImage.Webm);
            Assert.AreEqual(actualImage.Looping, expectedImage.Looping);
            Assert.AreEqual(actualImage.Favorite, expectedImage.Favorite);
            Assert.AreEqual(actualImage.Nsfw, expectedImage.Nsfw);
        }
        public async Task UploadImageUrlAsync_Equal()
        {
            var mockUrl = "https://api.imgur.com/3/image";
            var mockResponse = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(MockImageEndpointResponses.Imgur.UploadImage)
            };

            var client = new ImgurClient("123", "1234");
            var endpoint = new ImageEndpoint(client, new HttpClient(new MockHttpMessageHandler(mockUrl, mockResponse)));
            var image = await endpoint.UploadImageUrlAsync("http://i.imgur.com/kiNOcUl.gif").ConfigureAwait(false);

            Assert.NotNull(image);
            Assert.Equal(true, image.Animated);
            Assert.Equal(0, image.Bandwidth);
            Assert.Equal(new DateTimeOffset(new DateTime(2015, 8, 23, 23, 43, 31, DateTimeKind.Utc)), image.DateTime);
            Assert.Equal("nGxOKC9ML6KyTWQ", image.DeleteHash);
            Assert.Equal("Description Test", image.Description);
            Assert.Equal(false, image.Favorite);
            Assert.Equal("http://i.imgur.com/kiNOcUl.gifv", image.Gifv);
            Assert.Equal(189, image.Height);
            Assert.Equal("kiNOcUl", image.Id);
            Assert.Equal("http://i.imgur.com/kiNOcUl.gif", image.Link);
            Assert.Equal(true, image.Looping);
            Assert.Equal("http://i.imgur.com/kiNOcUl.mp4", image.Mp4);
            Assert.Equal("", image.Name);
            Assert.Equal(null, image.Nsfw);
            Assert.Equal(null, image.Section);
            Assert.Equal(1038889, image.Size);
            Assert.Equal("Title Test", image.Title);
            Assert.Equal("image/gif", image.Type);
            Assert.Equal(0, image.Views);
            Assert.Equal(null, image.Vote);
            Assert.Equal(290, image.Width);
        }
        public async Task GetImageAsync_Equal()
        {
            var mockUrl = "https://api.imgur.com/3/image/zVpyzhW";
            var mockResponse = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(MockImageEndpointResponses.Imgur.GetImage)
            };

            var client = new ImgurClient("123", "1234");
            var endpoint = new ImageEndpoint(client, new HttpClient(new MockHttpMessageHandler(mockUrl, mockResponse)));
            var image = await endpoint.GetImageAsync("zVpyzhW").ConfigureAwait(false);

            Assert.NotNull(image);
            Assert.Equal("zVpyzhW", image.Id);
            Assert.Equal("Look Mom, it's Bambi!", image.Title);
            Assert.Equal(null, image.Description);
            Assert.Equal(new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddSeconds(1440259938), image.DateTime);
            Assert.Equal("image/gif", image.Type);
            Assert.Equal(true, image.Animated);
            Assert.Equal(426, image.Width);
            Assert.Equal(240, image.Height);
            Assert.Equal(26270273, image.Size);
            Assert.Equal(3185896, image.Views);
            Assert.InRange(image.Bandwidth, 1, long.MaxValue);
            Assert.Equal(VoteOption.Up, image.Vote);
            Assert.Equal(false, image.Favorite);
            Assert.Equal(false, image.Nsfw);
            Assert.Equal("Eyebleach", image.Section);
            Assert.Equal("http://i.imgur.com/zVpyzhW.gifv", image.Gifv);
            Assert.Equal("http://i.imgur.com/zVpyzhW.mp4", image.Mp4);
            Assert.Equal("http://i.imgur.com/zVpyzhWh.gif", image.Link);
            Assert.Equal(true, image.Looping);
            Assert.Equal(true, image.InGallery);
            Assert.Equal(595876, image.Mp4Size);
        }
        public async Task UpdateRateLimit_WithImgurClientHeadersAndFakeResponse_Equal()
        {
            var mockUrl = "https://api.imgur.com/3/image/zVpyzhW/favorite";
            var mockResponse = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(MockImageEndpointResponses.Imgur.FavoriteImageFalse)
            };

            mockResponse.Headers.TryAddWithoutValidation("X-RateLimit-ClientLimit", "123");
            mockResponse.Headers.TryAddWithoutValidation("X-RateLimit-ClientRemaining", "345");

            var client = new ImgurClient("123", "1234", MockOAuth2Token);
            var endpoint = new ImageEndpoint(client, new HttpClient(new MockHttpMessageHandler(mockUrl, mockResponse)));

            await endpoint.FavoriteImageAsync("zVpyzhW").ConfigureAwait(false);

            Assert.Equal(123, endpoint.ApiClient.RateLimit.ClientLimit);
            Assert.Equal(345, endpoint.ApiClient.RateLimit.ClientRemaining);

            mockResponse.Headers.Remove("X-RateLimit-ClientLimit");
            mockResponse.Headers.Remove("X-RateLimit-ClientRemaining");

            mockResponse.Headers.TryAddWithoutValidation("X-RateLimit-ClientLimit", "122");
            mockResponse.Headers.TryAddWithoutValidation("X-RateLimit-ClientRemaining", "344");

            await endpoint.FavoriteImageAsync("zVpyzhW").ConfigureAwait(false);

            Assert.Equal(122, endpoint.ApiClient.RateLimit.ClientLimit);
            Assert.Equal(344, endpoint.ApiClient.RateLimit.ClientRemaining);
        }
Example #12
0
        public async Task UploadImageUrlAsync_WithImage_AreEqual()
        {
            var client = new ImgurClient(ClientId, ClientSecret);
            var endpoint = new ImageEndpoint(client);

            var image =
                await
                    endpoint.UploadImageUrlAsync("http://i.imgur.com/Eg71tvs.gif", null, "url test title!",
                        "url test desc!");

            Assert.IsFalse(string.IsNullOrEmpty(image.Id));
            Assert.AreEqual("url test title!", image.Title);
            Assert.AreEqual("url test desc!", image.Description);

            await GetImageAsync_WithImage_AreEqual(image);
            await UpdateImageAsync_WithImage_AreEqual(image);
            await DeleteImageAsync_WithImage_IsTrue(image);
        }
Example #13
0
        public async Task RunImgUR()
        {
            Console.Write("Authentication ID > ");
            string ImgurAuthenticationID = Console.ReadLine();

            /*
             * Console.Write("Authentication Secret > ");
             * string ImgurAuthenticationSecret=Console.ReadLine();
             * Console.Write("OAuth Access Token > ");
             * string OAuthAccessToken=Console.ReadLine();
             */
            IApiClient ClientImgur = new AuthenticationImpl.ImgurClient(ImgurAuthenticationID);

            //IApiClient ClientImgurAuthenticated=new AuthenticationImpl.ImgurClient(ImgurAuthenticationID,ImgurAuthenticationSecret,new ModelsImpl.OAuth2Token(OAuthAccessToken,string.Empty,"bearer","77530931","wereleven",315360000));
            Imgur.LibraryEnhancements.AccountEndpointEnhanced AccountAPI = new Imgur.LibraryEnhancements.AccountEndpointEnhanced(ClientImgur);
            ImgurEndpoints.ImageEndpoint ImageAPI = new ImgurEndpoints.ImageEndpoint(ClientImgur);
            ImgurEndpoints.AlbumEndpoint AlbumAPI = new ImgurEndpoints.AlbumEndpoint(ClientImgur);
            //ImgurEndpoints.CommentEndpoint CommentAPIAuthenticated=new ImgurEndpoints.CommentEndpoint(ClientImgurAuthenticated);
            //ImgurEndpoints.OAuth2Endpoint OAuthAPI=new ImgurEndpoints.OAuth2Endpoint(ClientImgurAuthenticated);
            ImgurEndpoints.RateLimitEndpoint LimitAPI = new ImgurEndpoints.RateLimitEndpoint(ClientImgur);
            try{
                /*
                 * Kewl Cat Album ID: YYL69
                 * Kewl Cat Image ID: 2rzgptw
                 * Galcian Image ID: BWeb9EM
                 */
                Console.WriteLine("Initial connection...");
                IRateLimit RemainingUsage = await LimitAPI.GetRateLimitAsync();

                Console.WriteLine("Remaining API usage - {0} / {1}", RemainingUsage.ClientRemaining, RemainingUsage.ClientLimit);
                Console.WriteLine();

                /*
                 * Console.WriteLine("Refreshing OAuth Token...");
                 * Task<IOAuth2Token> wait=OAuthAPI.GetTokenByRefreshTokenAsync(ClientImgurAuthenticated.OAuth2Token.RefreshToken);
                 * IOAuth2Token RefreshedOAuthToken=await wait;
                 * ClientImgurAuthenticated.SetOAuth2Token(RefreshedOAuthToken);
                 * Console.WriteLine("ImgUR Account: {0} [{1}]",RefreshedOAuthToken.AccountUsername,RefreshedOAuthToken.AccountId);
                 * Console.WriteLine("Type: {0}",RefreshedOAuthToken.TokenType);
                 * Console.WriteLine("Token: {0}",RefreshedOAuthToken.AccessToken);
                 * Console.WriteLine("Refresh Token: {0}",RefreshedOAuthToken.RefreshToken);
                 * Console.WriteLine("Expires: {0} ({1} seconds)",RefreshedOAuthToken.ExpiresAt,RefreshedOAuthToken.ExpiresIn);
                 * Console.WriteLine();
                 */
                Console.WriteLine("Retrieving Account details...");
                //IAccount Account=await AccountAPI.GetAccountAsync(ImgurUser);
                IAccount Account = await AccountAPI.GetAccountAsync(ImgurUserID);

                Console.WriteLine("ID - {0}", Account.Id);
                Console.WriteLine("Username - {0}", Account.Url);
                Console.WriteLine("Created - {0}", Account.Created);
                Console.WriteLine("Notoriety - {0}", Account.Notoriety);
                Console.WriteLine("Reputation - {0}", Account.Reputation);
                Console.WriteLine("Bio - {0}", Account.Bio);
                Console.WriteLine();
                Console.WriteLine("Retrieving recent Comments...");
                IList <IComment> Comments = (await AccountAPI.GetCommentsAsync(ImgurUser, CommentSortOrder.Newest, 0)).ToList();
                byte             count    = 0;
                foreach (IComment Comment in Comments)
                {
                    if (++count > 3)
                    {
                        break;
                    }
                    DisplayComment(Comment);
                }
                Console.WriteLine("Retrieving recent Comment IDs...");
                IList <int> CommentIDs = (await AccountAPI.GetCommentIdsAsync(ImgurUser, CommentSortOrder.Newest, 0)).ToList();
                if (CommentIDs.Count > 0)
                {
                    Console.WriteLine("Recent Comments - " + string.Join(", ", CommentIDs));
                    Console.WriteLine();
                    Console.WriteLine("Retrieving most recent Comment ({0})...", CommentIDs[0]);
                    IComment Comment = await AccountAPI.GetCommentAsync(CommentIDs[0], ImgurUser);

                    DisplayComment(Comment);
                    string CommentImageID;
                    if (!Comment.OnAlbum)
                    {
                        CommentImageID = Comment.ImageId;
                    }
                    else
                    {
                        Console.WriteLine("Retrieving most recent Comment Album details ({0})...", Comment.ImageId);
                        IAlbum Album = await AlbumAPI.GetAlbumAsync(Comment.ImageId);

                        Console.WriteLine("ID - {0}", Album.Id);
                        Console.WriteLine("Title - {0}", Album.Title);
                        Console.WriteLine("URL - {0}", Album.Link);
                        Console.WriteLine("Owner Username if Album not anonymous - {0}", Album.AccountUrl);
                        Console.WriteLine("Cover Image ID - {0}", Album.Cover);
                        Console.WriteLine("Cover Image Dimensions - {0}x{1}", Album.CoverWidth, Album.CoverHeight);
                        Console.WriteLine("Total Images - {0}", Album.ImagesCount);
                        Console.WriteLine("In Gallery - {0}", Album.InGallery);
                        Console.WriteLine("Created - {0}", Album.DateTime);
                        Console.WriteLine("Views - {0}", Album.Views);
                        Console.WriteLine("Category - {0}", Album.Section);
                        Console.WriteLine("NSFW - {0}", Album.Nsfw);
                        Console.WriteLine("View Layout - {0}", Album.Layout);
                        Console.WriteLine("Description - {0}", Album.Description);
                        Console.WriteLine();
                        CommentImageID = Comment.AlbumCover;
                    }
                    Console.WriteLine("Retrieving most recent Comment Image details ({0})...", CommentImageID);
                    IImage Image = await ImageAPI.GetImageAsync(CommentImageID);

                    Console.WriteLine("ID - {0}", Image.Id);
                    Console.WriteLine("Title - {0}", Image.Title);
                    Console.WriteLine("URL - {0}", Image.Link);
                    Console.WriteLine("Filename - {0}", Image.Name);
                    Console.WriteLine("MIME - {0}", Image.Type);
                    Console.WriteLine("Size - {0}B", Image.Size);
                    Console.WriteLine("Dimensions - {0}x{1}", Image.Width, Image.Height);
                    Console.WriteLine("Uploaded - {0}", Image.DateTime);
                    Console.WriteLine("Views - {0}", Image.Views);
                    Console.WriteLine("Category - {0}", Image.Section);
                    Console.WriteLine("NSFW - {0}", Image.Nsfw);
                    Console.WriteLine("Animated - {0}", Image.Animated);
                    Console.WriteLine("Description - {0}", Image.Description);
                    Console.WriteLine();

                    /*
                     * Console.Write("Enter Comment to post, or blank to skip > ");
                     * string CommentReply=Console.ReadLine();
                     * if(!string.IsNullOrWhiteSpace(CommentReply)){
                     * int ReplyID=await CommentAPIAuthenticated.CreateReplyAsync(CommentReply,Comment.ImageId,Comment.Id.ToString("D"));
                     * Console.WriteLine("Created Comment ID - {0}",ReplyID);
                     * }
                     * Console.WriteLine();
                     */
                }
                else
                {
                    Console.WriteLine();
                }
            }catch (ImgurException Error) {
                Console.Error.WriteLine("Error: " + Error.Message);
            }
            Console.WriteLine("Remaining API usage - {0} / {1}", ClientImgur.RateLimit.ClientRemaining, ClientImgur.RateLimit.ClientLimit);
            Console.ReadKey(true);
        }