Skip to content

Commit

Permalink
Remaning number insight methods to remove confusion
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-lethargic committed May 25, 2022
1 parent c7c3299 commit 018153e
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 38 deletions.
14 changes: 7 additions & 7 deletions Vonage.Test.Unit/NumberInsightsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -694,14 +694,14 @@ public void TestAdvancedAsync(bool passCreds, bool kitchenSink)
//ACT
var creds = Request.Credentials.FromApiKeyAndSecret(ApiKey, ApiSecret);
var client = new VonageClient(creds);
AdvancedInsightsAsyncResponse response;
AdvancedInsightsAsynchronousResponse response;
if (passCreds)
{
response = client.NumberInsightClient.GetNumberInsightAsync(request, creds);
response = client.NumberInsightClient.GetNumberInsightAsynchronous(request, creds);
}
else
{
response = client.NumberInsightClient.GetNumberInsightAsync(request);
response = client.NumberInsightClient.GetNumberInsightAsynchronous(request);
}

//ASSERT
Expand Down Expand Up @@ -739,14 +739,14 @@ public async void TestAdvancedAsyncAsync(bool passCreds, bool kitchenSink)
//ACT
var creds = Request.Credentials.FromApiKeyAndSecret(ApiKey, ApiSecret);
var client = new VonageClient(creds);
AdvancedInsightsAsyncResponse response;
AdvancedInsightsAsynchronousResponse response;
if (passCreds)
{
response = await client.NumberInsightClient.GetNumberInsightAsyncAsync(request, creds);
response = await client.NumberInsightClient.GetNumberInsightAsynchronousAsync(request, creds);
}
else
{
response = await client.NumberInsightClient.GetNumberInsightAsyncAsync(request);
response = await client.NumberInsightClient.GetNumberInsightAsynchronousAsync(request);
}

