@@ -29,19 +29,28 @@ namespace SocketLabs.InjectionApi
2929 /// }
3030 ///</code>
3131 /// </example>
32- public class SocketLabsClient : ISocketLabsClient , IDisposable
32+ public class SocketLabsClient : ISocketLabsClient , IDisposable
3333 {
34+
35+
3436 private string UserAgent { get ; } = $ "SocketLabs-csharp/{ typeof ( SocketLabsClient ) . GetTypeInfo ( ) . Assembly . GetName ( ) . Version } ";
3537
3638 private readonly int _serverId ;
3739 private readonly string _apiKey ;
3840 private readonly HttpClient _httpClient ;
39-
41+
4042 /// <summary>
4143 /// The SocketLabs Injection API endpoint Url
4244 /// </summary>
4345 public string EndpointUrl { get ; set ; } = "https://inject.socketlabs.com/api/v1/email" ;
4446
47+ /// <summary>
48+ /// A timeout occurred sending the message
49+ /// </summary>
50+
51+ public int RequestTimeout { get ; set ; } = 120 ;
52+
53+
4554 /// <summary>
4655 /// Creates a new instance of the <c>SocketLabsClient</c>.
4756 /// </summary>
@@ -54,18 +63,21 @@ public SocketLabsClient(int serverId, string apiKey)
5463 _httpClient = BuildHttpClient ( null ) ;
5564 }
5665
66+
5767 /// <summary>
5868 /// Creates a new instance of the <c>SocketLabsClient</c> with a proxy.
5969 /// </summary>
6070 /// <param name="serverId">Your SocketLabs ServerId number.</param>
6171 /// <param name="apiKey">Your SocketLabs Injection API key.</param>
6272 /// <param name="optionalProxy">The WebProxy you would like to use.</param>
73+ /* /// <param name="RequestTimeout">The RequestTimeout you would like to specify.</param> */
6374 public SocketLabsClient ( int serverId , string apiKey , IWebProxy optionalProxy )
6475 {
6576 _serverId = serverId ;
6677 _apiKey = apiKey ;
6778 _httpClient = BuildHttpClient ( optionalProxy ) ;
68- }
79+
80+ }
6981
7082 /// <summary>
7183 /// Creates a new instance of the <c>SocketLabsClient</c> with a provided HttpClient.
@@ -84,7 +96,8 @@ public SocketLabsClient(int serverId, string apiKey, HttpClient httpClient)
8496
8597 private HttpClient BuildHttpClient ( IWebProxy optionalProxy )
8698 {
87- var httpClient = optionalProxy != null ? new HttpClient ( new HttpClientHandler ( ) { UseProxy = true , Proxy = optionalProxy } ) : new HttpClient ( ) ;
99+ var httpClient = optionalProxy != null ? new HttpClient ( new HttpClientHandler ( ) { UseProxy = true , Proxy = optionalProxy } ) : new HttpClient ( ) ;
100+
88101 ConfigureHttpClient ( httpClient ) ;
89102 return httpClient ;
90103 }
@@ -217,19 +230,20 @@ public async Task<SendResponse> SendAsync(IBasicMessage message)
217230 var validationResult = validator . ValidateCredentials ( _serverId , _apiKey ) ;
218231 if ( validationResult . Result != SendResult . Success ) return validationResult ;
219232
233+
220234 validationResult = validator . ValidateMessage ( message ) ;
221235 if ( validationResult . Result != SendResult . Success ) return validationResult ;
222236
223237 var factory = new InjectionRequestFactory ( _serverId , _apiKey ) ;
224238 var injectionRequest = factory . GenerateRequest ( message ) ;
225239 var json = injectionRequest . GetAsJson ( ) ;
226-
227- var httpResponse = await _httpClient . PostAsync ( EndpointUrl , json ) ;
228-
240+ _httpClient . Timeout = TimeSpan . FromSeconds ( RequestTimeout ) ;
241+ var httpResponse = await _httpClient . PostAsync ( EndpointUrl , json ) ;
229242 var response = new InjectionResponseParser ( ) . Parse ( httpResponse ) ;
243+
230244 return response ;
231245 }
232-
246+
233247 /// <summary>
234248 /// Asynchronously sends a bulk email message and returns the response from the Injection API.
235249 /// </summary>
@@ -273,9 +287,8 @@ public async Task<SendResponse> SendAsync(IBulkMessage message)
273287
274288 var factory = new InjectionRequestFactory ( _serverId , _apiKey ) ;
275289 var injectionRequest = factory . GenerateRequest ( message ) ;
276-
290+ _httpClient . Timeout = TimeSpan . FromSeconds ( RequestTimeout ) ;
277291 var httpResponse = await _httpClient . PostAsync ( EndpointUrl , injectionRequest . GetAsJson ( ) ) ;
278-
279292 var response = new InjectionResponseParser ( ) . Parse ( httpResponse ) ;
280293 return response ;
281294 }
0 commit comments