Skip to content

Commit

Permalink
refactor: [breaking] remove sync methods from ShortCodesClient
Browse files Browse the repository at this point in the history
  • Loading branch information
Tr00d committed Mar 14, 2024
1 parent 6e07991 commit d3d7627
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 164 deletions.
119 changes: 0 additions & 119 deletions Vonage.Test/ShortCodeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,48 +10,6 @@ namespace Vonage.Test;
[Trait("Category", "Legacy")]
public class ShortCodeTests : TestBase
{
[Theory]
[InlineData(true, false)]
[InlineData(true, true)]
[InlineData(false, true)]
[InlineData(false, false)]
public void SendAlert(bool passCredentials, bool useAllParameters)
{
//ARRANGE
var request = new AlertRequest
{
To = "16365553226",
};
var expectedUri = $"{this.RestUrl}/sc/us/alert/json?to={request.To}";
if (useAllParameters)
{
request.StatusReportReq = "1";
request.ClientRef = Guid.NewGuid().ToString();
request.Template = "Test Template";
request.Type = "text";
expectedUri +=
$"&status-report-req={request.StatusReportReq}&client-ref={request.ClientRef}&template={WebUtility.UrlEncode(request.Template)}&type={request.Type}";
}

var expectedResponseContent = this.GetResponseJson();
expectedUri += $"&api_key={this.ApiKey}&api_secret={this.ApiSecret}&";
this.Setup(expectedUri, expectedResponseContent);

//ACT
var creds = Credentials.FromApiKeyAndSecret(this.ApiKey, this.ApiSecret);
var client = this.BuildVonageClient(creds);
var response = client.ShortCodesClient.SendAlert(request, passCredentials ? creds : null);

//ASSERT
Assert.Equal("1", response.MessageCount);
Assert.NotEmpty(response.Messages);
var message = response.Messages[0];
Assert.Equal("delivered", message.Status);
Assert.Equal("abcdefg", message.MessageId);
Assert.Equal("16365553226", message.To);
Assert.Equal("0", message.ErrorCode);
}

[Theory]
[InlineData(true, false)]
[InlineData(true, true)]
Expand Down Expand Up @@ -94,33 +52,6 @@ public async Task SendAlertAsync(bool passCredentials, bool useAllParameters)
Assert.Equal("0", message.ErrorCode);
}

[Theory]
[InlineData(true)]
[InlineData(false)]
public void ManageOptIn(bool passCredentials)
{
//ARRANGE
var request = new OptInManageRequest
{
Msisdn = "15559301529",
};
var expectedResponseContent = this.GetResponseJson();
var expectedUri =
$"{this.RestUrl}/sc/us/alert/opt-in/manage/json?msisdn={request.Msisdn}&api_key={this.ApiKey}&api_secret={this.ApiSecret}&";
this.Setup(expectedUri, expectedResponseContent);

//ACT
var creds = Credentials.FromApiKeyAndSecret(this.ApiKey, this.ApiSecret);
var client = this.BuildVonageClient(creds);
var response = client.ShortCodesClient.ManageOptIn(request, passCredentials ? creds : null);

//ASSERT
Assert.Equal("15559301529", response.Msisdn);
Assert.True(response.OptIn);
Assert.Equal("2014-08-21 17:34:47", response.OptInDate);
Assert.False(response.OptOut);
}

[Theory]
[InlineData(true)]
[InlineData(false)]
Expand Down Expand Up @@ -148,36 +79,6 @@ public async Task ManageOptInAsync(bool passCredentials)
Assert.False(response.OptOut);
}

[Theory]
[InlineData(true, true)]
[InlineData(false, false)]
[InlineData(true, false)]
[InlineData(false, true)]
public void QueryOptIns(bool passCredentials, bool allParameters)
{
//ARRANGE
var request = new OptInQueryRequest();
var expectedUri = $"{this.RestUrl}/sc/us/alert/opt-in/query/json?";
if (allParameters)
{
request.Page = "1";
request.PageSize = "20";
expectedUri += $"page-size={request.PageSize}&page={request.Page}&";
}

var expectedResponseContent = this.GetResponseJson();
expectedUri += $"api_key={this.ApiKey}&api_secret={this.ApiSecret}&";
this.Setup(expectedUri, expectedResponseContent);

//ACT
var creds = Credentials.FromApiKeyAndSecret(this.ApiKey, this.ApiSecret);
var client = this.BuildVonageClient(creds);
var response = client.ShortCodesClient.QueryOptIns(request, passCredentials ? creds : null);

//ASSERT
Assert.Equal("3", response.OptInCount);
}

[Theory]
[InlineData(true, true)]
[InlineData(false, false)]
Expand Down Expand Up @@ -208,26 +109,6 @@ public async Task QueryOptInsAsync(bool passCredentials, bool allParameters)
Assert.Equal("3", response.OptInCount);
}

