Beispiel #1
0
        /// <summary>
        /// Validtes the comment asynchronous.
        /// </summary>
        /// <param name="comment">The comment.</param>
        /// <returns>
        ///   <c>Spam</c> when the comment is spam, <c>Ham</c> when the comment is Ham aor <c>Invalid</c> when an error occured.
        /// </returns>
        /// <exception cref="System.ArgumentException"> when the API key is not validated.</exception>
        public async Task<CommentCheck> CheckCommentAsync(AkismetComment comment)
        {
            if (!this.keyVerified)
            {
                throw new ArgumentException("The API key is not verified. Call first the VerifyKey method.");
            }

            var keyvalues = comment.CreateKeyValues();
            var client = this.CreateClient(true);
            var request = new HttpRequestMessage(HttpMethod.Post, AkismetUrls.ValidateComment);
            request.Content = new FormUrlEncodedContent(keyvalues);

            var response = await client.SendAsync(request);
            if (response.StatusCode == System.Net.HttpStatusCode.OK)
            {
                var responseString = await response.Content.ReadAsStringAsync();

                switch (responseString)
                {
                    case "true": return CommentCheck.Spam;
                    case "false": return CommentCheck.Ham;
                    // TODO-rro: save error message in Errors property.
                    case "invalid": return CommentCheck.Invalid;
                    default: return CommentCheck.Invalid;
                }
            }

            return CommentCheck.Invalid;
        }
Beispiel #2
0
        /// <summary>
        /// Submits the comment as the ham.
        /// </summary>
        /// <param name="comment">The comment.</param>
        /// <returns></returns>
        /// <exception cref="System.NotImplementedException"></exception>
        public async Task<bool> SubmitHamAsync(AkismetComment comment)
        {
            if (!this.keyVerified)
            {
                throw new ArgumentException("The API key is not verified. Call first the VerifyKey method.");
            }

            var keyvalues = comment.CreateKeyValues();
            var client = this.CreateClient(true);
            var request = new HttpRequestMessage(HttpMethod.Post, AkismetUrls.SubmitHam);
            request.Content = new FormUrlEncodedContent(keyvalues);

            var response = await client.SendAsync(request);
            if (response.StatusCode == System.Net.HttpStatusCode.OK)
            {
                var responseString = await response.Content.ReadAsStringAsync();
                // TODO-rro: handle error message.
                return responseString.Equals("Thanks for making the web a better place.");
            }

            // TODO-rro: handle error message.
            return false;
        }