Imgur.API.Endpoints.Impl.CommentEndpoint.VoteCommentAsync C# (CSharp) Method

VoteCommentAsync() public method

Vote on a comment. OAuth authentication required.
/// 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 VoteCommentAsync ( int commentId, VoteOption vote ) : Task
commentId int The comment id.
vote VoteOption The vote.
return Task
        public async Task<bool> VoteCommentAsync(int commentId, VoteOption vote)
        {
            if (ApiClient.OAuth2Token == null)
                throw new ArgumentNullException(nameof(ApiClient.OAuth2Token), OAuth2RequiredExceptionMessage);

            var voteValue = $"{vote}".ToLower();
            var url = $"comment/{commentId}/vote/{voteValue}";

            using (var request = RequestBuilder.CreateRequest(HttpMethod.Post, url))
            {
                var voted = await SendRequestAsync<bool>(request).ConfigureAwait(false);
                return voted;
            }
        }
    }

Usage Example

        public async Task VoteCommentAsync_WithOAuth2TokenNull_ThrowsArgumentNullException()
        {
            var client = new ImgurClient("123", "1234");
            var endpoint = new CommentEndpoint(client);

            var exception =
                await
                    Record.ExceptionAsync(
                        async () => await endpoint.VoteCommentAsync(539556821, VoteOption.Down).ConfigureAwait(false))
                        .ConfigureAwait(false);
            Assert.NotNull(exception);
            Assert.IsType<ArgumentNullException>(exception);
        }
All Usage Examples Of Imgur.API.Endpoints.Impl.CommentEndpoint::VoteCommentAsync