[Theory]
[InlineData(false)]
[InlineData(true)]
public void SendTwoFactorAuth(bool passCredentials)
{
//ARRANGE
var request = new TwoFactorAuthRequest();
var expectedUri = $"{this.RestUrl}/sc/us/2fa/json?api_key={this.ApiKey}&api_secret={this.ApiSecret}&";
var expectedResponseContent = this.GetResponseJson();
this.Setup(expectedUri, expectedResponseContent);

//ACT
var creds = Credentials.FromApiKeyAndSecret(this.ApiKey, this.ApiSecret);
var client = this.BuildVonageClient(creds);
var response = client.ShortCodesClient.SendTwoFactorAuth(request, passCredentials ? creds : null);

//ASSERT
Assert.Equal("1", response.MessageCount);
}

[Theory]
[InlineData(false)]
[InlineData(true)]
Expand Down
8 changes: 0 additions & 8 deletions Vonage/ShortCodes/IShortCodesClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,4 @@ public interface IShortCodesClient
Task<AlertResponse> SendAlertAsync(AlertRequest request, Credentials creds = null);

Task<TwoFactorAuthResponse> SendTwoFactorAuthAsync(TwoFactorAuthRequest request, Credentials creds = null);

OptInSearchResponse QueryOptIns(OptInQueryRequest request, Credentials creds = null);

OptInRecord ManageOptIn(OptInManageRequest request, Credentials creds = null);

AlertResponse SendAlert(AlertRequest request, Credentials creds = null);

TwoFactorAuthResponse SendTwoFactorAuth(TwoFactorAuthRequest request, Credentials creds = null);
}
37 changes: 0 additions & 37 deletions Vonage/ShortCodes/ShortCodesClient.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using System.Threading.Tasks;
using Vonage.Common;
using Vonage.Request;
Expand All @@ -25,15 +24,6 @@ internal ShortCodesClient(Credentials credentials, Configuration configuration,

public Credentials Credentials { get; set; }

/// <inheritdoc/>
[Obsolete("Favor asynchronous version instead.")]
public OptInRecord ManageOptIn(OptInManageRequest request, Credentials creds = null) =>
ApiRequest.Build(this.GetCredentials(creds), this.configuration, this.timeProvider)
.DoGetRequestWithQueryParameters<OptInRecord>(
ApiRequest.GetBaseUri(ApiRequest.UriType.Rest, this.configuration, "/sc/us/alert/opt-in/manage/json"),
AuthType.Query,
request);

/// <inheritdoc/>
public Task<OptInRecord> ManageOptInAsync(OptInManageRequest request, Credentials creds = null) =>
ApiRequest.Build(this.GetCredentials(creds), this.configuration, this.timeProvider)
Expand All @@ -42,15 +32,6 @@ internal ShortCodesClient(Credentials credentials, Configuration configuration,
AuthType.Query,
request);

/// <inheritdoc/>
[Obsolete("Favor asynchronous version instead.")]
public OptInSearchResponse QueryOptIns(OptInQueryRequest request, Credentials creds = null) =>
ApiRequest.Build(this.GetCredentials(creds), this.configuration, this.timeProvider)
.DoGetRequestWithQueryParameters<OptInSearchResponse>(
ApiRequest.GetBaseUri(ApiRequest.UriType.Rest, this.configuration, "/sc/us/alert/opt-in/query/json"),
AuthType.Query,
request);

/// <inheritdoc/>
public Task<OptInSearchResponse> QueryOptInsAsync(OptInQueryRequest request, Credentials creds = null) =>
ApiRequest.Build(this.GetCredentials(creds), this.configuration, this.timeProvider)
Expand All @@ -59,15 +40,6 @@ internal ShortCodesClient(Credentials credentials, Configuration configuration,
AuthType.Query,
request);

/// <inheritdoc/>
[Obsolete("Favor asynchronous version instead.")]
public AlertResponse SendAlert(AlertRequest request, Credentials creds = null) =>
ApiRequest.Build(this.GetCredentials(creds), this.configuration, this.timeProvider)
.DoGetRequestWithQueryParameters<AlertResponse>(
ApiRequest.GetBaseUri(ApiRequest.UriType.Rest, this.configuration, "/sc/us/alert/json"),
AuthType.Query,
request);

/// <inheritdoc/>
public Task<AlertResponse> SendAlertAsync(AlertRequest request, Credentials creds = null) =>
ApiRequest.Build(this.GetCredentials(creds), this.configuration, this.timeProvider)
Expand All @@ -76,15 +48,6 @@ internal ShortCodesClient(Credentials credentials, Configuration configuration,
AuthType.Query,
request);

/// <inheritdoc/>
[Obsolete("Favor asynchronous version instead.")]
public TwoFactorAuthResponse SendTwoFactorAuth(TwoFactorAuthRequest request, Credentials creds = null) =>
ApiRequest.Build(this.GetCredentials(creds), this.configuration, this.timeProvider)
.DoGetRequestWithQueryParameters<TwoFactorAuthResponse>(
ApiRequest.GetBaseUri(ApiRequest.UriType.Rest, this.configuration, "/sc/us/2fa/json"),
AuthType.Query,
request);

/// <inheritdoc/>
public Task<TwoFactorAuthResponse> SendTwoFactorAuthAsync(TwoFactorAuthRequest request, Credentials creds = null) =>
ApiRequest.Build(this.GetCredentials(creds), this.configuration, this.timeProvider)
Expand Down

0 comments on commit d3d7627

Please sign in to comment.