/// <summary>
        /// Initializes a new instance of the <see cref="CheckForSpamClientBase"/> class.
        /// </summary>
        /// <remarks>
        /// This constructor takes in all the dependencies to allow for 
        ///   dependency injection and unit testing. Seems like overkill, 
        ///   but it's worth it.
        /// </remarks>
        /// <param name="apiKey">
        /// The Akismet API key.
        /// </param>
        /// <param name="blogUrl">
        /// The root url of the blog.
        /// </param>
        /// <param name="httpClient">
        /// Client class used to make the underlying requests.
        /// </param>
        protected CheckForSpamClientBase(
            [NotNull] string apiKey,
            [NotNull] Uri blogUrl,
            [NotNull] HttpClient httpClient)
        {
            CodeContracts.VerifyNotNull(apiKey, "apiKey");
            CodeContracts.VerifyNotNull(blogUrl, "blogUrl");
            CodeContracts.VerifyNotNull(httpClient, "httpClient");

            this.apiKey = apiKey;
            this.rootUrl = blogUrl;
            this.httpClient = httpClient;

            this.SetServiceUrls();
        }
Esempio n. 2
0
        /// <summary>
        /// Reports the user as bot.
        /// </summary>
        /// <param name="ipAddress">The IP address.</param>
        /// <param name="emailAddress">The email address.</param>
        /// <param name="userName">Name of the user.</param>
        /// <returns>Returns If the report was successful or not</returns>
        public bool ReportUserAsBot(
            [CanBeNull] string ipAddress,
            [CanBeNull] string emailAddress,
            [CanBeNull] string userName)
        {
            var parameters = "username={0}&ip_addr={1}&email={2}&api_key={3}".FormatWith(
                userName,
                ipAddress,
                emailAddress,
                YafContext.Current.Get<YafBoardSettings>().StopForumSpamApiKey);

            var result = new HttpClient().PostRequest(
                new Uri("http://www.stopforumspam.com/add.php"),
                null,
                60 * 1000,
                parameters);

            return result.Contains("success");
        }