Skip to content

Commit

Permalink
refactor: [breaking] remove URLs on Configuration, in favor or Vonage…
Browse files Browse the repository at this point in the history
…Urls
  • Loading branch information
Tr00d committed Mar 15, 2024
1 parent 2dfa40d commit 8d42b09
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 57 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,9 @@ an `appsettings` section:
"UserAgent": "myApp/1.0",
"Url.Rest": "https://rest.nexmo.com",
"Url.Api": "https://api.nexmo.com",
"Url.Api.Europe": "https://api-eu.vonage.com",
"Url.Api.EMEA": "https://api-eu.vonage.com",
"Url.Api.AMER": "https://api-us.vonage.com",
"Url.Api.APAC": "https://api-ap.vonage.com",
"Url.Api.Video": "https://video.api.vonage.com",
"Api.Key": "VONAGE-API-KEY",
"Api.Secret": "VONAGE-API-SECRET",
Expand Down Expand Up @@ -213,7 +215,9 @@ Configuration.Instance.Settings["vonage:Url.Rest"] = "https://www.example.com/re
| Signing_method | Optional. This is the method used for signing SMS messages |
| Url.Rest | Optional. Vonage REST API base URL. Defaults to https://rest.nexmo.com |
| Url.Api | Optional. Vonage API base URL. Defaults to https://api.nexmo.com |
| Url.Api.Europe | Optional. Vonage API base URL for Meetings. Defaults to https://api-eu.vonage.com |
| Url.Api.EMEA | Optional. Vonage API base URL for Europe, Middle East and Africa. Defaults to https://api-eu.vonage.com |
| Url.Api.AMER | Optional. Vonage API base URL for North, Central and South America. Defaults to https://api-us.vonage.com |
| Url.Api.APAC | Optional. Vonage API base URL for Asia and Pacific. Defaults to https://api-ap.vonage.com |
| Url.Api.Video | Optional. Vonage API base URL for Video. Defaults to https://video.api.vonage.com |
| RequestsPerSecond | Optional. Throttle to specified requests per second. |
| RequestTimeout | Optional. The timeout (in seconds) applied to every request. If not provided, the default timeout will be applied. |
Expand Down
19 changes: 6 additions & 13 deletions Vonage.Test/ConfigurationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@ public void FromConfiguration_ShouldCreateEmptyConfiguration_GivenConfigurationC
configuration.SecuritySecret.Should().BeEmpty();
configuration.SigningMethod.Should().BeEmpty();
configuration.UserAgent.Should().BeEmpty();
configuration.EuropeApiUrl.Should().Be(new Uri("https://api-eu.vonage.com"));
configuration.VonageUrls.Nexmo.Should().Be(new Uri("https://api.nexmo.com"));
configuration.VonageUrls.Rest.Should().Be(new Uri("https://rest.nexmo.com"));
configuration.VonageUrls.Video.Should().Be(new Uri("https://video.api.vonage.com"));
configuration.VonageUrls.Get(VonageUrls.Region.EU).Should().Be(new Uri("https://api-eu.vonage.com"));
configuration.VonageUrls.Get(VonageUrls.Region.APAC).Should().Be(new Uri("https://api-ap.vonage.com"));
configuration.VonageUrls.Get(VonageUrls.Region.US).Should().Be(new Uri("https://api-us.vonage.com"));
configuration.RequestTimeout.Should().BeNone();
}

Expand Down Expand Up @@ -77,15 +79,6 @@ public void FromConfiguration_ShouldCreateEmptyConfiguration_GivenConfigurationC
})
.Build()).ApplicationKey.Should().Be("RandomValue");

[Fact]
public void FromConfiguration_ShouldSetEuropeApiUrl_GivenConfigurationContainsEuropeApiUrl() =>
Configuration.FromConfiguration(new ConfigurationBuilder()
.AddInMemoryCollection(new Dictionary<string, string>
{
{"vonage:Url.Api.Europe", "https://api.vonage.com"},
})
.Build()).EuropeApiUrl.Should().Be(new Uri("https://api.vonage.com"));

[Fact]
public void FromConfiguration_ShouldSetNexmoApiUrl_GivenConfigurationContainsNexmoApiUrl() =>
Configuration.FromConfiguration(new ConfigurationBuilder()
Expand Down Expand Up @@ -150,9 +143,9 @@ public void FromConfiguration_ShouldCreateEmptyConfiguration_GivenConfigurationC
.Build()).VonageUrls.Video.Should().Be(new Uri("https://api.vonage.com"));

