Album related actions.
Inheritance: EndpointBase, IAlbumEndpoint
        public async Task AddAlbumImagesAsync_WithIdNull_ThrowsArgumentNullException()
        {
            var client = new ImgurClient("123", "1234");
            var endpoint = new AlbumEndpoint(client);

            var exception =
                await
                    Record.ExceptionAsync(
                        async () => await endpoint.AddAlbumImagesAsync("12x5454", null).ConfigureAwait(false))
                        .ConfigureAwait(false);
            Assert.NotNull(exception);
            Assert.IsType<ArgumentNullException>(exception);
        }
        public async Task CreateAlbumAsync_Equal()
        {
            var mockResponse = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(MockAlbumEndpointResponses.Imgur.CreateAlbum)
            };

            var mockUrl = "https://api.imgur.com/3/album";
            var client = new ImgurClient("123", "1234");
            var endpoint = new AlbumEndpoint(client, new HttpClient(new MockHttpMessageHandler(mockUrl, mockResponse)));
            var album = await endpoint.CreateAlbumAsync().ConfigureAwait(false);

            Assert.NotNull(album);
            Assert.Equal("3gfxo", album.Id);
            Assert.Equal("iIFJnFpVbYOvzvv", album.DeleteHash);
        }
        public async Task AddAlbumImagesAsync_True()
        {
            var mockResponse = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(MockAlbumEndpointResponses.Imgur.AddAlbumImages)
            };

            var mockUrl = "https://api.imgur.com/3/album/12x5454/add";
            var client = new ImgurClient("123", "1234");
            var endpoint = new AlbumEndpoint(client, new HttpClient(new MockHttpMessageHandler(mockUrl, mockResponse)));

            var updated =
                await
                    endpoint.AddAlbumImagesAsync("12x5454", new List<string> {"AbcDef", "IrcDef"}).ConfigureAwait(false);

            Assert.True(updated);
        }