//ASSERT
Expand All @@ -770,7 +770,7 @@ public void TestFailedAsyncRequest()
var client = new VonageClient(creds);
try
{
client.NumberInsightClient.GetNumberInsightAsync(request);
client.NumberInsightClient.GetNumberInsightAsynchronous(request);
//ASSERT
Assert.True(false, "Auto fail because request returned without throwing exception");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Vonage.NumberInsights
{
public class AdvancedInsightsAsyncResponse : NumberInsightResponseBase
public class AdvancedInsightsAsynchronousResponse : NumberInsightResponseBase
{
/// <summary>
/// The number in your request
Expand Down
14 changes: 5 additions & 9 deletions Vonage/NumberInsights/INumberInsightClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ public interface INumberInsightClient
/// <param name="request"></param>
/// <param name="creds"></param>
/// <returns></returns>
Task<StandardInsightResponse>
GetNumberInsightStandardAsync(StandardNumberInsightRequest request, Credentials creds = null);
Task<StandardInsightResponse> GetNumberInsightStandardAsync(StandardNumberInsightRequest request, Credentials creds = null);

/// <summary>
/// Provides advanced number insight information about a number synchronously, in the same way that the basic and standard endpoints do.
Expand All @@ -39,7 +38,7 @@ Task<AdvancedInsightsResponse> GetNumberInsightAdvancedAsync(AdvancedNumberInsig
/// <param name="request"></param>
/// <param name="creds"></param>
/// <returns></returns>
Task<AdvancedInsightsAsyncResponse> GetNumberInsightAsyncAsync(AdvancedNumberInsightAsynchronousRequest request,
Task<AdvancedInsightsAsynchronousResponse> GetNumberInsightAsynchronousAsync(AdvancedNumberInsightAsynchronousRequest request,
Credentials creds = null);

/// <summary>
Expand All @@ -56,8 +55,7 @@ Task<AdvancedInsightsAsyncResponse> GetNumberInsightAsyncAsync(AdvancedNumberIns
/// <param name="request"></param>
/// <param name="creds"></param>
/// <returns></returns>
StandardInsightResponse
GetNumberInsightStandard(StandardNumberInsightRequest request, Credentials creds = null);
StandardInsightResponse GetNumberInsightStandard(StandardNumberInsightRequest request, Credentials creds = null);

/// <summary>
/// Provides advanced number insight information about a number synchronously, in the same way that the basic and standard endpoints do.
Expand All @@ -66,8 +64,7 @@ Task<AdvancedInsightsAsyncResponse> GetNumberInsightAsyncAsync(AdvancedNumberIns
/// <param name="request"></param>
/// <param name="creds"></param>
/// <returns></returns>
AdvancedInsightsResponse GetNumberInsightAdvanced(AdvancedNumberInsightRequest request,
Credentials creds = null);
AdvancedInsightsResponse GetNumberInsightAdvanced(AdvancedNumberInsightRequest request, Credentials creds = null);

/// <summary>
/// Provides advanced number insight number information asynchronously using the URL specified in the callback parameter.
Expand All @@ -76,7 +73,6 @@ AdvancedInsightsResponse GetNumberInsightAdvanced(AdvancedNumberInsightRequest r
/// <param name="request"></param>
/// <param name="creds"></param>
/// <returns></returns>
AdvancedInsightsAsyncResponse GetNumberInsightAsync(AdvancedNumberInsightAsynchronousRequest request,
Credentials creds = null);
AdvancedInsightsAsynchronousResponse GetNumberInsightAsynchronous(AdvancedNumberInsightAsynchronousRequest request, Credentials creds = null);
}
}
40 changes: 19 additions & 21 deletions Vonage/NumberInsights/NumberInsightClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ public async Task<StandardInsightResponse> GetNumberInsightStandardAsync(Standar
return response;
}

public async Task<AdvancedInsightsResponse> GetNumberInsightAdvancedAsync(AdvancedNumberInsightRequest request,
Credentials creds = null)
public async Task<AdvancedInsightsResponse> GetNumberInsightAdvancedAsync(AdvancedNumberInsightRequest request, Credentials creds = null)
{
var response = await ApiRequest.DoGetRequestWithQueryParametersAsync<AdvancedInsightsResponse>(
ApiRequest.GetBaseUri(ApiRequest.UriType.Api, "/ni/advanced/json"),
Expand All @@ -48,9 +47,9 @@ public async Task<AdvancedInsightsResponse> GetNumberInsightAdvancedAsync(Advanc
return response;
}

public async Task<AdvancedInsightsAsyncResponse> GetNumberInsightAsyncAsync(AdvancedNumberInsightAsynchronousRequest request, Credentials creds = null)
public async Task<AdvancedInsightsAsynchronousResponse> GetNumberInsightAsynchronousAsync(AdvancedNumberInsightAsynchronousRequest request, Credentials creds = null)
{
var response = await ApiRequest.DoGetRequestWithQueryParametersAsync<AdvancedInsightsAsyncResponse>(
var response = await ApiRequest.DoGetRequestWithQueryParametersAsync<AdvancedInsightsAsynchronousResponse>(
ApiRequest.GetBaseUri(ApiRequest.UriType.Api, "/ni/advanced/async/json"),
ApiRequest.AuthType.Query,
request,
Expand All @@ -60,21 +59,6 @@ public async Task<AdvancedInsightsAsyncResponse> GetNumberInsightAsyncAsync(Adva
return response;
}

public void ValidateNumberInsightResponse(NumberInsightResponseBase response)
{
if (response.Status != 0)
{
if(response is AdvancedInsightsAsyncResponse asyncResponse)
{
throw new VonageNumberInsightResponseException($"Advanced Insights Async response failed with status: {asyncResponse.Status}") { Response = response};
}
else if(response is BasicInsightResponse basicInsightResponse)
{
throw new VonageNumberInsightResponseException($"Number insight request failed with status: {basicInsightResponse.Status} and error message: {basicInsightResponse.StatusMessage}") { Response=response};
}
}
}

public BasicInsightResponse GetNumberInsightBasic(BasicNumberInsightRequest request, Credentials creds = null)
{
var response = ApiRequest.DoGetRequestWithQueryParameters<BasicInsightResponse>(
Expand Down Expand Up @@ -111,9 +95,9 @@ public AdvancedInsightsResponse GetNumberInsightAdvanced(AdvancedNumberInsightRe
return response;
}

public AdvancedInsightsAsyncResponse GetNumberInsightAsync(AdvancedNumberInsightAsynchronousRequest request, Credentials creds = null)
public AdvancedInsightsAsynchronousResponse GetNumberInsightAsynchronous(AdvancedNumberInsightAsynchronousRequest request, Credentials creds = null)
{
var response = ApiRequest.DoGetRequestWithQueryParameters<AdvancedInsightsAsyncResponse>(
var response = ApiRequest.DoGetRequestWithQueryParameters<AdvancedInsightsAsynchronousResponse>(
ApiRequest.GetBaseUri(ApiRequest.UriType.Api, "/ni/advanced/async/json"),
ApiRequest.AuthType.Query,
request,
Expand All @@ -122,5 +106,19 @@ public AdvancedInsightsAsyncResponse GetNumberInsightAsync(AdvancedNumberInsight
ValidateNumberInsightResponse(response);
return response;
}

public void ValidateNumberInsightResponse(NumberInsightResponseBase response)
{
if (response.Status != 0)
{
switch (response)
{
case AdvancedInsightsAsynchronousResponse asyncResponse:
throw new VonageNumberInsightResponseException($"Advanced Insights Async response failed with status: {asyncResponse.Status}") { Response = response};
case BasicInsightResponse basicInsightResponse:
throw new VonageNumberInsightResponseException($"Number insight request failed with status: {basicInsightResponse.Status} and error message: {basicInsightResponse.StatusMessage}") { Response=response};
}
}
}
}
}

0 comments on commit 018153e

Please sign in to comment.