From 673b0e0c4543440241c21fd6c9e8e06834ac4f95 Mon Sep 17 00:00:00 2001 From: sburman Date: Fri, 24 Nov 2023 20:55:00 +0530 Subject: [PATCH] init --- src/SendGrid/SendGridClientOptions.cs | 30 +++++++++++++++++++ .../SendgridEmailClientTests.cs | 16 ++++++++++ 2 files changed, 46 insertions(+) create mode 100644 tests/SendGrid.Tests/SendgridEmailClientTests.cs diff --git a/src/SendGrid/SendGridClientOptions.cs b/src/SendGrid/SendGridClientOptions.cs index 290f6cfab..d9ec4a58c 100644 --- a/src/SendGrid/SendGridClientOptions.cs +++ b/src/SendGrid/SendGridClientOptions.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Net.Http.Headers; namespace SendGrid @@ -17,6 +18,11 @@ public SendGridClientOptions() } private string apiKey; + Dictionary REGION_HOST_MAP = new Dictionary + { + {"eu", "https://api.eu.sendgrid.com/"}, + {"global", "https://api.sendgrid.com/"} + }; /// /// The Twilio SendGrid API key. @@ -36,5 +42,29 @@ public string ApiKey Auth = new AuthenticationHeaderValue("Bearer", apiKey); } } + + /// + /// Sets the data residency for the SendGrid client. + /// + /// The desired data residency region ("global" or "eu"). + /// The updated SendGridClientOptions instance. + public SendGridClientOptions SetDataResidency(string region) + { + if (string.IsNullOrWhiteSpace(region)) + { + throw new ArgumentNullException(nameof(region)); + } + + if (!REGION_HOST_MAP.ContainsKey(region)) + { + Console.WriteLine("Region can only be 'global' or 'eu'."); + } + else + { + Host = REGION_HOST_MAP[region]; + } + + return this; + } } } diff --git a/tests/SendGrid.Tests/SendgridEmailClientTests.cs b/tests/SendGrid.Tests/SendgridEmailClientTests.cs new file mode 100644 index 000000000..744c64662 --- /dev/null +++ b/tests/SendGrid.Tests/SendgridEmailClientTests.cs @@ -0,0 +1,16 @@ +namespace SendGrid.Tests +{ + using System; + using Xunit; + + public class SendgridEmailClientTests + { + [Fact] + public void TestClientOptionsConstruction() + { + var options = new SendGridClientOptions(); + Assert.Equal("https://api.sendgrid.com", options.Host); + } + + } +}