1
+ // <copyright file="SendGridClient.cs" company="SendGrid">
2
+ // Copyright (c) SendGrid. All rights reserved.
3
+ // Licensed under the MIT license. See LICENSE file in the project root for full license information.
4
+ // </copyright>
5
+
6
+ using System ;
7
+
8
+ namespace SendGrid
9
+ {
10
+ using System . Collections . Generic ;
11
+ using System . Net . Http ;
12
+ using System . Net . Http . Headers ;
13
+ using System . Threading ;
14
+ using System . Threading . Tasks ;
15
+ using Helpers . Mail ;
16
+
17
+ /// <summary>
18
+ /// A HTTP client wrapper for interacting with SendGrid's API
19
+ /// </summary>
20
+ public interface ISendGridClient
21
+ {
22
+ /// <summary>
23
+ /// Gets or sets the path to the API resource.
24
+ /// </summary>
25
+ string UrlPath { get ; set ; }
26
+
27
+ /// <summary>
28
+ /// Gets or sets the API version.
29
+ /// </summary>
30
+ string Version { get ; set ; }
31
+
32
+ /// <summary>
33
+ /// Gets or sets the request media type.
34
+ /// </summary>
35
+ string MediaType { get ; set ; }
36
+
37
+ /// <summary>
38
+ /// Add the authorization header, override to customize
39
+ /// </summary>
40
+ /// <param name="header">Authorization header</param>
41
+ /// <returns>Authorization value to add to the header</returns>
42
+ AuthenticationHeaderValue AddAuthorization ( KeyValuePair < string , string > header ) ;
43
+
44
+ /// <summary>
45
+ /// Make the call to the API server, override for testing or customization
46
+ /// </summary>
47
+ /// <param name="request">The parameters for the API call</param>
48
+ /// <param name="cancellationToken">Cancel the asynchronous call</param>
49
+ /// <returns>Response object</returns>
50
+ Task < Response > MakeRequest ( HttpRequestMessage request , CancellationToken cancellationToken = default ( CancellationToken ) ) ;
51
+
52
+ /// <summary>
53
+ /// Prepare for async call to the API server
54
+ /// </summary>
55
+ /// <param name="method">HTTP verb</param>
56
+ /// <param name="requestBody">JSON formatted string</param>
57
+ /// <param name="queryParams">JSON formatted query paramaters</param>
58
+ /// <param name="urlPath">The path to the API endpoint.</param>
59
+ /// <param name="cancellationToken">Cancel the asynchronous call.</param>
60
+ /// <returns>Response object</returns>
61
+ /// <exception cref="Exception">The method will NOT catch and swallow exceptions generated by sending a request
62
+ /// through the internal http client. Any underlying exception will pass right through.
63
+ /// In particular, this means that you may expect
64
+ /// a TimeoutException if you are not connected to the internet.</exception>
65
+ Task < Response > RequestAsync ( SendGridClient . Method method , string requestBody = null , string queryParams = null , string urlPath = null , CancellationToken cancellationToken = default ( CancellationToken ) ) ;
66
+
67
+ /// <summary>
68
+ /// Make a request to send an email through SendGrid asychronously.
69
+ /// </summary>
70
+ /// <param name="msg">A SendGridMessage object with the details for the request.</param>
71
+ /// <param name="cancellationToken">Cancel the asychronous call.</param>
72
+ /// <returns>A Response object.</returns>
73
+ Task < Response > SendEmailAsync ( SendGridMessage msg , CancellationToken cancellationToken = default ( CancellationToken ) ) ;
74
+ }
75
+ }
0 commit comments