From 8d42b0977f53e48833743e3382c52eccdb79de22 Mon Sep 17 00:00:00 2001 From: tr00d Date: Fri, 15 Mar 2024 11:26:06 +0100 Subject: [PATCH] refactor: [breaking] remove URLs on Configuration, in favor or VonageUrls --- README.md | 8 +++-- Vonage.Test/ConfigurationTest.cs | 19 ++++-------- Vonage.Test/Meetings/E2EBase.cs | 2 +- Vonage.Test/ProactiveConnect/E2EBase.cs | 2 +- Vonage/Configuration.cs | 41 ++----------------------- Vonage/VonageClient.cs | 6 ++-- 6 files changed, 21 insertions(+), 57 deletions(-) diff --git a/README.md b/README.md index b765c43c1..40159a7e5 100644 --- a/README.md +++ b/README.md @@ -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", @@ -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. | diff --git a/Vonage.Test/ConfigurationTest.cs b/Vonage.Test/ConfigurationTest.cs index 5b103792f..bf4cb9e62 100644 --- a/Vonage.Test/ConfigurationTest.cs +++ b/Vonage.Test/ConfigurationTest.cs @@ -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(); } @@ -77,15 +79,6 @@ public void FromConfiguration_ShouldSetApplicationKey_GivenConfigurationContains }) .Build()).ApplicationKey.Should().Be("RandomValue"); - [Fact] - public void FromConfiguration_ShouldSetEuropeApiUrl_GivenConfigurationContainsEuropeApiUrl() => - Configuration.FromConfiguration(new ConfigurationBuilder() - .AddInMemoryCollection(new Dictionary - { - {"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() @@ -150,9 +143,9 @@ public void FromConfiguration_ShouldSetVideoApiUrl_GivenConfigurationContainsVid .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( diff --git a/Vonage.Test/Meetings/E2EBase.cs b/Vonage.Test/Meetings/E2EBase.cs index da25c450a..90c996066 100644 --- a/Vonage.Test/Meetings/E2EBase.cs +++ b/Vonage.Test/Meetings/E2EBase.cs @@ -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()); } diff --git a/Vonage.Test/ProactiveConnect/E2EBase.cs b/Vonage.Test/ProactiveConnect/E2EBase.cs index 91b92902c..baf783df6 100644 --- a/Vonage.Test/ProactiveConnect/E2EBase.cs +++ b/Vonage.Test/ProactiveConnect/E2EBase.cs @@ -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()); } diff --git a/Vonage/Configuration.cs b/Vonage/Configuration.cs index 016fb95f1..1586fb660 100644 --- a/Vonage/Configuration.cs +++ b/Vonage/Configuration.cs @@ -88,25 +88,11 @@ public HttpClient Client /// public HttpMessageHandler ClientHandler { get; set; } - /// - /// Retrieves the Europe Api Url. - /// - [Obsolete("Favor the VonageUrls property instead.")] - public Uri EuropeApiUrl => this.FetchApiUrlEurope(); - /// /// Retrieves the unique instance (Singleton). /// public static Configuration Instance { get; } = new Configuration(); - /// - /// Retrieves the Nexmo Api Url. - /// - [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"]); - /// /// The timeout (in seconds) applied to every request. If not provided, the default timeout will be applied. /// @@ -115,14 +101,6 @@ public HttpClient Client ? Maybe.Some(TimeSpan.FromSeconds(timeout)) : Maybe.None; - /// - /// Retrieves the Rest Api Url. - /// - [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"]); - /// /// Retrieves the Security Secret. /// @@ -143,14 +121,6 @@ public HttpClient Client /// public string UserAgent => this.Settings["vonage:UserAgent"] ?? string.Empty; - /// - /// Retrieves the Video Api Url. - /// - [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"]); - /// /// Provide urls to all Vonage APIs. /// @@ -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) @@ -301,14 +266,14 @@ public enum Region { /// /// - [Description("Us")] US, + [Description("AMER")] US, /// /// - [Description("Eu")] EU, + [Description("EMEA")] EU, /// /// - [Description("Apac")] APAC, + [Description("APAC")] APAC, } } \ No newline at end of file diff --git a/Vonage/VonageClient.cs b/Vonage/VonageClient.cs index acb961481..6f06d6d6f 100644 --- a/Vonage/VonageClient.cs +++ b/Vonage/VonageClient.cs @@ -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)));