Skip to content

Commit

Permalink
finale
Browse files Browse the repository at this point in the history
  • Loading branch information
shrutiburman committed Nov 24, 2023
1 parent 1519a0a commit 6b4b5b8
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 13 deletions.
4 changes: 3 additions & 1 deletion src/SendGrid/SendGridClient.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Http;

Expand Down Expand Up @@ -90,5 +91,6 @@ private static SendGridClientOptions buildOptions(string apiKey, string host, Di
HttpErrorAsException = httpErrorAsException
};
}

}
}
18 changes: 8 additions & 10 deletions src/SendGrid/SendGridClientOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ namespace SendGrid
/// </summary>
public class SendGridClientOptions : BaseClientOptions
{
Dictionary<string, string> REGION_HOST_MAP = new Dictionary<string, string>
{
{"eu", "https://api.eu.sendgrid.com/"},
{"global", "https://api.sendgrid.com/"}
};

/// <summary>
/// Initializes a new instance of the <see cref="SendGridClientOptions"/> class.
/// </summary>
Expand All @@ -18,11 +24,6 @@ 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 Down Expand Up @@ -59,11 +60,8 @@ public SendGridClientOptions SetDataResidency(string region)
{
Console.WriteLine("Region can only be 'global' or 'eu'.");
}
else
{
Host = REGION_HOST_MAP[region];
}

string result = REGION_HOST_MAP.ContainsKey(region) ? REGION_HOST_MAP[region] : "https://api.sendgrid.com";
Host = result;
return this;
}
}
Expand Down
17 changes: 15 additions & 2 deletions tests/SendGrid.Tests/SendgridEmailClientTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
namespace SendGrid.Tests
{
using System;
using SendGrid.Helpers.Mail;
using Xunit;

public class SendgridEmailClientTests
Expand All @@ -19,12 +20,24 @@ public void TestClientOptionsSetDataResidency()
Assert.Equal("https://api.eu.sendgrid.com/", options.Host);
}
[Fact]
public void TestClientOptionsSetDataResidencyGlobalWrong()
public void TestClientOptionsSetDataResidencyEU()
{
var options = new SendGridClientOptions();
options.SetDataResidency("eu");
Assert.Equal("https://api.sendgrid.com/", options.Host);
Assert.Equal("https://api.eu.sendgrid.com/", options.Host);
}

[Fact]
public void TestClientOptionsSetViaSendgridClient()
{
var options = new SendGridClientOptions();
options.SetDataResidency("eu");
var sg = new SendGridClient(options);
Assert.Equal("https://api.eu.sendgrid.com/", options.Host);
Console.WriteLine(sg);
//Assert.Equal("https://api.eu.sendgrid.com/", sg.UrlPath);
}


}
}

0 comments on commit 6b4b5b8

Please sign in to comment.