GetImageAsync() public method

Get information about an image.
/// Thrown when a null reference is passed to a method that does not accept it as a /// valid argument. /// Thrown when an error is found in a response from an Imgur endpoint. Thrown when an error is found in a response from a Mashape endpoint.
public GetImageAsync ( string imageId ) : Task
imageId string The image id.
return Task
Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
        public async Task GetImageAsync_WithIdNull_ThrowsArgumentNullException()
        {
            var client = new ImgurClient("123", "1234");
            var endpoint = new ImageEndpoint(client);

            var exception =
                await
                    Record.ExceptionAsync(
                        async () => await endpoint.GetImageAsync(null).ConfigureAwait(false))
                        .ConfigureAwait(false);
            Assert.NotNull(exception);
            Assert.IsType<ArgumentNullException>(exception);
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
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);
        }