@@ -24,11 +24,10 @@ namespace SendGrid
2424 public class SendGridClient
2525 {
2626 private readonly string version ;
27- //private readonly string urlPath;
27+ // private readonly string urlPath;
2828 private readonly string mediaType ;
2929 private HttpClient client ;
3030
31-
3231 /// <summary>
3332 /// Initializes a new instance of the <see cref="SendGridClient"/> class.
3433 /// </summary>
@@ -45,8 +44,7 @@ public SendGridClient(IWebProxy webProxy, string apiKey, string host = null, Dic
4544 var baseAddress = host ?? "https://api.sendgrid.com" ;
4645 var clientVersion = GetType ( ) . GetTypeInfo ( ) . Assembly . GetName ( ) . Version . ToString ( ) ;
4746
48-
49- //var servicePoint = ServicePointManager.FindServicePoint()
47+ // var servicePoint = ServicePointManager.FindServicePoint()
5048
5149 // Add the WebProxy if set
5250 if ( webProxy != null )
@@ -61,20 +59,20 @@ public SendGridClient(IWebProxy webProxy, string apiKey, string host = null, Dic
6159 }
6260 else
6361 {
64- client = new HttpClient ( ) ;
62+ client = new HttpClient ( ) ;
6563 }
6664
6765 // standard headers
6866 client . BaseAddress = new Uri ( baseAddress ) ;
6967 Dictionary < string , string > headers = new Dictionary < string , string >
7068 {
71- { "Authorization" , "Bearer " + apiKey } ,
72- { "Content-Type" , "application/json" } ,
73- { "User-Agent" , "sendgrid/" + clientVersion + " csharp" } ,
74- { "Accept" , "application/json" }
69+ { "Authorization" , "Bearer " + apiKey } ,
70+ { "Content-Type" , "application/json" } ,
71+ { "User-Agent" , "sendgrid/" + clientVersion + " csharp" } ,
72+ { "Accept" , "application/json" }
7573 } ;
7674
77- // set header overrides
75+ // set header overrides
7876 if ( requestHeaders != null )
7977 {
8078 foreach ( var header in requestHeaders )
@@ -111,7 +109,7 @@ public SendGridClient(IWebProxy webProxy, string apiKey, string host = null, Dic
111109 /// <param name="requestHeaders">A dictionary of request headers</param>
112110 /// <param name="version">API version, override AddVersion to customize</param>
113111 /// <returns>Interface to the SendGrid REST API</returns>
114- public SendGridClient ( string apiKey , string host = null , Dictionary < string , string > requestHeaders = null , string version = "v3" )
112+ public SendGridClient ( string apiKey , string host = null , Dictionary < string , string > requestHeaders = null , string version = "v3" )
115113 : this ( null , apiKey , host , requestHeaders , version )
116114 {
117115 }
@@ -164,7 +162,7 @@ public virtual AuthenticationHeaderValue AddAuthorization(KeyValuePair<string, s
164162 /// <param name="request">The parameters for the API call</param>
165163 /// <param name="cancellationToken">Cancel the asynchronous call</param>
166164 /// <returns>Response object</returns>
167- private async Task < Response > MakeRequest ( HttpRequestMessage request , CancellationToken cancellationToken = default ( CancellationToken ) )
165+ public async Task < Response > MakeRequest ( HttpRequestMessage request , CancellationToken cancellationToken = default ( CancellationToken ) )
168166 {
169167 HttpResponseMessage response = await client . SendAsync ( request , cancellationToken ) ;
170168 return new Response ( response . StatusCode , response . Content , response . Headers ) ;
@@ -188,7 +186,7 @@ public async Task<Response> RequestAsync(
188186 {
189187 try
190188 {
191- var endpoint = BuildUrl ( urlPath , queryParams ) ;
189+ var endpoint = client . BaseAddress + BuildUrl ( urlPath , queryParams ) ;
192190 // Build the request body
193191 StringContent content = null ;
194192 if ( requestBody != null )
@@ -222,10 +220,11 @@ public async Task<Response> RequestAsync(
222220 /// <returns>A Response object.</returns>
223221 public async Task < Response > SendEmailAsync ( SendGridMessage msg , CancellationToken cancellationToken = default ( CancellationToken ) )
224222 {
225- return await this . RequestAsync ( Method . POST ,
223+ return await this . RequestAsync (
224+ Method . POST ,
226225 msg . Serialize ( ) ,
227226 urlPath : "mail/send" ,
228- cancellationToken : cancellationToken ) . ConfigureAwait ( false ) ;
227+ cancellationToken : cancellationToken ) ;
229228 }
230229
231230 /// <summary>
@@ -242,11 +241,11 @@ private string BuildUrl(string urlPath, string queryParams = null)
242241
243242 if ( version != null )
244243 {
245- url = "/" + version + "/" + urlPath ;
244+ url = version + "/" + urlPath ;
246245 }
247246 else
248247 {
249- url = "/" + urlPath ;
248+ url = urlPath ;
250249 }
251250
252251 if ( queryParams != null )
0 commit comments