This class defines an Akismet's comment format.
示例#1
0
 /// <summary>
 /// This call is intended for the marking of false positives, things that were incorrectly marked as spam.
 /// </summary>
 /// <param name="comment">The input comment to be sent as ham.</param>
 /// <returns>True if the comment was successfully sent, false otherwise.</returns>
 public void SubmitHam(Comment comment)
 {
     // prepare pars for the request
     NameValueCollection pars = PreparePars(comment);
     if (null != pars)
     {
         PostRequest(String.Format("http://{0}.rest.akismet.com/1.1/submit-spam", m_key), pars);
     }
 }
示例#2
0
        /// <summary>
        /// Check if the input comment is valid or not.
        /// </summary>
        /// <param name="comment">The input comment to be checked.</param>
        /// <returns>True if the comment is valid, false otherwise.</returns>
        public Boolean IsSpam(Comment comment)
        {
            // prepare pars for the request
            NameValueCollection pars = PreparePars(comment);
            if (null != pars)
            {
                // extract result from the request
                return ExtractResult(PostRequest(String.Format("http://{0}.rest.akismet.com/1.1/comment-check", m_key), pars));
            }

            // return no spam
            return false;
        }
示例#3
0
        /// <summary>
        /// Prepare request parameters based on the input comment.
        /// </summary>
        /// <param name="comment">The input comment.</param>
        /// <returns>The prepared parameters if any.</returns>
        protected virtual NameValueCollection PreparePars(Comment comment)
        {
            // check the input parameters
            if ((null != comment) && (!comment.IsValid))
                return null;

            // initialize result
            NameValueCollection result = new NameValueCollection();

            // add required information
            result["blog"] = HttpUtility.UrlEncode(comment.blog);
            result["user_ip"] = HttpUtility.UrlEncode(comment.user_ip);
            result["user_agent"] = HttpUtility.UrlEncode(comment.user_agent);
            // add optional information
            result["referrer"] = String.IsNullOrEmpty(comment.referrer) ? String.Empty : HttpUtility.UrlEncode(comment.referrer);
            result["permalink"] = String.IsNullOrEmpty(comment.permalink) ? String.Empty : HttpUtility.UrlEncode(comment.permalink);
            result["comment_type"] = String.IsNullOrEmpty(comment.comment_type) ? String.Empty : HttpUtility.UrlEncode(comment.comment_type);
            result["comment_author"] = String.IsNullOrEmpty(comment.comment_author) ? String.Empty : HttpUtility.UrlEncode(comment.comment_author);
            result["comment_author_email"] = String.IsNullOrEmpty(comment.comment_author_email) ? String.Empty : HttpUtility.UrlEncode(comment.comment_author_email);
            result["comment_author_url"] = String.IsNullOrEmpty(comment.comment_author_url) ? String.Empty : HttpUtility.UrlEncode(comment.comment_author_url);
            result["comment_content"] = String.IsNullOrEmpty(comment.comment_content) ? String.Empty : HttpUtility.UrlEncode(comment.comment_content);

            // return result
            return result;
        }