Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
shrutiburman committed Nov 24, 2023
1 parent e66576c commit 673b0e0
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/SendGrid/SendGridClientOptions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Net.Http.Headers;

namespace SendGrid
Expand All @@ -17,6 +18,11 @@ public SendGridClientOptions()
}

private string apiKey;
Dictionary<string, string> REGION_HOST_MAP = new Dictionary<string, string>
{
{"eu", "https://api.eu.sendgrid.com/"},
{"global", "https://api.sendgrid.com/"}
};

/// <summary>
/// The Twilio SendGrid API key.
Expand All @@ -36,5 +42,29 @@ public string ApiKey
Auth = new AuthenticationHeaderValue("Bearer", apiKey);
}
}

/// <summary>
/// Sets the data residency for the SendGrid client.
/// </summary>
/// <param name="region">The desired data residency region ("global" or "eu").</param>
/// <returns>The updated SendGridClientOptions instance.</returns>
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;
}
}
}
16 changes: 16 additions & 0 deletions tests/SendGrid.Tests/SendgridEmailClientTests.cs
Original file line number Diff line number Diff line change
@@ -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);
}

}
}

0 comments on commit 673b0e0

Please sign in to comment.