diff --git a/.editorconfig b/.editorconfig
new file mode 100644
index 0000000..d4eab18
--- /dev/null
+++ b/.editorconfig
@@ -0,0 +1,4 @@
+[*.cs]
+
+# Default severity for analyzer diagnostics with category 'Style'
+dotnet_analyzer_diagnostic.category-Style.severity = suggestion
diff --git a/Example Projects/dotNetCoreExample/Examples/Basic/BasicSendWithProxy.cs b/Example Projects/dotNetCoreExample/Examples/Basic/BasicSendWithProxy.cs
index f297ce0..b1e390a 100644
--- a/Example Projects/dotNetCoreExample/Examples/Basic/BasicSendWithProxy.cs
+++ b/Example Projects/dotNetCoreExample/Examples/Basic/BasicSendWithProxy.cs
@@ -8,7 +8,9 @@ public class BasicSendWithProxy : IExample
{
public SendResponse RunExample()
{
- var proxy = new WebProxy("http://localhost.:8888", false);
+ // var proxy = new WebProxy("http://localhost.:8888", false);
+
+ var proxy = new WebProxy("http://localhost:4433", false);
var client = new SocketLabsClient(ExampleConfig.ServerId, ExampleConfig.ApiKey, proxy)
{
@@ -25,6 +27,7 @@ public SendResponse RunExample()
message.ReplyTo.Email = "replyto@example.com";
message.To.Add("recipient1@example.com");
+ client.RequestTimeout = 50;
return client.Send(message);
}
}
diff --git a/Example Projects/dotNetCoreExample/Examples/ExampleConfig.cs b/Example Projects/dotNetCoreExample/Examples/ExampleConfig.cs
index d58c4d3..d5afb8c 100644
--- a/Example Projects/dotNetCoreExample/Examples/ExampleConfig.cs
+++ b/Example Projects/dotNetCoreExample/Examples/ExampleConfig.cs
@@ -1,13 +1,11 @@
-namespace dotNetCoreExample.Examples
+using System;
+namespace dotNetCoreExample.Examples
{
public static class ExampleConfig
{
- //public static int ServerId => Environment.GetEnvironmentVariable("SocketlabsServerId", EnvironmentVariableTarget.User);
- //public static string ApiKey => Environment.GetEnvironmentVariable("SocketlabsApiPassword", EnvironmentVariableTarget.User);
+ public static int ServerId => int.Parse(Environment.GetEnvironmentVariable("SocketlabsServerId", EnvironmentVariableTarget.User));
+ public static string ApiKey => Environment.GetEnvironmentVariable("SocketlabsApiPassword", EnvironmentVariableTarget.User);
public static string TargetApi = "https://inject.socketlabs.com/api/v1/email";
-
- public static int ServerId => 0; //your serverId
- public static string ApiKey => "your api key";
-
+
}
-}
+}
\ No newline at end of file
diff --git a/Example Projects/dotNetCoreExample/Program.cs b/Example Projects/dotNetCoreExample/Program.cs
index 3365842..10b3c87 100644
--- a/Example Projects/dotNetCoreExample/Program.cs
+++ b/Example Projects/dotNetCoreExample/Program.cs
@@ -26,7 +26,7 @@ public static void Main()
quit = selection.ToLower().Trim() == "quit";
if (quit)
continue;
-
+
var exampleClassName = GetExampleName(selection);
if(exampleClassName == null)
continue;
diff --git a/SocketLabs.sln b/SocketLabs.sln
index a12b4f9..df0a8bb 100644
--- a/SocketLabs.sln
+++ b/SocketLabs.sln
@@ -1,7 +1,7 @@
Microsoft Visual Studio Solution File, Format Version 12.00
-# Visual Studio 15
-VisualStudioVersion = 15.0.27703.2047
+# Visual Studio Version 16
+VisualStudioVersion = 16.0.30907.101
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SocketLabs.UnitTests", "test\SocketLabs.Test\SocketLabs.UnitTests.csproj", "{C6E1FF08-07E8-47A9-B04B-F2F91468F045}"
EndProject
@@ -11,6 +11,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "dotNetCoreExample", "Exampl
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SocketLabs", "src\SocketLabs\SocketLabs.csproj", "{5FE88690-970A-4B7C-A8E9-BD8FF42FA01B}"
EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{58D953F4-41BE-42B0-B3E6-9A6978A74630}"
+ ProjectSection(SolutionItems) = preProject
+ .editorconfig = .editorconfig
+ EndProjectSection
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
diff --git a/src/SocketLabs/InjectionApi/SendResponse.cs b/src/SocketLabs/InjectionApi/SendResponse.cs
index 3237bae..b9712dc 100644
--- a/src/SocketLabs/InjectionApi/SendResponse.cs
+++ b/src/SocketLabs/InjectionApi/SendResponse.cs
@@ -36,7 +36,7 @@ public string ResponseMessage
case SendResult.Timeout:
return "A timeout occurred sending the message";
-
+
case SendResult.Success:
return "Successful send of message";
diff --git a/src/SocketLabs/InjectionApi/SocketLabsClient.cs b/src/SocketLabs/InjectionApi/SocketLabsClient.cs
index 58196fb..2d34395 100644
--- a/src/SocketLabs/InjectionApi/SocketLabsClient.cs
+++ b/src/SocketLabs/InjectionApi/SocketLabsClient.cs
@@ -29,19 +29,24 @@ namespace SocketLabs.InjectionApi
/// }
///
///
- public class SocketLabsClient : ISocketLabsClient , IDisposable
+ public class SocketLabsClient : ISocketLabsClient, IDisposable
{
private string UserAgent { get; } = $"SocketLabs-csharp/{typeof(SocketLabsClient).GetTypeInfo().Assembly.GetName().Version}";
private readonly int _serverId;
private readonly string _apiKey;
private readonly HttpClient _httpClient;
-
+
///
/// The SocketLabs Injection API endpoint Url
///
public string EndpointUrl { get; set; } = "https://inject.socketlabs.com/api/v1/email";
+ ///
+ /// A timeout period for the Injection API request (in Seconds). Default: 120s
+ ///
+ public int RequestTimeout { get; set; } = 120;
+
///
/// Creates a new instance of the SocketLabsClient.
///
@@ -53,18 +58,19 @@ public SocketLabsClient(int serverId, string apiKey)
_apiKey = apiKey;
_httpClient = BuildHttpClient(null);
}
-
+
///
/// Creates a new instance of the SocketLabsClient with a proxy.
///
/// Your SocketLabs ServerId number.
/// Your SocketLabs Injection API key.
/// The WebProxy you would like to use.
- public SocketLabsClient(int serverId, string apiKey, IWebProxy optionalProxy)
+ public SocketLabsClient(int serverId, string apiKey, IWebProxy optionalProxy)
{
_serverId = serverId;
_apiKey = apiKey;
_httpClient = BuildHttpClient(optionalProxy);
+
}
///
@@ -84,7 +90,7 @@ public SocketLabsClient(int serverId, string apiKey, HttpClient httpClient)
private HttpClient BuildHttpClient(IWebProxy optionalProxy)
{
- var httpClient = optionalProxy != null ? new HttpClient(new HttpClientHandler() {UseProxy = true, Proxy = optionalProxy}) : new HttpClient();
+ var httpClient = optionalProxy != null ? new HttpClient(new HttpClientHandler() { UseProxy = true, Proxy = optionalProxy}) : new HttpClient();
ConfigureHttpClient(httpClient);
return httpClient;
}
@@ -216,7 +222,7 @@ public async Task SendAsync(IBasicMessage message)
var validationResult = validator.ValidateCredentials(_serverId, _apiKey);
if (validationResult.Result != SendResult.Success) return validationResult;
-
+
validationResult = validator.ValidateMessage(message);
if(validationResult.Result != SendResult.Success) return validationResult;
@@ -224,12 +230,13 @@ public async Task SendAsync(IBasicMessage message)
var injectionRequest = factory.GenerateRequest(message);
var json = injectionRequest.GetAsJson();
- var httpResponse = await _httpClient.PostAsync(EndpointUrl, json);
+ _httpClient.Timeout = TimeSpan.FromSeconds(RequestTimeout);
+ var httpResponse = await _httpClient.PostAsync(EndpointUrl,json);
var response = new InjectionResponseParser().Parse(httpResponse);
return response;
}
-
+
///
/// Asynchronously sends a bulk email message and returns the response from the Injection API.
///
@@ -274,6 +281,7 @@ public async Task SendAsync(IBulkMessage message)
var factory = new InjectionRequestFactory(_serverId, _apiKey);
var injectionRequest = factory.GenerateRequest(message);
+ _httpClient.Timeout = TimeSpan.FromSeconds(RequestTimeout);
var httpResponse = await _httpClient.PostAsync(EndpointUrl, injectionRequest.GetAsJson());
var response = new InjectionResponseParser().Parse(httpResponse);
diff --git a/test/SocketLabs.Test/SocketLabs.UnitTests.csproj b/test/SocketLabs.Test/SocketLabs.UnitTests.csproj
index ef0cbdb..81ee08c 100644
--- a/test/SocketLabs.Test/SocketLabs.UnitTests.csproj
+++ b/test/SocketLabs.Test/SocketLabs.UnitTests.csproj
@@ -40,7 +40,7 @@
true
false
-
+
..\..\packages\Castle.Core.4.3.1\lib\net45\Castle.Core.dll
@@ -70,6 +70,9 @@
+
+ .editorconfig
+