/// <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: save error message in Errors property. case "invalid": return(CommentCheck.Invalid); default: return(CommentCheck.Invalid); } } return(CommentCheck.Invalid); }
/// <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: handle error message. return(responseString.Equals("Thanks for making the web a better place.")); } // TODO: handle error message. return(false); }
/// <summary> /// Creates an <see cref="AkismetComment"/> object for the specified blog. /// </summary> /// <returns></returns> public AkismetComment CreateComment() { var comment = new AkismetComment(this.blog); return(comment); }