diff --git a/src/SendGrid/ISendGridClient.cs b/src/SendGrid/ISendGridClient.cs new file mode 100644 index 000000000..8dfdfd318 --- /dev/null +++ b/src/SendGrid/ISendGridClient.cs @@ -0,0 +1,75 @@ +// +// Copyright (c) SendGrid. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +using System; + +namespace SendGrid +{ + using System.Collections.Generic; + using System.Net.Http; + using System.Net.Http.Headers; + using System.Threading; + using System.Threading.Tasks; + using Helpers.Mail; + + /// + /// A HTTP client wrapper for interacting with SendGrid's API + /// + public interface ISendGridClient + { + /// + /// Gets or sets the path to the API resource. + /// + string UrlPath { get; set; } + + /// + /// Gets or sets the API version. + /// + string Version { get; set; } + + /// + /// Gets or sets the request media type. + /// + string MediaType { get; set; } + + /// + /// Add the authorization header, override to customize + /// + /// Authorization header + /// Authorization value to add to the header + AuthenticationHeaderValue AddAuthorization( KeyValuePair header ); + + /// + /// Make the call to the API server, override for testing or customization + /// + /// The parameters for the API call + /// Cancel the asynchronous call + /// Response object + Task MakeRequest( HttpRequestMessage request, CancellationToken cancellationToken = default( CancellationToken ) ); + + /// + /// Prepare for async call to the API server + /// + /// HTTP verb + /// JSON formatted string + /// JSON formatted query paramaters + /// The path to the API endpoint. + /// Cancel the asynchronous call. + /// Response object + /// The method will NOT catch and swallow exceptions generated by sending a request + /// through the internal http client. Any underlying exception will pass right through. + /// In particular, this means that you may expect + /// a TimeoutException if you are not connected to the internet. + Task RequestAsync( SendGridClient.Method method, string requestBody = null, string queryParams = null, string urlPath = null, CancellationToken cancellationToken = default( CancellationToken ) ); + + /// + /// Make a request to send an email through SendGrid asychronously. + /// + /// A SendGridMessage object with the details for the request. + /// Cancel the asychronous call. + /// A Response object. + Task SendEmailAsync( SendGridMessage msg, CancellationToken cancellationToken = default( CancellationToken ) ); + } +} \ No newline at end of file diff --git a/src/SendGrid/SendGridClient.cs b/src/SendGrid/SendGridClient.cs index cd75b8278..114dc6dec 100644 --- a/src/SendGrid/SendGridClient.cs +++ b/src/SendGrid/SendGridClient.cs @@ -20,8 +20,8 @@ namespace SendGrid /// /// A HTTP client wrapper for interacting with SendGrid's API /// - public class SendGridClient - { + public class SendGridClient : ISendGridClient + { /// /// Gets or sets the path to the API resource. ///