Exemple #1
0
        /// <summary>
        /// Vote a definiton to be up or down.
        /// </summary>
        /// <param name="defId">The definiton id of the... definiton.</param>
        /// <param name="direction">The direction, either Up or Down</param>
        /// <returns>When awaited, returns a <see cref="VoteResponse"/>.</returns>
        /// <exception cref="VoteException">
        /// When the <see cref="VoteResponse.Status"/> is <see cref="VoteStatus.Error"/>.
        /// </exception>
        public async Task <VoteResponse> VoteOnDefinition(int defId, VoteDirection direction)
        {
            CheckDefinitionId(defId);
            var lowered = direction.ToString().ToLower();
            var result  = await Rest.ExecuteAsync <VoteResponse>(new RestRequest($"vote?defid={defId}&direction={lowered}")).ConfigureAwait(false);

            if (result.Status == VoteStatus.Error)
            {
                throw new VoteException($"An error occured while sending the vote request, the definiton id ({defId}) is probably wrong.");
            }
            return(result);
        }
		/// <summary>
		/// Vote on a comment
		/// </summary>
		/// <param name="commentId">The Id of the comment</param>
		/// <param name="vote">The vote to give the comment</param>
		public async Task<ImgurResponse<Boolean>> VoteCommentAsync(Int64 commentId, VoteDirection vote)
		{
			if (ImgurClient.Authentication == null)
				throw new InvalidAuthenticationException("Authentication can not be null. Set it in the main Imgur class.");

			if (!(ImgurClient.Authentication is OAuth2Authentication))
				throw new InvalidAuthenticationException("You need to use OAuth2Authentication to call this Endpoint.");

			return
				await
					Request.SubmitImgurRequestAsync<Boolean>(Request.HttpMethod.Get, String.Format(CommentVoteUrl, commentId, vote.ToString().ToLowerInvariant()),
						ImgurClient.Authentication);
		}
Exemple #3
0
        /// <summary>
        /// Vote on a comment
        /// </summary>
        /// <param name="commentId">The Id of the comment</param>
        /// <param name="vote">The vote to give the comment</param>
        public async Task <ImgurResponse <Boolean> > VoteCommentAsync(Int64 commentId, VoteDirection vote)
        {
            if (ImgurClient.Authentication == null)
            {
                throw new InvalidAuthenticationException("Authentication can not be null. Set it in the main Imgur class.");
            }

            if (!(ImgurClient.Authentication is OAuth2Authentication))
            {
                throw new InvalidAuthenticationException("You need to use OAuth2Authentication to call this Endpoint.");
            }

            return
                (await
                 Request.SubmitImgurRequestAsync <Boolean>(Request.HttpMethod.Get, String.Format(CommentVoteUrl, commentId, vote.ToString().ToLowerInvariant()),
                                                           ImgurClient.Authentication));
        }
Exemple #4
0
        /// <summary>
        /// Vote for an item. Send the same value again to undo a vote.
        /// </summary>
        /// <param name="ident">The Id of the item to vote for</param>
        /// <param name="isAlbum">Flags declaring if the item is an album</param>
        /// <param name="vote">The vote to give</param>
        private async Task <ImgurResponse <Boolean> > VoteOnGalleryObjectAsync(string ident, bool isAlbum, VoteDirection vote)
        {
            if (ImgurClient.Authentication == null)
            {
                throw new InvalidAuthenticationException("Authentication can not be null. Set it in the main Imgur class.");
            }

            if (!(ImgurClient.Authentication is OAuth2Authentication))
            {
                throw new InvalidAuthenticationException("You need to use OAuth2Authentication to call this Endpoint.");
            }

            var endpoint = String.Format(isAlbum ? GalleryVoteAlbumUrl : GalleryVoteImageUrl, ident, vote.ToString().ToLowerInvariant());

            return
                (await
                 Request.SubmitImgurRequestAsync <Boolean>(Request.HttpMethod.Post, endpoint, ImgurClient.Authentication));
        }