diff --git a/README.md b/README.md index 8dd0fcdb1..2203074b3 100644 --- a/README.md +++ b/README.md @@ -151,23 +151,20 @@ an `appsettings` section: ```json { - "appSettings": { - "Vonage.UserAgent": "myApp/1.0", - "Vonage.Url.Rest": "https://rest.nexmo.com", - "Vonage.Url.Api": "https://api.nexmo.com", - "Vonage.Url.Api.Europe": "https://api-eu.vonage.com", - "Vonage.Url.Api.Video": "https://video.api.vonage.com", - "Vonage_key": "VONAGE-API-KEY", - "Vonage_secret": "VONAGE-API-SECRET", - "Vonage.Application.Id": "ffffffff-ffff-ffff-ffff-ffffffffffff", - "Vonage.Application.Key": "VONAGE_APPLICATION_PRIVATE_KEY" + "vonage": { + "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.Video": "https://video.api.vonage.com", + "Api.Key": "VONAGE-API-KEY", + "Api.Secret": "VONAGE-API-SECRET", + "Application.Id": "ffffffff-ffff-ffff-ffff-ffffffffffff", + "Application.Key": "VONAGE_APPLICATION_PRIVATE_KEY" } } ``` -> Note: While the section is currently names `appsettings`, we intend to use a more explicit name like `vonageSettings`. -> Stay tuned for the next major release. - The configuration is automatically loaded in the `Configuration` singleton. #### Lazy registration (recommended for .NET Core and above) @@ -226,10 +223,8 @@ var vonageClient = new VonageClient(credentials); If required, you can override values directly in the `Configuration` singleton: ```cshap -Configuration.Instance.Settings["appSettings:Vonage.Url.Api"] = "https://www.example.com/api"; -Configuration.Instance.Settings["appSettings:Vonage.Url.Rest"] = "https://www.example.com/rest"; -Configuration.Instance.Settings["appSettings:Vonage.Url.Api.Europe"] = "https://www.meetings.example.com/api"; -Configuration.Instance.Settings["appSettings:Vonage.Video.Url.Rest"] = "https://www.video.example.com/rest"; +Configuration.Instance.Settings["vonage:Url.Api"] = "https://www.example.com/api"; +Configuration.Instance.Settings["vonage:Url.Rest"] = "https://www.example.com/rest"; ``` > Note: Private Key is the literal key - not a path to the file containing the key @@ -239,21 +234,21 @@ Configuration.Instance.Settings["appSettings:Vonage.Video.Url.Rest"] = "https:// ### Configuration Reference -| Key | Description | -|--------------------------|----------------------------------------------------------------------------------------------------------------------------------| -| Vonage_key | Your API key from the [dashboard](https://dashboard.nexmo.com/settings) | -| Vonage_secret | Your API secret from the [dashboard](https://dashboard.nexmo.com/settings) | -| Vonage.Application.Id | Your application ID | -| Vonage.Application.Key | Your application's private key | -| Vonage.security_secret | Optional. This is the signing secret that's used for [signing SMS](https://developer.nexmo.com/concepts/guides/signing-messages) | -| Vonage.signing_method | Optional. This is the method used for signing SMS messages | -| Vonage.Url.Rest | Optional. Vonage REST API base URL. Defaults to https://rest.nexmo.com | -| Vonage.Url.Api | Optional. Vonage API base URL. Defaults to https://api.nexmo.com | -| Vonage.Url.Api.Europe | Optional. Vonage API base URL for Meetings. Defaults to https://api-eu.vonage.com | -| Vonage.Url.Api.Video | Optional. Vonage API base URL for Video. Defaults to https://video.api.vonage.com | -| Vonage.RequestsPerSecond | Optional. Throttle to specified requests per second. | -| Vonage.RequestTimeout | Optional. The timeout (in seconds) applied to every request. If not provided, the default timeout will be applied. | -| Vonage.UserAgent | Optional. Your app-specific usage identifier in the format of `name/version`. Example: `"myApp/1.0"` | +| Key | Description | +|-------------------|----------------------------------------------------------------------------------------------------------------------------------| +| Api.Key | Your API key from the [dashboard](https://dashboard.nexmo.com/settings) | +| Api.Secret | Your API secret from the [dashboard](https://dashboard.nexmo.com/settings) | +| Application.Id | Your application ID | +| Application.Key | Your application's private key | +| Security_secret | Optional. This is the signing secret that's used for [signing SMS](https://developer.nexmo.com/concepts/guides/signing-messages) | +| 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.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. | +| UserAgent | Optional. Your app-specific usage identifier in the format of `name/version`. Example: `"myApp/1.0"` | ### Logging @@ -695,9 +690,8 @@ Pick your preferred IDE: - Visual Studio Code - Jetbrains Rider -Keep in mind the SDK is built on `netstandard2.0` and tested against several framework versions (v4.6.2 & upper, and -.Net6.0). -Therefore, they should be installed on your machine to guarantee compatibility with all supported framework versions. +Keep in mind the SDK is built on `netstandard2.0` and tested against several framework versions (.NET6.0 and above). +Therefore, they should be installed on your machine for tests to run. 1. Get the latest code either by cloning the repository or downloading a snapshot of the source. 2. Open "Vonage.sln" diff --git a/Vonage.Test/ConfigurationTest.cs b/Vonage.Test/ConfigurationTest.cs index 7af6a74e5..5b103792f 100644 --- a/Vonage.Test/ConfigurationTest.cs +++ b/Vonage.Test/ConfigurationTest.cs @@ -46,7 +46,7 @@ public void FromConfiguration_ShouldSetApiKey_GivenConfigurationContainsApiKey() Configuration.FromConfiguration(new ConfigurationBuilder() .AddInMemoryCollection(new Dictionary { - {"appSettings:Vonage_key", "RandomValue"}, + {"vonage:Api.Key", "RandomValue"}, }) .Build()).ApiKey.Should().Be("RandomValue"); @@ -55,7 +55,7 @@ public void FromConfiguration_ShouldSetApiKSecret_GivenConfigurationContainsApiS Configuration.FromConfiguration(new ConfigurationBuilder() .AddInMemoryCollection(new Dictionary { - {"appSettings:Vonage_secret", "RandomValue"}, + {"vonage:Api.Secret", "RandomValue"}, }) .Build()).ApiSecret.Should().Be("RandomValue"); @@ -64,7 +64,7 @@ public void FromConfiguration_ShouldSetApplicationId_GivenConfigurationContainsA Configuration.FromConfiguration(new ConfigurationBuilder() .AddInMemoryCollection(new Dictionary { - {"appSettings:Vonage.Application.Id", "RandomValue"}, + {"vonage:Application.Id", "RandomValue"}, }) .Build()).ApplicationId.Should().Be("RandomValue"); @@ -73,7 +73,7 @@ public void FromConfiguration_ShouldSetApplicationKey_GivenConfigurationContains Configuration.FromConfiguration(new ConfigurationBuilder() .AddInMemoryCollection(new Dictionary { - {"appSettings:Vonage.Application.Key", "RandomValue"}, + {"vonage:Application.Key", "RandomValue"}, }) .Build()).ApplicationKey.Should().Be("RandomValue"); @@ -82,7 +82,7 @@ public void FromConfiguration_ShouldSetEuropeApiUrl_GivenConfigurationContainsEu Configuration.FromConfiguration(new ConfigurationBuilder() .AddInMemoryCollection(new Dictionary { - {"appSettings:Vonage.Url.Api.Europe", "https://api.vonage.com"}, + {"vonage:Url.Api.Europe", "https://api.vonage.com"}, }) .Build()).EuropeApiUrl.Should().Be(new Uri("https://api.vonage.com")); @@ -91,7 +91,7 @@ public void FromConfiguration_ShouldSetNexmoApiUrl_GivenConfigurationContainsNex Configuration.FromConfiguration(new ConfigurationBuilder() .AddInMemoryCollection(new Dictionary { - {"appSettings:Vonage.Url.Api", "https://api.vonage.com"}, + {"vonage:Url.Api", "https://api.vonage.com"}, }) .Build()).VonageUrls.Nexmo.Should().Be(new Uri("https://api.vonage.com")); @@ -100,7 +100,7 @@ public void FromConfiguration_ShouldSetRequestTimeout_GivenConfigurationContains Configuration.FromConfiguration(new ConfigurationBuilder() .AddInMemoryCollection(new Dictionary { - {"appSettings:Vonage.RequestTimeout", "100"}, + {"vonage:RequestTimeout", "100"}, }) .Build()).RequestTimeout.Should().BeSome(TimeSpan.FromSeconds(100)); @@ -109,7 +109,7 @@ public void FromConfiguration_ShouldSetRestApiUrl_GivenConfigurationContainsRest Configuration.FromConfiguration(new ConfigurationBuilder() .AddInMemoryCollection(new Dictionary { - {"appSettings:Vonage.Url.Rest", "https://api.vonage.com"}, + {"vonage:Url.Rest", "https://api.vonage.com"}, }) .Build()).VonageUrls.Rest.Should().Be(new Uri("https://api.vonage.com")); @@ -118,7 +118,7 @@ public void FromConfiguration_ShouldSetSecuritySecret_GivenConfigurationContains Configuration.FromConfiguration(new ConfigurationBuilder() .AddInMemoryCollection(new Dictionary { - {"appSettings:Vonage.security_secret", "RandomValue"}, + {"vonage:Security_secret", "RandomValue"}, }) .Build()).SecuritySecret.Should().Be("RandomValue"); @@ -127,7 +127,7 @@ public void FromConfiguration_ShouldSetSigningMethod_GivenConfigurationContainsS Configuration.FromConfiguration(new ConfigurationBuilder() .AddInMemoryCollection(new Dictionary { - {"appSettings:Vonage.signing_method", "sha512"}, + {"vonage:Signing_method", "sha512"}, }) .Build()).SigningMethod.Should().Be("sha512"); @@ -136,7 +136,7 @@ public void FromConfiguration_ShouldSetUserAgent_GivenConfigurationContainsUserA Configuration.FromConfiguration(new ConfigurationBuilder() .AddInMemoryCollection(new Dictionary { - {"appSettings:Vonage.UserAgent", "RandomValue"}, + {"vonage:UserAgent", "RandomValue"}, }) .Build()).UserAgent.Should().Be("RandomValue"); @@ -145,14 +145,14 @@ public void FromConfiguration_ShouldSetVideoApiUrl_GivenConfigurationContainsVid Configuration.FromConfiguration(new ConfigurationBuilder() .AddInMemoryCollection(new Dictionary { - {"appSettings:Vonage.Url.Api.Video", "https://api.vonage.com"}, + {"vonage:Url.Api.Video", "https://api.vonage.com"}, }) .Build()).VonageUrls.Video.Should().Be(new Uri("https://api.vonage.com")); [Theory] - [InlineData(VonageUrls.Region.US, "appSettings:Vonage.Url.Api.Us")] - [InlineData(VonageUrls.Region.EU, "appSettings:Vonage.Url.Api.Eu")] - [InlineData(VonageUrls.Region.APAC, "appSettings:Vonage.Url.Api.Apac")] + [InlineData(VonageUrls.Region.US, "vonage:Url.Api.Us")] + [InlineData(VonageUrls.Region.EU, "vonage:Url.Api.Eu")] + [InlineData(VonageUrls.Region.APAC, "vonage:Url.Api.Apac")] public void VonageUrl_ShouldReturnCustomApiUsUrl_GivenConfigurationContainsApiUsUrl(VonageUrls.Region region, string key) => Configuration.FromConfiguration(new ConfigurationBuilder().AddInMemoryCollection( @@ -166,7 +166,7 @@ public void VonageUrl_ShouldReturnCustomApiUsUrl_GivenConfigurationContainsApiUs public void VonageUrl_ShouldReturnCustomNexmoUrl_GivenConfigurationContainsDefaultUrl() => Configuration.FromConfiguration(new ConfigurationBuilder() .AddInMemoryCollection(new Dictionary - {{"appSettings:Vonage.Url.Api", "https://api.com"}}).Build()) + {{"vonage:Url.Api", "https://api.com"}}).Build()) .VonageUrls.Nexmo.Should().Be(new Uri("https://api.com")); [Fact] @@ -174,7 +174,7 @@ public void VonageUrl_ShouldReturnCustomRestUrl_GivenConfigurationContainsRestUr Configuration.FromConfiguration(new ConfigurationBuilder().AddInMemoryCollection( new Dictionary { - {"appSettings:Vonage.Url.Rest", "https://api.com"}, + {"vonage:Url.Rest", "https://api.com"}, }).Build()) .VonageUrls.Rest.Should().Be(new Uri("https://api.com")); @@ -183,7 +183,7 @@ public void VonageUrl_ShouldReturnCustomVideoUrl_GivenConfigurationContainsVideo Configuration.FromConfiguration(new ConfigurationBuilder().AddInMemoryCollection( new Dictionary { - {"appSettings:Vonage.Url.Api.Video", "https://api.com"}, + {"vonage:Url.Api.Video", "https://api.com"}, }).Build()) .VonageUrls.Video.Should().Be(new Uri("https://api.com")); diff --git a/Vonage.Test/Conversations/E2EBase.cs b/Vonage.Test/Conversations/E2EBase.cs index 7df61b5c2..c232e6ca7 100644 --- a/Vonage.Test/Conversations/E2EBase.cs +++ b/Vonage.Test/Conversations/E2EBase.cs @@ -12,5 +12,5 @@ public class E2EBase protected E2EBase(string serializationNamespace) : this() => this.Serialization = new SerializationTestHelper(serializationNamespace, JsonSerializerBuilder.BuildWithSnakeCase()); - protected E2EBase() => this.Helper = TestingContext.WithBearerCredentials("Vonage.Url.Api"); + protected E2EBase() => this.Helper = TestingContext.WithBearerCredentials("Url.Api"); } \ No newline at end of file diff --git a/Vonage.Test/Extensions/ServiceCollectionExtensionsTest.cs b/Vonage.Test/Extensions/ServiceCollectionExtensionsTest.cs index 7eeb7a355..c089a270c 100644 --- a/Vonage.Test/Extensions/ServiceCollectionExtensionsTest.cs +++ b/Vonage.Test/Extensions/ServiceCollectionExtensionsTest.cs @@ -35,7 +35,7 @@ public class ServiceCollectionExtensionsTest private readonly IConfigurationRoot configuration = new ConfigurationBuilder() .AddInMemoryCollection(new Dictionary { - {"appSettings:Vonage_key", "RandomValue"}, + {"vonage:Vonage_key", "RandomValue"}, }) .Build(); diff --git a/Vonage.Test/Meetings/E2EBase.cs b/Vonage.Test/Meetings/E2EBase.cs index 73111d5aa..da25c450a 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("Vonage.Url.Api.Europe"); + this.Helper = TestingContext.WithBearerCredentials("Url.Api.Europe"); this.Serialization = new SerializationTestHelper(serializationNamespace, JsonSerializerBuilder.BuildWithSnakeCase()); } diff --git a/Vonage.Test/NumberInsightsV2/FraudCheck/E2ETest.cs b/Vonage.Test/NumberInsightsV2/FraudCheck/E2ETest.cs index 0d93250a8..22860b7bd 100644 --- a/Vonage.Test/NumberInsightsV2/FraudCheck/E2ETest.cs +++ b/Vonage.Test/NumberInsightsV2/FraudCheck/E2ETest.cs @@ -14,7 +14,7 @@ namespace Vonage.Test.NumberInsightsV2.FraudCheck; [Trait("Category", "E2E")] public class E2ETest { - private const string ApiUrl = "Vonage.Url.Api"; + private const string ApiUrl = "Url.Api"; private readonly SerializationTestHelper serialization = new SerializationTestHelper(typeof(E2ETest).Namespace, JsonSerializerBuilder.BuildWithSnakeCase()); diff --git a/Vonage.Test/ProactiveConnect/E2EBase.cs b/Vonage.Test/ProactiveConnect/E2EBase.cs index 66c7ca71d..91b92902c 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("Vonage.Url.Api.Europe"); + this.Helper = TestingContext.WithBearerCredentials("Url.Api.Europe"); this.Serialization = new SerializationTestHelper(serializationNamespace, JsonSerializerBuilder.BuildWithSnakeCase()); } diff --git a/Vonage.Test/SubAccounts/E2EBase.cs b/Vonage.Test/SubAccounts/E2EBase.cs index 36ded86f7..f71d13242 100644 --- a/Vonage.Test/SubAccounts/E2EBase.cs +++ b/Vonage.Test/SubAccounts/E2EBase.cs @@ -11,7 +11,7 @@ public abstract class E2EBase protected E2EBase(string serializationNamespace) { - this.Helper = TestingContext.WithBasicCredentials("Vonage.Url.Api"); + this.Helper = TestingContext.WithBasicCredentials("Url.Api"); this.Serialization = new SerializationTestHelper(serializationNamespace, JsonSerializerBuilder.BuildWithSnakeCase()); } diff --git a/Vonage.Test/TestHelpers/TestingContext.cs b/Vonage.Test/TestHelpers/TestingContext.cs index 6a8c24d86..72620b978 100644 --- a/Vonage.Test/TestHelpers/TestingContext.cs +++ b/Vonage.Test/TestHelpers/TestingContext.cs @@ -16,7 +16,7 @@ private TestingContext(string appSettingsKey, Credentials credentials, string au { Settings = { - [$"appSettings:{appSettingsKey}"] = this.Server.Url, + [$"vonage:{appSettingsKey}"] = this.Server.Url, }, }; this.VonageClient = new VonageClient(credentials, configuration, new TimeProvider()); diff --git a/Vonage.Test/Users/E2EBase.cs b/Vonage.Test/Users/E2EBase.cs index 0c7b09736..5a1e180d1 100644 --- a/Vonage.Test/Users/E2EBase.cs +++ b/Vonage.Test/Users/E2EBase.cs @@ -17,7 +17,7 @@ public class E2EBase protected E2EBase(string serializationNamespace) : this() => this.Serialization = new SerializationTestHelper(serializationNamespace, JsonSerializerBuilder.BuildWithSnakeCase()); - protected E2EBase() => this.Helper = TestingContext.WithBearerCredentials("Vonage.Url.Api"); + protected E2EBase() => this.Helper = TestingContext.WithBearerCredentials("Url.Api"); internal static void VerifyUser(User success) { diff --git a/Vonage.Test/VerifyV2/E2EBase.cs b/Vonage.Test/VerifyV2/E2EBase.cs index bcd827b36..b3e0b120c 100644 --- a/Vonage.Test/VerifyV2/E2EBase.cs +++ b/Vonage.Test/VerifyV2/E2EBase.cs @@ -12,5 +12,5 @@ public class E2EBase protected E2EBase(string serializationNamespace) : this() => this.Serialization = new SerializationTestHelper(serializationNamespace, JsonSerializerBuilder.BuildWithSnakeCase()); - protected E2EBase() => this.Helper = TestingContext.WithBearerCredentials("Vonage.Url.Api"); + protected E2EBase() => this.Helper = TestingContext.WithBearerCredentials("Url.Api"); } \ No newline at end of file diff --git a/Vonage.Test/Video/E2EBase.cs b/Vonage.Test/Video/E2EBase.cs index a24fae194..1ea91f397 100644 --- a/Vonage.Test/Video/E2EBase.cs +++ b/Vonage.Test/Video/E2EBase.cs @@ -8,7 +8,7 @@ public abstract class E2EBase { internal readonly TestingContext Helper; internal readonly SerializationTestHelper Serialization; - private E2EBase() => this.Helper = TestingContext.WithBearerCredentials("Vonage.Url.Api.Video"); + private E2EBase() => this.Helper = TestingContext.WithBearerCredentials("Url.Api.Video"); protected E2EBase(string serializationNamespace) : this() => this.Serialization = new SerializationTestHelper(serializationNamespace, diff --git a/Vonage/Configuration.cs b/Vonage/Configuration.cs index 800575af8..016fb95f1 100644 --- a/Vonage/Configuration.cs +++ b/Vonage/Configuration.cs @@ -19,11 +19,6 @@ public sealed class Configuration { private const string LoggerCategory = "Vonage.Configuration"; - private static Maybe RequestsPerSecond => - double.TryParse(Instance.Settings["appSettings:Vonage.RequestsPerSecond"], out var requestsPerSecond) - ? requestsPerSecond - : Maybe.None; - static Configuration() { } @@ -34,25 +29,43 @@ private Configuration(IConfiguration configuration) this.LogAuthenticationCapabilities(LogProvider.GetLogger(LoggerCategory)); } + internal Configuration() + { + var builder = new ConfigurationBuilder() + .AddInMemoryCollection(new Dictionary + { + {"vonage:EnsureSuccessStatusCode", "false"}, + }) + .AddJsonFile("settings.json", true, true) + .AddJsonFile("appsettings.json", true, true); + this.Settings = builder.Build(); + this.LogAuthenticationCapabilities(LogProvider.GetLogger(LoggerCategory)); + } + + private static Maybe RequestsPerSecond => + double.TryParse(Instance.Settings["vonage:RequestsPerSecond"], out var requestsPerSecond) + ? requestsPerSecond + : Maybe.None; + /// /// Retrieves the Api secret. /// - public string ApiKey => this.Settings["appSettings:Vonage_key"] ?? string.Empty; + public string ApiKey => this.Settings["vonage:Api.Key"] ?? string.Empty; /// /// Retrieves the Api secret. /// - public string ApiSecret => this.Settings["appSettings:Vonage_secret"] ?? string.Empty; + public string ApiSecret => this.Settings["vonage:Api.Secret"] ?? string.Empty; /// /// Retrieves the Application Id. /// - public string ApplicationId => this.Settings["appSettings:Vonage.Application.Id"] ?? string.Empty; + public string ApplicationId => this.Settings["vonage:Application.Id"] ?? string.Empty; /// /// Retrieves the Application Key. /// - public string ApplicationKey => this.Settings["appSettings:Vonage.Application.Key"] ?? string.Empty; + public string ApplicationKey => this.Settings["vonage:Application.Key"] ?? string.Empty; /// /// Retrieves a configured HttpClient. @@ -90,15 +103,15 @@ public HttpClient Client /// Retrieves the Nexmo Api Url. /// [Obsolete("Favor the VonageUrls property instead.")] - public Uri NexmoApiUrl => this.Settings["appSettings:Vonage.Url.Api"] is null + public Uri NexmoApiUrl => this.Settings["vonage:Url.Api"] is null ? this.VonageUrls.Nexmo - : new Uri(this.Settings["appSettings:Vonage.Url.Api"]); + : new Uri(this.Settings["vonage:Url.Api"]); /// /// The timeout (in seconds) applied to every request. If not provided, the default timeout will be applied. /// public Maybe RequestTimeout => - int.TryParse(this.Settings["appSettings:Vonage.RequestTimeout"], out var timeout) + int.TryParse(this.Settings["vonage:RequestTimeout"], out var timeout) ? Maybe.Some(TimeSpan.FromSeconds(timeout)) : Maybe.None; @@ -106,14 +119,14 @@ public HttpClient Client /// Retrieves the Rest Api Url. /// [Obsolete("Favor the VonageUrls property instead.")] - public Uri RestApiUrl => this.Settings["appSettings:Vonage.Url.Rest"] is null + public Uri RestApiUrl => this.Settings["vonage:Url.Rest"] is null ? this.VonageUrls.Rest - : new Uri(this.Settings["appSettings:Vonage.Url.Rest"]); + : new Uri(this.Settings["vonage:Url.Rest"]); /// /// Retrieves the Security Secret. /// - public string SecuritySecret => this.Settings["appSettings:Vonage.security_secret"] ?? string.Empty; + public string SecuritySecret => this.Settings["vonage:Security_secret"] ?? string.Empty; /// /// Exposes the configuration's content. @@ -123,39 +136,26 @@ public HttpClient Client /// /// Retrieves the SigningMethod. /// - public string SigningMethod => this.Settings["appSettings:Vonage.signing_method"] ?? string.Empty; + public string SigningMethod => this.Settings["vonage:Signing_method"] ?? string.Empty; /// /// Retrieves the User Agent. /// - public string UserAgent => this.Settings["appSettings:Vonage.UserAgent"] ?? string.Empty; + 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["appSettings:Vonage.Url.Api.Video"] is null + public Uri VideoApiUrl => this.Settings["vonage:Url.Api.Video"] is null ? this.VonageUrls.Video - : new Uri(this.Settings["appSettings:Vonage.Url.Api.Video"]); + : new Uri(this.Settings["vonage:Url.Api.Video"]); /// /// Provide urls to all Vonage APIs. /// public VonageUrls VonageUrls => VonageUrls.FromConfiguration(this.Settings); - internal Configuration() - { - var builder = new ConfigurationBuilder() - .AddInMemoryCollection(new Dictionary - { - {"appSettings:Vonage.EnsureSuccessStatusCode", "false"}, - }) - .AddJsonFile("settings.json", true, true) - .AddJsonFile("appsettings.json", true, true); - this.Settings = builder.Build(); - this.LogAuthenticationCapabilities(LogProvider.GetLogger(LoggerCategory)); - } - /// /// Builds a Credentials from the current Configuration. /// @@ -195,9 +195,9 @@ private static TimeSpanSemaphore BuildSemaphore(double requestsPerSecond) } private Uri FetchApiUrlEurope() => - this.Settings["appSettings:Vonage.Url.Api.Europe"] is null + this.Settings["vonage:Url.Api.Europe"] is null ? this.VonageUrls.Get(VonageUrls.Region.EU) - : new Uri(this.Settings["appSettings:Vonage.Url.Api.Europe"]); + : new Uri(this.Settings["vonage:Url.Api.Europe"]); private ThrottlingMessageHandler GetThrottlingMessageHandler(TimeSpanSemaphore semaphore) => this.ClientHandler != null @@ -213,13 +213,13 @@ private void LogAuthenticationCapabilities(ILogger logger) authCapabilities.Add("Key/Secret"); } - if (!string.IsNullOrWhiteSpace(this.Settings["appSettings:Vonage.security_secret"])) + if (!string.IsNullOrWhiteSpace(this.Settings["vonage:Security_secret"])) { authCapabilities.Add("Security/Signing"); } - if (!string.IsNullOrWhiteSpace(this.Settings["appSettings:Vonage.Application.Id"]) && - !string.IsNullOrWhiteSpace(this.Settings["appSettings:Vonage.Application.Key"])) + if (!string.IsNullOrWhiteSpace(this.Settings["vonage:Application.Id"]) && + !string.IsNullOrWhiteSpace(this.Settings["vonage:Application.Key"])) { authCapabilities.Add("Application"); } @@ -246,9 +246,9 @@ public readonly struct VonageUrls private const string DefaultNexmoApiUrl = "https://api.nexmo.com"; private const string DefaultRestApiUrl = "https://rest.nexmo.com"; private const string DefaultVideoApiUrl = "https://video.api.vonage.com"; - private const string NexmoApiKey = "appSettings:Vonage.Url.Api"; - private const string NexmoRestKey = "appSettings:Vonage.Url.Rest"; - private const string VideoApiKey = "appSettings:Vonage.Url.Api.Video"; + private const string NexmoApiKey = "vonage:Url.Api"; + private const string NexmoRestKey = "vonage:Url.Rest"; + private const string VideoApiKey = "vonage:Url.Api.Video"; private readonly Dictionary regions = new Dictionary { diff --git a/Vonage/Request/Credentials.cs b/Vonage/Request/Credentials.cs index 7ef5a31d4..42892dfd6 100644 --- a/Vonage/Request/Credentials.cs +++ b/Vonage/Request/Credentials.cs @@ -2,7 +2,6 @@ using System.IO; using System.Net.Http.Headers; using System.Text; -using Microsoft.Extensions.Configuration; using Vonage.Common.Failures; using Vonage.Common.Monads; using Vonage.Cryptography; @@ -182,7 +181,7 @@ public Result GetPreferredAuthenticationType() /// /// The user agent. public string GetUserAgent() => - this.AppUserAgent ?? Configuration.Instance.Settings["appSettings:Vonage.UserAgent"]; + this.AppUserAgent ?? Configuration.Instance.Settings["vonage:Vonage.UserAgent"]; private Result GetPreferredAuthenticationHeader(AuthType authenticationType) => authenticationType switch