@@ -29,19 +29,24 @@ namespace SocketLabs.InjectionApi
2929 /// }
3030 ///</code>
3131 /// </example>
32- public class SocketLabsClient : ISocketLabsClient , IDisposable
32+ public class SocketLabsClient : ISocketLabsClient , IDisposable
3333 {
3434 private string UserAgent { get ; } = $ "SocketLabs-csharp/{ typeof ( SocketLabsClient ) . GetTypeInfo ( ) . Assembly . GetName ( ) . Version } ";
3535
3636 private readonly int _serverId ;
3737 private readonly string _apiKey ;
3838 private readonly HttpClient _httpClient ;
39-
39+
4040 /// <summary>
4141 /// The SocketLabs Injection API endpoint Url
4242 /// </summary>
4343 public string EndpointUrl { get ; set ; } = "https://inject.socketlabs.com/api/v1/email" ;
4444
45+ /// <summary>
46+ /// A timeout period for the Injection API request (in Seconds). Default: 120s
47+ /// </summary>
48+ public int RequestTimeout { get ; set ; } = 120 ;
49+
4550 /// <summary>
4651 /// Creates a new instance of the <c>SocketLabsClient</c>.
4752 /// </summary>
@@ -53,18 +58,19 @@ public SocketLabsClient(int serverId, string apiKey)
5358 _apiKey = apiKey ;
5459 _httpClient = BuildHttpClient ( null ) ;
5560 }
56-
61+
5762 /// <summary>
5863 /// Creates a new instance of the <c>SocketLabsClient</c> with a proxy.
5964 /// </summary>
6065 /// <param name="serverId">Your SocketLabs ServerId number.</param>
6166 /// <param name="apiKey">Your SocketLabs Injection API key.</param>
6267 /// <param name="optionalProxy">The WebProxy you would like to use.</param>
63- public SocketLabsClient ( int serverId , string apiKey , IWebProxy optionalProxy )
68+ public SocketLabsClient ( int serverId , string apiKey , IWebProxy optionalProxy )
6469 {
6570 _serverId = serverId ;
6671 _apiKey = apiKey ;
6772 _httpClient = BuildHttpClient ( optionalProxy ) ;
73+
6874 }
6975
7076 /// <summary>
@@ -84,7 +90,7 @@ public SocketLabsClient(int serverId, string apiKey, HttpClient httpClient)
8490
8591 private HttpClient BuildHttpClient ( IWebProxy optionalProxy )
8692 {
87- var httpClient = optionalProxy != null ? new HttpClient ( new HttpClientHandler ( ) { UseProxy = true , Proxy = optionalProxy } ) : new HttpClient ( ) ;
93+ var httpClient = optionalProxy != null ? new HttpClient ( new HttpClientHandler ( ) { UseProxy = true , Proxy = optionalProxy } ) : new HttpClient ( ) ;
8894 ConfigureHttpClient ( httpClient ) ;
8995 return httpClient ;
9096 }
@@ -216,20 +222,21 @@ public async Task<SendResponse> SendAsync(IBasicMessage message)
216222
217223 var validationResult = validator . ValidateCredentials ( _serverId , _apiKey ) ;
218224 if ( validationResult . Result != SendResult . Success ) return validationResult ;
219-
225+
220226 validationResult = validator . ValidateMessage ( message ) ;
221227 if ( validationResult . Result != SendResult . Success ) return validationResult ;
222228
223229 var factory = new InjectionRequestFactory ( _serverId , _apiKey ) ;
224230 var injectionRequest = factory . GenerateRequest ( message ) ;
225231 var json = injectionRequest . GetAsJson ( ) ;
226232
227- var httpResponse = await _httpClient . PostAsync ( EndpointUrl , json ) ;
233+ _httpClient . Timeout = TimeSpan . FromSeconds ( RequestTimeout ) ;
234+ var httpResponse = await _httpClient . PostAsync ( EndpointUrl , json ) ;
228235
229236 var response = new InjectionResponseParser ( ) . Parse ( httpResponse ) ;
230237 return response ;
231238 }
232-
239+
233240 /// <summary>
234241 /// Asynchronously sends a bulk email message and returns the response from the Injection API.
235242 /// </summary>
@@ -274,6 +281,7 @@ public async Task<SendResponse> SendAsync(IBulkMessage message)
274281 var factory = new InjectionRequestFactory ( _serverId , _apiKey ) ;
275282 var injectionRequest = factory . GenerateRequest ( message ) ;
276283
284+ _httpClient . Timeout = TimeSpan . FromSeconds ( RequestTimeout ) ;
277285 var httpResponse = await _httpClient . PostAsync ( EndpointUrl , injectionRequest . GetAsJson ( ) ) ;
278286
279287 var response = new InjectionResponseParser ( ) . Parse ( httpResponse ) ;
0 commit comments