Skip to content

Commit af60d5a

Browse files
code cleanup
1 parent 1b5b5c8 commit af60d5a

File tree

3 files changed

+12
-22
lines changed

3 files changed

+12
-22
lines changed

Example Projects/dotNetCoreExample/Examples/ExampleConfig.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,9 @@ namespace dotNetCoreExample.Examples
33
{
44
public static class ExampleConfig
55
{
6-
//public static int ServerId => Environment.GetEnvironmentVariable("SocketlabsServerId", EnvironmentVariableTarget.User);
7-
//public static string ApiKey => Environment.GetEnvironmentVariable("SocketlabsApiPassword", EnvironmentVariableTarget.User);
8-
public static string TargetApi = "https://inject.socketlabs.com/api/v1/email";
9-
106
public static int ServerId => int.Parse(Environment.GetEnvironmentVariable("SocketlabsServerId", EnvironmentVariableTarget.User));
117
public static string ApiKey => Environment.GetEnvironmentVariable("SocketlabsApiPassword", EnvironmentVariableTarget.User);
12-
13-
8+
public static string TargetApi = "https://inject.socketlabs.com/api/v1/email";
9+
1410
}
1511
}

src/SocketLabs/InjectionApi/SendResponse.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,7 @@ public string ResponseMessage
3636

3737
case SendResult.Timeout:
3838
return "A timeout occurred sending the message";
39-
40-
41-
39+
4240
case SendResult.Success:
4341
return "Successful send of message";
4442

src/SocketLabs/InjectionApi/SocketLabsClient.cs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ namespace SocketLabs.InjectionApi
3131
/// </example>
3232
public class SocketLabsClient : ISocketLabsClient, IDisposable
3333
{
34-
35-
3634
private string UserAgent { get; } = $"SocketLabs-csharp/{typeof(SocketLabsClient).GetTypeInfo().Assembly.GetName().Version}";
3735

3836
private readonly int _serverId;
@@ -45,12 +43,10 @@ public class SocketLabsClient : ISocketLabsClient, IDisposable
4543
public string EndpointUrl { get; set; } = "https://inject.socketlabs.com/api/v1/email";
4644

4745
/// <summary>
48-
/// A timeout occurred sending the message
46+
/// A timeout period for the Injection API request (in Seconds). Default: 120s
4947
/// </summary>
5048
public int RequestTimeout { get; set; } = 120;
51-
52-
53-
49+
5450
/// <summary>
5551
/// Creates a new instance of the <c>SocketLabsClient</c>.
5652
/// </summary>
@@ -62,8 +58,7 @@ public SocketLabsClient(int serverId, string apiKey)
6258
_apiKey = apiKey;
6359
_httpClient = BuildHttpClient(null);
6460
}
65-
66-
61+
6762
/// <summary>
6863
/// Creates a new instance of the <c>SocketLabsClient</c> with a proxy.
6964
/// </summary>
@@ -76,7 +71,7 @@ public SocketLabsClient(int serverId, string apiKey, IWebProxy optionalProxy)
7671
_apiKey = apiKey;
7772
_httpClient = BuildHttpClient(optionalProxy);
7873

79-
}
74+
}
8075

8176
/// <summary>
8277
/// Creates a new instance of the <c>SocketLabsClient</c> with a provided HttpClient.
@@ -96,7 +91,6 @@ public SocketLabsClient(int serverId, string apiKey, HttpClient httpClient)
9691
private HttpClient BuildHttpClient(IWebProxy optionalProxy)
9792
{
9893
var httpClient = optionalProxy != null ? new HttpClient(new HttpClientHandler() { UseProxy = true, Proxy = optionalProxy}) : new HttpClient();
99-
10094
ConfigureHttpClient(httpClient);
10195
return httpClient;
10296
}
@@ -228,18 +222,18 @@ public async Task<SendResponse> SendAsync(IBasicMessage message)
228222

229223
var validationResult = validator.ValidateCredentials(_serverId, _apiKey);
230224
if (validationResult.Result != SendResult.Success) return validationResult;
231-
232-
225+
233226
validationResult = validator.ValidateMessage(message);
234227
if(validationResult.Result != SendResult.Success) return validationResult;
235228

236229
var factory = new InjectionRequestFactory(_serverId, _apiKey);
237230
var injectionRequest = factory.GenerateRequest(message);
238231
var json = injectionRequest.GetAsJson();
232+
239233
_httpClient.Timeout = TimeSpan.FromSeconds(RequestTimeout);
240234
var httpResponse = await _httpClient.PostAsync(EndpointUrl,json);
241-
var response = new InjectionResponseParser().Parse(httpResponse);
242235

236+
var response = new InjectionResponseParser().Parse(httpResponse);
243237
return response;
244238
}
245239

@@ -286,8 +280,10 @@ public async Task<SendResponse> SendAsync(IBulkMessage message)
286280

287281
var factory = new InjectionRequestFactory(_serverId, _apiKey);
288282
var injectionRequest = factory.GenerateRequest(message);
283+
289284
_httpClient.Timeout = TimeSpan.FromSeconds(RequestTimeout);
290285
var httpResponse = await _httpClient.PostAsync(EndpointUrl, injectionRequest.GetAsJson());
286+
291287
var response = new InjectionResponseParser().Parse(httpResponse);
292288
return response;
293289
}

0 commit comments

Comments
 (0)