-
Notifications
You must be signed in to change notification settings - Fork 82
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: subaccounts #431
feat: subaccounts #431
Conversation
Kudos, SonarCloud Quality Gate passed! |
.WithNumber(this.fixture.Create<string>()) | ||
.WithCountry(StringHelper.GenerateString(2)) | ||
.Create() | ||
.Map(request => request.WithApiKey("489dsSS564652")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that API keys are 8 hex characters.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't any other verification on ApiKeys in the SDK, they consider it a simple string everywhere else.
I'll add that.
|
||
namespace Vonage.SubAccounts.CreateSubAccount; | ||
|
||
internal class CreateSubAccountRequestBuilder : IBuilderForName, IBuilderForOptional |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the point of these interfaces?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The initializer returns an IBuilderForName that forces the customer to set a name and then returns an IBuildForOptional that allows setting optional values. TLDR: creating a CreateSubAccountRequest without a name is not possible
They help with Mandatory/Optional fields, and I can direct the customer where I want.
/// <inheritdoc /> | ||
public string GetEndpointPath() => $"/accounts/{this.ApiKey}/subaccounts/{this.SubAccountKey}"; | ||
|
||
private StringContent GetRequestContent() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If no properties are set, an exception should be thrown because the API will return a 400.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exactly. The validation is on the builder, as it's responsible for building and, therefore, parsing.
Following "Parse, Don't Validate", my Request instance is always valid, because an invalid instance cannot be created.
private static Result<UpdateSubAccountRequest> VerifyAtLeastOneUpdate(UpdateSubAccountRequest request) =>
request.Name.IsSome || request.UsePrimaryAccountBalance.IsSome || request.Suspended.IsSome
? request
: Result<UpdateSubAccountRequest>.FromFailure(ResultFailure.FromErrorMessage("No property was modified."));
Implementation of SubAccounts.
The previous (incomplete) implementation has been flagged as
obsolete
and will be removed in the next major version.