Beispiel #4
0
        public void ImgurSetup()
        {
            string imgID = Karuta.registry.GetString("imgur_id");
            string imgSec = Karuta.registry.GetString("imgur_secret");
            if (string.IsNullOrWhiteSpace(imgID) || string.IsNullOrWhiteSpace(imgSec))
            {
                Karuta.Write("Please enter Imgur API information:");
                imgID = Karuta.GetInput("Imgur API ID");
                imgSec = Karuta.GetInput("Imgur API Sec");
            }
            Karuta.Write("Connecting to imgur...");
            try
            {
                _imgurClient = new ImgurClient(imgID, imgSec);
                Karuta.Write(_imgurClient.RateLimit);
                albumEndpoint = new AlbumEndpoint(_imgurClient);
            }
            catch (Exception e)
            {
                Karuta.Write("Failed to connect");
                Karuta.Write(e.Message);
                _imgurClient = null;
            }

            Karuta.registry.SetValue("imgur_id", imgID);
            Karuta.registry.SetValue("imgur_secret", imgSec);
        }
        public async Task DeleteAlbumAsync_True()
        {
            var mockResponse = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(MockAlbumEndpointResponses.Imgur.DeleteAlbum)
            };

            var mockUrl = "https://api.imgur.com/3/album/12x5454";
            var client = new ImgurClient("123", "1234");
            var endpoint = new AlbumEndpoint(client, new HttpClient(new MockHttpMessageHandler(mockUrl, mockResponse)));
            var deleted = await endpoint.DeleteAlbumAsync("12x5454").ConfigureAwait(false);

            Assert.True(deleted);
        }
        public async Task GetAlbumImagesAsync_ImageCountTrue()
        {
            var mockUrl = "https://api.imgur.com/3/album/5F5Cy/images";
            var mockResponse = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(MockAlbumEndpointResponses.Imgur.GetAlbumImages)
            };

            var client = new ImgurClient("123", "1234");
            var endpoint = new AlbumEndpoint(client, new HttpClient(new MockHttpMessageHandler(mockUrl, mockResponse)));
            var images = await endpoint.GetAlbumImagesAsync("5F5Cy").ConfigureAwait(false);

            Assert.True(images.Count() == 3);
        }
        public async Task GetAlbumImageAsync_Equal()
        {
            var mockUrl = "https://api.imgur.com/3/album/5F5Cy/image/79MH23L";
            var mockResponse = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(MockAlbumEndpointResponses.Imgur.GetAlbumImage)
            };

            var client = new ImgurClient("123", "1234");
            var endpoint = new AlbumEndpoint(client, new HttpClient(new MockHttpMessageHandler(mockUrl, mockResponse)));
            var image = await endpoint.GetAlbumImageAsync("79MH23L", "5F5Cy").ConfigureAwait(false);

            Assert.NotNull(image);

            Assert.Equal("79MH23L", image.Id);
            Assert.Equal(null, image.Title);
            Assert.Equal(null, image.Description);
            Assert.Equal(image.DateTime, new DateTimeOffset(new DateTime(2015, 11, 3, 23, 03, 03, DateTimeKind.Utc)));
            Assert.Equal("image/png", image.Type);
            Assert.Equal(false, image.Animated);
            Assert.Equal(609, image.Width);
            Assert.Equal(738, image.Height);
            Assert.Equal(451530, image.Size);
            Assert.Equal(2849, image.Views);
            Assert.Equal(1286408970, image.Bandwidth);
            Assert.Equal(null, image.Vote);
            Assert.Equal(false, image.Favorite);
            Assert.Equal(null, image.Nsfw);
            Assert.Equal(null, image.Section);
            Assert.Equal("http://i.imgur.com/79MH23L.png", image.Link);
        }
        public async Task GetAlbumAsync_Equal()
        {
            var mockUrl = "https://api.imgur.com/3/album/5F5Cy";
            var mockResponse = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(MockAlbumEndpointResponses.Imgur.GetAlbum)
            };

            var client = new ImgurClient("123", "1234");
            var endpoint = new AlbumEndpoint(client, new HttpClient(new MockHttpMessageHandler(mockUrl, mockResponse)));
            var album = await endpoint.GetAlbumAsync("5F5Cy").ConfigureAwait(false);

            Assert.NotNull(album);
            Assert.Equal("5F5Cy", album.Id);
            Assert.Equal(null, album.Title);
            Assert.Equal(null, album.Description);
            Assert.Equal(album.DateTime, new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddSeconds(1446591779));
            Assert.Equal("79MH23L", album.Cover);
            Assert.Equal(609, album.CoverWidth);
            Assert.Equal(738, album.CoverHeight);
            Assert.Equal("sarah", album.AccountUrl);
            Assert.Equal(9571, album.AccountId);
            Assert.Equal(AlbumPrivacy.Public, album.Privacy);
            Assert.Equal(AlbumLayout.Blog, album.Layout);
            Assert.Equal(19, album.Views);
            Assert.Equal("http://imgur.com/a/5F5Cy", album.Link);
            Assert.Equal(false, album.Favorite);
            Assert.Equal(null, album.Nsfw);
            Assert.Equal(null, album.Section);
            Assert.Equal(3, album.ImagesCount);
            Assert.Equal(3, album.Images.Count());
            Assert.Equal(false, album.InGallery);
        }
        public async Task FavoriteAlbumAsync_WithMashapeClient_True()
        {
            var mockUrl = "https://imgur-apiv3.p.mashape.com/3/album/zVpyzhW/favorite";
            var mockResponse = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(MockAlbumEndpointResponses.Imgur.FavoriteAlbumTrue)
            };

            var client = new MashapeClient("123", "1234", "xyz", MockOAuth2Token);
            var endpoint = new AlbumEndpoint(client, new HttpClient(new MockHttpMessageHandler(mockUrl, mockResponse)));
            var favorited = await endpoint.FavoriteAlbumAsync("zVpyzhW").ConfigureAwait(false);

            Assert.True(favorited);
        }
        public async Task FavoriteAlbumAsync_WithIdNull_ThrowsArgumentNullException()
        {
            var client = new ImgurClient("123", "1234", MockOAuth2Token);
            var endpoint = new AlbumEndpoint(client);

            var exception =
                await
                    Record.ExceptionAsync(
                        async () => await endpoint.FavoriteAlbumAsync(null).ConfigureAwait(false))
                        .ConfigureAwait(false);
            Assert.NotNull(exception);
            Assert.IsType<ArgumentNullException>(exception);
        }
Beispiel #11
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);
        }