Skip to content
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

Merged
merged 25 commits into from
Jun 20, 2023
Merged

feat: subaccounts #431

merged 25 commits into from
Jun 20, 2023

Conversation

Tr00d
Copy link
Contributor

@Tr00d Tr00d commented Jun 13, 2023

Implementation of SubAccounts.
The previous (incomplete) implementation has been flagged as obsolete and will be removed in the next major version.

@Tr00d Tr00d added the feature label Jun 13, 2023
@Tr00d Tr00d marked this pull request as draft June 13, 2023 12:06
@sonarcloud
Copy link

sonarcloud bot commented Jun 16, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 4 Code Smells

100.0% 100.0% Coverage
0.0% 0.0% Duplication

@Tr00d Tr00d marked this pull request as ready for review June 20, 2023 05:20
.WithNumber(this.fixture.Create<string>())
.WithCountry(StringHelper.GenerateString(2))
.Create()
.Map(request => request.WithApiKey("489dsSS564652"))
Copy link

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.

Copy link
Contributor Author

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
Copy link

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?

Copy link
Contributor Author

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()
Copy link

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.

Copy link
Contributor Author

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."));

@Tr00d Tr00d requested a review from SMadani June 20, 2023 10:52
@Tr00d Tr00d merged commit 29b03c2 into main Jun 20, 2023
6 checks passed
@Tr00d Tr00d deleted the devx-7402-subaccounts branch June 20, 2023 14:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants