Skip to content

Commit

Permalink
refactor: [breaking] replace 'appSettings' key by 'vonage' (#550)
Browse files Browse the repository at this point in the history
* Replace 'appSettings' key by 'vonage'

* fix: update value after merge conflict

* fix: merge conflicts

* Update key/value pair under vonage settings
  • Loading branch information
Tr00d committed Mar 13, 2024
1 parent e473554 commit d1f245e
Show file tree
Hide file tree
Showing 14 changed files with 98 additions and 105 deletions.
64 changes: 29 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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"
Expand Down
36 changes: 18 additions & 18 deletions Vonage.Test/ConfigurationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void FromConfiguration_ShouldCreateEmptyConfiguration_GivenConfigurationC
Configuration.FromConfiguration(new ConfigurationBuilder()
.AddInMemoryCollection(new Dictionary<string, string>
{
{"appSettings:Vonage_key", "RandomValue"},
{"vonage:Api.Key", "RandomValue"},
})
.Build()).ApiKey.Should().Be("RandomValue");

Expand All @@ -55,7 +55,7 @@ public void FromConfiguration_ShouldCreateEmptyConfiguration_GivenConfigurationC
Configuration.FromConfiguration(new ConfigurationBuilder()
.AddInMemoryCollection(new Dictionary<string, string>
{
{"appSettings:Vonage_secret", "RandomValue"},
{"vonage:Api.Secret", "RandomValue"},
})
.Build()).ApiSecret.Should().Be("RandomValue");

Expand All @@ -64,7 +64,7 @@ public void FromConfiguration_ShouldCreateEmptyConfiguration_GivenConfigurationC
Configuration.FromConfiguration(new ConfigurationBuilder()
.AddInMemoryCollection(new Dictionary<string, string>
{
{"appSettings:Vonage.Application.Id", "RandomValue"},
{"vonage:Application.Id", "RandomValue"},
})
.Build()).ApplicationId.Should().Be("RandomValue");

Expand All @@ -73,7 +73,7 @@ public void FromConfiguration_ShouldCreateEmptyConfiguration_GivenConfigurationC
Configuration.FromConfiguration(new ConfigurationBuilder()
.AddInMemoryCollection(new Dictionary<string, string>
{
{"appSettings:Vonage.Application.Key", "RandomValue"},
{"vonage:Application.Key", "RandomValue"},
})
.Build()).ApplicationKey.Should().Be("RandomValue");

Expand All @@ -82,7 +82,7 @@ public void FromConfiguration_ShouldCreateEmptyConfiguration_GivenConfigurationC
Configuration.FromConfiguration(new ConfigurationBuilder()
.AddInMemoryCollection(new Dictionary<string, string>
{
{"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"));

Expand All @@ -91,7 +91,7 @@ public void FromConfiguration_ShouldCreateEmptyConfiguration_GivenConfigurationC
Configuration.FromConfiguration(new ConfigurationBuilder()
.AddInMemoryCollection(new Dictionary<string, string>
{
{"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"));

Expand All @@ -100,7 +100,7 @@ public void FromConfiguration_ShouldCreateEmptyConfiguration_GivenConfigurationC
Configuration.FromConfiguration(new ConfigurationBuilder()
.AddInMemoryCollection(new Dictionary<string, string>
{
{"appSettings:Vonage.RequestTimeout", "100"},
{"vonage:RequestTimeout", "100"},
})
.Build()).RequestTimeout.Should().BeSome(TimeSpan.FromSeconds(100));

Expand All @@ -109,7 +109,7 @@ public void FromConfiguration_ShouldCreateEmptyConfiguration_GivenConfigurationC
Configuration.FromConfiguration(new ConfigurationBuilder()
.AddInMemoryCollection(new Dictionary<string, string>
{
{"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"));

Expand All @@ -118,7 +118,7 @@ public void FromConfiguration_ShouldCreateEmptyConfiguration_GivenConfigurationC
Configuration.FromConfiguration(new ConfigurationBuilder()
.AddInMemoryCollection(new Dictionary<string, string>
{
{"appSettings:Vonage.security_secret", "RandomValue"},
{"vonage:Security_secret", "RandomValue"},
})
.Build()).SecuritySecret.Should().Be("RandomValue");

Expand All @@ -127,7 +127,7 @@ public void FromConfiguration_ShouldCreateEmptyConfiguration_GivenConfigurationC
Configuration.FromConfiguration(new ConfigurationBuilder()
.AddInMemoryCollection(new Dictionary<string, string>
{
{"appSettings:Vonage.signing_method", "sha512"},
{"vonage:Signing_method", "sha512"},
})
.Build()).SigningMethod.Should().Be("sha512");

Expand All @@ -136,7 +136,7 @@ public void FromConfiguration_ShouldCreateEmptyConfiguration_GivenConfigurationC
Configuration.FromConfiguration(new ConfigurationBuilder()
.AddInMemoryCollection(new Dictionary<string, string>
{
{"appSettings:Vonage.UserAgent", "RandomValue"},
{"vonage:UserAgent", "RandomValue"},
})
.Build()).UserAgent.Should().Be("RandomValue");

Expand All @@ -145,14 +145,14 @@ public void FromConfiguration_ShouldCreateEmptyConfiguration_GivenConfigurationC
Configuration.FromConfiguration(new ConfigurationBuilder()
.AddInMemoryCollection(new Dictionary<string, string>
{
{"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(
Expand All @@ -166,15 +166,15 @@ public void FromConfiguration_ShouldCreateEmptyConfiguration_GivenConfigurationC
public void VonageUrl_ShouldReturnCustomNexmoUrl_GivenConfigurationContainsDefaultUrl() =>
Configuration.FromConfiguration(new ConfigurationBuilder()
.AddInMemoryCollection(new Dictionary<string, string>
{{"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]
public void VonageUrl_ShouldReturnCustomRestUrl_GivenConfigurationContainsRestUrl() =>
Configuration.FromConfiguration(new ConfigurationBuilder().AddInMemoryCollection(
new Dictionary<string, string>
{
{"appSettings:Vonage.Url.Rest", "https://api.com"},
{"vonage:Url.Rest", "https://api.com"},
}).Build())
.VonageUrls.Rest.Should().Be(new Uri("https://api.com"));

Expand All @@ -183,7 +183,7 @@ public void FromConfiguration_ShouldCreateEmptyConfiguration_GivenConfigurationC
Configuration.FromConfiguration(new ConfigurationBuilder().AddInMemoryCollection(
new Dictionary<string, string>
{
{"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"));

Expand Down
2 changes: 1 addition & 1 deletion Vonage.Test/Conversations/E2EBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
2 changes: 1 addition & 1 deletion Vonage.Test/Extensions/ServiceCollectionExtensionsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class ServiceCollectionExtensionsTest
private readonly IConfigurationRoot configuration = new ConfigurationBuilder()
.AddInMemoryCollection(new Dictionary<string, string>
{
{"appSettings:Vonage_key", "RandomValue"},
{"vonage:Vonage_key", "RandomValue"},
})
.Build();

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("Vonage.Url.Api.Europe");
this.Helper = TestingContext.WithBearerCredentials("Url.Api.Europe");
this.Serialization =
new SerializationTestHelper(serializationNamespace, JsonSerializerBuilder.BuildWithSnakeCase());
}
Expand Down
2 changes: 1 addition & 1 deletion Vonage.Test/NumberInsightsV2/FraudCheck/E2ETest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
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("Vonage.Url.Api.Europe");
this.Helper = TestingContext.WithBearerCredentials("Url.Api.Europe");
this.Serialization =
new SerializationTestHelper(serializationNamespace, JsonSerializerBuilder.BuildWithSnakeCase());
}
Expand Down
2 changes: 1 addition & 1 deletion Vonage.Test/SubAccounts/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.WithBasicCredentials("Vonage.Url.Api");
this.Helper = TestingContext.WithBasicCredentials("Url.Api");
this.Serialization =
new SerializationTestHelper(serializationNamespace, JsonSerializerBuilder.BuildWithSnakeCase());
}
Expand Down
2 changes: 1 addition & 1 deletion Vonage.Test/TestHelpers/TestingContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion Vonage.Test/Users/E2EBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion Vonage.Test/VerifyV2/E2EBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
2 changes: 1 addition & 1 deletion Vonage.Test/Video/E2EBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading

0 comments on commit d1f245e

Please sign in to comment.