[Theory]
[InlineData(VonageUrls.Region.US, "vonage:Url.Api.Us")]
[InlineData(VonageUrls.Region.EU, "vonage:Url.Api.Eu")]
[InlineData(VonageUrls.Region.APAC, "vonage:Url.Api.Apac")]
[InlineData(VonageUrls.Region.US, "vonage:Url.Api.AMER")]
[InlineData(VonageUrls.Region.EU, "vonage:Url.Api.EMEA")]
[InlineData(VonageUrls.Region.APAC, "vonage:Url.Api.APAC")]
public void VonageUrl_ShouldReturnCustomApiUsUrl_GivenConfigurationContainsApiUsUrl(VonageUrls.Region region,
string key) =>
Configuration.FromConfiguration(new ConfigurationBuilder().AddInMemoryCollection(
Expand Down
2 changes: 1 addition & 1 deletion Vonage.Test/Meetings/E2EBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public abstract class E2EBase

protected E2EBase(string serializationNamespace)
{
this.Helper = TestingContext.WithBearerCredentials("Url.Api.Europe");
this.Helper = TestingContext.WithBearerCredentials("Url.Api.EMEA");
this.Serialization =
new SerializationTestHelper(serializationNamespace, JsonSerializerBuilder.BuildWithSnakeCase());
}
Expand Down
2 changes: 1 addition & 1 deletion Vonage.Test/ProactiveConnect/E2EBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public abstract class E2EBase

protected E2EBase(string serializationNamespace)
{
this.Helper = TestingContext.WithBearerCredentials("Url.Api.Europe");
this.Helper = TestingContext.WithBearerCredentials("Url.Api.EMEA");
this.Serialization =
new SerializationTestHelper(serializationNamespace, JsonSerializerBuilder.BuildWithSnakeCase());
}
Expand Down
41 changes: 3 additions & 38 deletions Vonage/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,25 +88,11 @@ public HttpClient Client
/// </summary>
public HttpMessageHandler ClientHandler { get; set; }

/// <summary>
/// Retrieves the Europe Api Url.
/// </summary>
[Obsolete("Favor the VonageUrls property instead.")]
public Uri EuropeApiUrl => this.FetchApiUrlEurope();

/// <summary>
/// Retrieves the unique instance (Singleton).
/// </summary>
public static Configuration Instance { get; } = new Configuration();

/// <summary>
/// Retrieves the Nexmo Api Url.
/// </summary>
[Obsolete("Favor the VonageUrls property instead.")]
public Uri NexmoApiUrl => this.Settings["vonage:Url.Api"] is null
? this.VonageUrls.Nexmo
: new Uri(this.Settings["vonage:Url.Api"]);

/// <summary>
/// The timeout (in seconds) applied to every request. If not provided, the default timeout will be applied.
/// </summary>
Expand All @@ -115,14 +101,6 @@ public HttpClient Client
? Maybe<TimeSpan>.Some(TimeSpan.FromSeconds(timeout))
: Maybe<TimeSpan>.None;

/// <summary>
/// Retrieves the Rest Api Url.
/// </summary>
[Obsolete("Favor the VonageUrls property instead.")]
public Uri RestApiUrl => this.Settings["vonage:Url.Rest"] is null
? this.VonageUrls.Rest
: new Uri(this.Settings["vonage:Url.Rest"]);

/// <summary>
/// Retrieves the Security Secret.
/// </summary>
Expand All @@ -143,14 +121,6 @@ public HttpClient Client
/// </summary>
public string UserAgent => this.Settings["vonage:UserAgent"] ?? string.Empty;

/// <summary>
/// Retrieves the Video Api Url.
/// </summary>
[Obsolete("Favor the VonageUrls property instead.")]
public Uri VideoApiUrl => this.Settings["vonage:Url.Api.Video"] is null
? this.VonageUrls.Video
: new Uri(this.Settings["vonage:Url.Api.Video"]);

/// <summary>
/// Provide urls to all Vonage APIs.
/// </summary>
Expand Down Expand Up @@ -194,11 +164,6 @@ private static TimeSpanSemaphore BuildSemaphore(double requestsPerSecond)
return execTimeSpanSemaphore;
}

private Uri FetchApiUrlEurope() =>
this.Settings["vonage:Url.Api.Europe"] is null
? this.VonageUrls.Get(VonageUrls.Region.EU)
: new Uri(this.Settings["vonage:Url.Api.Europe"]);

private ThrottlingMessageHandler GetThrottlingMessageHandler(TimeSpanSemaphore semaphore) =>
this.ClientHandler != null
? new ThrottlingMessageHandler(semaphore, this.ClientHandler)
Expand Down Expand Up @@ -301,14 +266,14 @@ public enum Region
{
/// <summary>
/// </summary>
[Description("Us")] US,
[Description("AMER")] US,

/// <summary>
/// </summary>
[Description("Eu")] EU,
[Description("EMEA")] EU,

/// <summary>
/// </summary>
[Description("Apac")] APAC,
[Description("APAC")] APAC,
}
}
6 changes: 4 additions & 2 deletions Vonage/VonageClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,13 @@ private void PropagateCredentials()
new ConversationsClient(
this.BuildConfiguration(this.InitializeHttpClient(this.GetConfiguration().VonageUrls.Nexmo)));
this.MeetingsClient = new MeetingsClient(
this.BuildConfiguration(this.InitializeHttpClient(this.GetConfiguration().EuropeApiUrl)),
this.BuildConfiguration(
this.InitializeHttpClient(this.GetConfiguration().VonageUrls.Get(VonageUrls.Region.EU))),
new FileSystem());
this.ProactiveConnectClient =
new ProactiveConnectClient(
this.BuildConfiguration(this.InitializeHttpClient(this.GetConfiguration().EuropeApiUrl)));
this.BuildConfiguration(
this.InitializeHttpClient(this.GetConfiguration().VonageUrls.Get(VonageUrls.Region.EU))));
this.VideoClient =
new VideoClient(
this.BuildConfiguration(this.InitializeHttpClient(this.GetConfiguration().VonageUrls.Video)));
Expand Down

0 comments on commit 8d42b09

Please sign in to comment.