Skip to content

Commit 29c5600

Browse files
committed
Merge branch 'release/0.114.0'
2 parents ee798b1 + 60df780 commit 29c5600

5 files changed

Lines changed: 37 additions & 26 deletions

File tree

Source/StrongGrid/BaseClient.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ public abstract class BaseClient : IBaseClient, IDisposable
1818
{
1919
#region FIELDS
2020

21-
private const string SENDGRID_V3_BASE_URI = "https://api.sendgrid.com/v3";
22-
2321
private static string _version;
2422

2523
private readonly bool _mustDisposeHttpClient;
@@ -278,10 +276,12 @@ public BaseClient(string apiKey, HttpClient httpClient, bool disposeClient, Stro
278276
{
279277
_mustDisposeHttpClient = disposeClient;
280278
_httpClient = httpClient;
281-
_options = options;
279+
_options = options ?? new StrongGridClientOptions();
282280
_logger = logger ?? NullLogger.Instance;
283281

284-
_fluentClient = new FluentClient(new Uri(SENDGRID_V3_BASE_URI), httpClient)
282+
if (_options.ApiEndPoint == null) throw new ArgumentNullException($"{nameof(options)}.{nameof(options.ApiEndPoint)}");
283+
284+
_fluentClient = new FluentClient(_options.ApiEndPoint, httpClient)
285285
.SetUserAgent($"StrongGrid/{Version} (+https://github.com/Jericho/StrongGrid)")
286286
.SetRequestCoordinator(new SendGridRetryStrategy());
287287

Source/StrongGrid/Client.cs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,6 @@ namespace StrongGrid
1111
/// </summary>
1212
public class Client : BaseClient, IClient
1313
{
14-
private static readonly StrongGridClientOptions _defaultOptions = new StrongGridClientOptions()
15-
{
16-
LogLevelSuccessfulCalls = LogLevel.Debug,
17-
LogLevelFailedCalls = LogLevel.Error
18-
};
19-
2014
#region PROPERTIES
2115

2216
/// <summary>
@@ -81,7 +75,7 @@ public class Client : BaseClient, IClient
8175
/// <param name="options">Options for the SendGrid client.</param>
8276
/// <param name="logger">Logger.</param>
8377
public Client(string apiKey, StrongGridClientOptions options = null, ILogger logger = null)
84-
: base(apiKey, null, false, options ?? _defaultOptions, logger)
78+
: base(apiKey, null, false, options, logger)
8579
{
8680
Init();
8781
}
@@ -94,7 +88,7 @@ public Client(string apiKey, StrongGridClientOptions options = null, ILogger log
9488
/// <param name="options">Options for the SendGrid client.</param>
9589
/// <param name="logger">Logger.</param>
9690
public Client(string apiKey, IWebProxy proxy, StrongGridClientOptions options = null, ILogger logger = null)
97-
: base(apiKey, new HttpClient(new HttpClientHandler { Proxy = proxy, UseProxy = proxy != null }), true, options ?? _defaultOptions, logger)
91+
: base(apiKey, new HttpClient(new HttpClientHandler { Proxy = proxy, UseProxy = proxy != null }), true, options, logger)
9892
{
9993
Init();
10094
}
@@ -107,7 +101,7 @@ public Client(string apiKey, IWebProxy proxy, StrongGridClientOptions options =
107101
/// <param name="options">Options for the SendGrid client.</param>
108102
/// <param name="logger">Logger.</param>
109103
public Client(string apiKey, HttpMessageHandler handler, StrongGridClientOptions options = null, ILogger logger = null)
110-
: base(apiKey, new HttpClient(handler), true, options ?? _defaultOptions, logger)
104+
: base(apiKey, new HttpClient(handler), true, options, logger)
111105
{
112106
Init();
113107
}
@@ -120,7 +114,7 @@ public Client(string apiKey, HttpMessageHandler handler, StrongGridClientOptions
120114
/// <param name="options">Options for the SendGrid client.</param>
121115
/// <param name="logger">Logger.</param>
122116
public Client(string apiKey, HttpClient httpClient, StrongGridClientOptions options = null, ILogger logger = null)
123-
: base(apiKey, httpClient, false, options ?? _defaultOptions, logger)
117+
: base(apiKey, httpClient, false, options, logger)
124118
{
125119
Init();
126120
}

Source/StrongGrid/Extensions/Public.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1775,5 +1775,20 @@ public static IHttpClientBuilder AddLegacyStrongGrid(this IServiceCollection ser
17751775

17761776
return httpClientBuilder;
17771777
}
1778+
1779+
/// <summary>
1780+
/// Configures the client options to use the European Union SendGrid API endpoint.
1781+
/// </summary>
1782+
/// <remarks>Use this method to direct API requests to SendGrid's European Union infrastructure, which may be
1783+
/// required for compliance with regional data regulations.</remarks>
1784+
/// <param name="options">The client options to configure. Cannot be null.</param>
1785+
/// <returns>The same <see cref="StrongGridClientOptions"/> instance with the API endpoint set to the European Union endpoint.</returns>
1786+
/// <exception cref="ArgumentNullException">Thrown if <paramref name="options"/> is null.</exception>
1787+
public static StrongGridClientOptions WithEuropeanUnionApiEndPoint(this StrongGridClientOptions options)
1788+
{
1789+
if (options == null) throw new ArgumentNullException(nameof(options));
1790+
options.ApiEndPoint = new Uri("https://api.eu.sendgrid.com/v3");
1791+
return options;
1792+
}
17781793
}
17791794
}

Source/StrongGrid/LegacyClient.cs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,6 @@ namespace StrongGrid
1212
[Obsolete("The legacy client, legacy resources and legacy model classes are obsolete")]
1313
public class LegacyClient : BaseClient, ILegacyClient
1414
{
15-
private static readonly StrongGridClientOptions _defaultOptions = new StrongGridClientOptions()
16-
{
17-
LogLevelSuccessfulCalls = LogLevel.Debug,
18-
LogLevelFailedCalls = LogLevel.Debug
19-
};
20-
2115
#region PROPERTIES
2216

2317
/// <summary>
@@ -87,7 +81,7 @@ public class LegacyClient : BaseClient, ILegacyClient
8781
/// <param name="options">Options for the SendGrid client.</param>
8882
/// <param name="logger">Logger.</param>
8983
public LegacyClient(string apiKey, StrongGridClientOptions options = null, ILogger logger = null)
90-
: base(apiKey, null, false, options ?? _defaultOptions, logger)
84+
: base(apiKey, null, false, options, logger)
9185
{
9286
Init();
9387
}
@@ -100,7 +94,7 @@ public LegacyClient(string apiKey, StrongGridClientOptions options = null, ILogg
10094
/// <param name="options">Options for the SendGrid client.</param>
10195
/// <param name="logger">Logger.</param>
10296
public LegacyClient(string apiKey, IWebProxy proxy, StrongGridClientOptions options = null, ILogger logger = null)
103-
: base(apiKey, new HttpClient(new HttpClientHandler { Proxy = proxy, UseProxy = proxy != null }), true, options ?? _defaultOptions, logger)
97+
: base(apiKey, new HttpClient(new HttpClientHandler { Proxy = proxy, UseProxy = proxy != null }), true, options, logger)
10498
{
10599
Init();
106100
}
@@ -113,7 +107,7 @@ public LegacyClient(string apiKey, IWebProxy proxy, StrongGridClientOptions opti
113107
/// <param name="options">Options for the SendGrid client.</param>
114108
/// <param name="logger">Logger.</param>
115109
public LegacyClient(string apiKey, HttpMessageHandler handler, StrongGridClientOptions options = null, ILogger logger = null)
116-
: base(apiKey, new HttpClient(handler), true, options ?? _defaultOptions, logger)
110+
: base(apiKey, new HttpClient(handler), true, options, logger)
117111
{
118112
Init();
119113
}
@@ -126,7 +120,7 @@ public LegacyClient(string apiKey, HttpMessageHandler handler, StrongGridClientO
126120
/// <param name="options">Options for the SendGrid client.</param>
127121
/// <param name="logger">Logger.</param>
128122
public LegacyClient(string apiKey, HttpClient httpClient, StrongGridClientOptions options = null, ILogger logger = null)
129-
: base(apiKey, httpClient, false, options ?? _defaultOptions, logger)
123+
: base(apiKey, httpClient, false, options, logger)
130124
{
131125
Init();
132126
}
Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Microsoft.Extensions.Logging;
2+
using System;
23

34
namespace StrongGrid.Utilities
45
{
@@ -7,14 +8,21 @@ namespace StrongGrid.Utilities
78
/// </summary>
89
public class StrongGridClientOptions
910
{
11+
private const string SENDGRID_V3_BASE_URI = "https://api.sendgrid.com/v3";
12+
1013
/// <summary>
1114
/// Gets or sets the log levels for successful calls (HTTP status code in the 200-299 range).
1215
/// </summary>
13-
public LogLevel LogLevelSuccessfulCalls { get; set; }
16+
public LogLevel LogLevelSuccessfulCalls { get; set; } = LogLevel.Debug;
1417

1518
/// <summary>
1619
/// Gets or sets the log levels for failed calls (HTTP status code outside of the 200-299 range).
1720
/// </summary>
18-
public LogLevel LogLevelFailedCalls { get; set; }
21+
public LogLevel LogLevelFailedCalls { get; set; } = LogLevel.Error;
22+
23+
/// <summary>
24+
/// Gets or sets the base URI of the SendGrid API endpoint.
25+
/// </summary>
26+
public Uri ApiEndPoint { get; set; } = new Uri(SENDGRID_V3_BASE_URI);
1927
}
2028
}

0 commit comments

Comments
 (0)