Skip to content

Commit

Permalink
feat: setup base structure for Number Insight V2
Browse files Browse the repository at this point in the history
  • Loading branch information
Tr00d committed Nov 29, 2023
1 parent 0e25394 commit f906166
Show file tree
Hide file tree
Showing 11 changed files with 209 additions and 0 deletions.
19 changes: 19 additions & 0 deletions Vonage.Test.Unit/NumberInsightsV2/E2EBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Vonage.Common;
using Vonage.Common.Test;
using Vonage.Test.Unit.TestHelpers;

namespace Vonage.Test.Unit.NumberInsightsV2
{
public abstract class E2EBase
{
protected E2EBase(string serializationNamespace)
{
this.Helper = E2EHelper.WithBasicCredentials("Vonage.Url.Api");
this.Serialization =
new SerializationTestHelper(serializationNamespace, JsonSerializer.BuildWithSnakeCase());
}

internal readonly E2EHelper Helper;
internal readonly SerializationTestHelper Serialization;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"request_id": "6cb4c489-0fc8-4c40-8c3d-95e7e74f9450",
"type": "phone",
"phone": {
"phone": "16197363066",
"carrier": "Orange France",
"type": "MOBILE"
},
"fraud_score": {
"risk_score": "54",
"risk_recommendation": "flag",
"label": "medium",
"status": "completed"
},
"sim_swap": {
"status": "failed",
"reason": "Mobile Network Operator Not Supported"
}
}
33 changes: 33 additions & 0 deletions Vonage.Test.Unit/NumberInsightsV2/FraudCheck/E2ETest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System.Net;
using System.Threading.Tasks;
using Vonage.Common.Test.Extensions;
using Vonage.NumberInsightV2.FraudCheck;
using WireMock.ResponseBuilders;
using Xunit;

namespace Vonage.Test.Unit.NumberInsightsV2.FraudCheck
{
[Trait("Category", "E2E")]
public class E2ETest : E2EBase
{
public E2ETest() : base(typeof(E2ETest).Namespace)
{
}

[Fact]
public async Task CreateEmptyUser()
{
this.Helper.Server.Given(WireMock.RequestBuilders.Request.Create()
.WithPath("/v2/ni")
.WithHeader("Authorization", "Basic NzkwZmM1ZTU6QWEzNDU2Nzg5")
.WithBody(this.Serialization.GetRequestJson(nameof(SerializationTest
.ShouldDeserialize200WithFraudScoreAndSimSwap)))
.UsingPost())
.RespondWith(Response.Create().WithStatusCode(HttpStatusCode.OK));
await this.Helper.VonageClient.NumberInsightV2Client
.PerformFraudCheckAsync(FraudCheckRequest.Build())
.Should()
.BeSuccessAsync();
}
}
}
17 changes: 17 additions & 0 deletions Vonage.Test.Unit/NumberInsightsV2/FraudCheck/SerializationTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using Vonage.Common;
using Vonage.Common.Test;
using Xunit;

namespace Vonage.Test.Unit.NumberInsightsV2.FraudCheck
{
public class SerializationTest
{
private readonly SerializationTestHelper helper = new SerializationTestHelper(
typeof(SerializationTest).Namespace,
JsonSerializer.BuildWithSnakeCase());

[Fact]
public void ShouldDeserialize200WithFraudScoreAndSimSwap() => throw new NotImplementedException();
}
}
3 changes: 3 additions & 0 deletions Vonage.Test.Unit/Vonage.Test.Unit.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -890,6 +890,9 @@
<None Update="VerifyV2\StartVerification\Data\ShouldSerializeSilentAuthWorkflowWithRedirectUrl-request.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="NumberInsightsV2\FraudCheck\Data\ShouldDeserialize200WithFraudScoreAndSimSwap-response.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<Target Name="PreBuild" BeforeTargets="PreBuildEvent">
<Exec Command="node ../.scripts/init.js"/>
Expand Down
18 changes: 18 additions & 0 deletions Vonage/NumberInsightV2/FraudCheck/FraudCheckRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using System.Net.Http;
using Vonage.Common.Client;
using Vonage.Common.Monads;

namespace Vonage.NumberInsightV2.FraudCheck;

public struct FraudCheckRequest : IVonageRequest
{
public static Result<FraudCheckRequest> Build()
{
throw new NotImplementedException();
}

public HttpRequestMessage BuildRequestMessage() => throw new NotImplementedException();

public string GetEndpointPath() => throw new NotImplementedException();
}
51 changes: 51 additions & 0 deletions Vonage/NumberInsightV2/FraudCheck/FraudCheckRequestBuilder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using System;
using Vonage.Common.Client;
using Vonage.Common.Monads;

namespace Vonage.NumberInsightV2.FraudCheck;

internal class FraudCheckRequestBuilder : IBuilderForPhone, IBuilderForOptional
{
/// <inheritdoc />
public Result<FraudCheckRequest> Create() => throw new NotImplementedException();

/// <inheritdoc />
public IBuilderForOptional WithFraudScore() => throw new NotImplementedException();

/// <inheritdoc />
public IBuilderForOptional WithPhone(string value) => throw new NotImplementedException();

/// <inheritdoc />
public IBuilderForOptional WithSimSwap() => throw new NotImplementedException();
}

/// <summary>
/// Represents a builder for Phone.
/// </summary>
public interface IBuilderForPhone
{
/// <summary>
/// Sets the Phone.
/// </summary>
/// <param name="value">The phone.</param>
/// <returns>The builder.</returns>
IBuilderForOptional WithPhone(string value);
}

/// <summary>
/// Represents a builder for optional values.
/// </summary>
public interface IBuilderForOptional : IVonageRequestBuilder<FraudCheckRequest>
{
/// <summary>
/// Enables Fraud Score in the response.
/// </summary>
/// <returns>The builder.</returns>
IBuilderForOptional WithFraudScore();

/// <summary>
/// Enables Sim Swap in the response.
/// </summary>
/// <returns>The builder.</returns>
IBuilderForOptional WithSimSwap();
}
5 changes: 5 additions & 0 deletions Vonage/NumberInsightV2/FraudCheck/FraudCheckResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
namespace Vonage.NumberInsightV2.FraudCheck;

public class FraudCheckResponse
{
}
18 changes: 18 additions & 0 deletions Vonage/NumberInsightV2/INumberInsightV2Client.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System.Threading.Tasks;
using Vonage.Common.Monads;
using Vonage.NumberInsightV2.FraudCheck;

namespace Vonage.NumberInsightV2;

/// <summary>
/// Exposes Number Insight V2 features.
/// </summary>
public interface INumberInsightV2Client
{
/// <summary>
/// Performs a fraud check request with a phone number.
/// </summary>
/// <param name="request">The request.</param>
/// <returns>A result indicating if the request whether succeeded or failed.</returns>
Task<Result<FraudCheckResponse>> PerformFraudCheckAsync(Result<FraudCheckRequest> request);
}
18 changes: 18 additions & 0 deletions Vonage/NumberInsightV2/NumberInsightV2Client.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using System.Threading.Tasks;
using Vonage.Common.Client;
using Vonage.Common.Monads;
using Vonage.NumberInsightV2.FraudCheck;

namespace Vonage.NumberInsightV2;

internal class NumberInsightV2Client : INumberInsightV2Client
{
public NumberInsightV2Client(VonageHttpClientConfiguration buildConfiguration)
{
throw new NotImplementedException();
}

public Task<Result<FraudCheckResponse>> PerformFraudCheckAsync(Result<FraudCheckRequest> request) =>
throw new NotImplementedException();
}
8 changes: 8 additions & 0 deletions Vonage/VonageClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Vonage.Messages;
using Vonage.Messaging;
using Vonage.NumberInsights;
using Vonage.NumberInsightV2;
using Vonage.Numbers;
using Vonage.Pricing;
using Vonage.ProactiveConnect;
Expand Down Expand Up @@ -64,6 +65,11 @@ public Credentials Credentials

public INumberInsightClient NumberInsightClient { get; private set; }

/// <summary>
/// Exposes Number Insight V2 features.
/// </summary>
public INumberInsightV2Client NumberInsightV2Client { get; private set; }

public INumbersClient NumbersClient { get; private set; }

public IPricingClient PricingClient { get; private set; }
Expand Down Expand Up @@ -153,6 +159,8 @@ private void PropagateCredentials()
this.SubAccountsClient = new SubAccountsClient(
this.BuildConfiguration(this.InitializeHttpClient(this.GetConfiguration().NexmoApiUrl)),
this.Credentials.ApiKey);
this.NumberInsightV2Client = new NumberInsightV2Client(
this.BuildConfiguration(this.InitializeHttpClient(this.GetConfiguration().NexmoApiUrl)));
this.UsersClient =
new UsersClient(this.BuildConfiguration(this.InitializeHttpClient(this.GetConfiguration().NexmoApiUrl)));
this.MeetingsClient = new MeetingsClient(
Expand Down

0 comments on commit f906166

Please sign in to comment.