Gets credit limit.
Inheritance: EndpointBase, IRateLimitEndpoint
        public async Task GetRateLimitAsync_Equal()
        {
            var mockUrl = "https://api.imgur.com/3/credits";
            var mockResponse = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(MockRateLimitEndpointResponses.GetRateLimit)
            };

            var httpClient = new HttpClient(new MockHttpMessageHandler(mockUrl, mockResponse));

            var client = new ImgurClient("123", "1234");
            var endpoint = new RateLimitEndpoint(client, httpClient);

            var rateLimit = await endpoint.GetRateLimitAsync().ConfigureAwait(false);

            Assert.NotNull(rateLimit);
            Assert.Equal(10500, rateLimit.ClientLimit);
            Assert.Equal(9500, rateLimit.ClientRemaining);
        }
        public async Task GetRateLimitAsync_AreEqual()
        {
            var fakeHttpMessageHandler = new FakeHttpMessageHandler();
            var fakeResponse = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(RateLimitEndpointResponses.RateLimitResponse)
            };

            fakeHttpMessageHandler.AddFakeResponse(new Uri("https://api.imgur.com/3/credits"), fakeResponse);

            var httpClient = new HttpClient(fakeHttpMessageHandler);

            var client = new ImgurClient("123", "1234");
            var endpoint = new RateLimitEndpoint(client, httpClient);

            var rateLimit = await endpoint.GetRateLimitAsync();

            Assert.IsNotNull(rateLimit);
            Assert.AreEqual(412, rateLimit.UserLimit);
            Assert.AreEqual(382, rateLimit.UserRemaining);
            Assert.AreEqual(10500, rateLimit.ClientLimit);
            Assert.AreEqual(9500, rateLimit.ClientRemaining);
        }
Example #3
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);
        }