Class used to make the actual HTTP requests.
Yeah, I know you're thinking this is overkill, but it makes it easier to write tests to have this layer of abstraction from the underlying Http request.
示例#1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="AkismetClient"/> 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>
        public AkismetClient(string apiKey, Uri blogUrl, HttpClient httpClient)
        {
            if(apiKey == null)
                throw new ArgumentNullException("The akismet Api Key must be specified");

            if (blogUrl == null)
                throw new ArgumentNullException("The blog's url must be specified");

            if (httpClient == null)
                throw new ArgumentNullException("Must supply an http client");

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

            SetServiceUrls();
        }
示例#2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="AkismetClient"/> 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>
        public AkismetClient(string apiKey, Uri blogUrl, HttpClient httpClient)
        {
            if(apiKey == null)
            {
                throw new ArgumentNullException("apiKey");
            }

            if(blogUrl == null)
            {
                throw new ArgumentNullException("blogUrl");
            }

            if(httpClient == null)
            {
                throw new ArgumentNullException("httpClient");
            }

            _apiKey = apiKey;
            BlogUrl = blogUrl;
            _httpClient = httpClient;
            Timeout = 5000; /* default */
            SetServiceUrls();
        }