Skip to content

Commit

Permalink
Async calls implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
AzureAD\TomasValiunas committed Oct 6, 2020
1 parent b445e0c commit cbf2e85
Show file tree
Hide file tree
Showing 33 changed files with 335 additions and 311 deletions.
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

Vonage Client Library for .NET
===================================

Expand Down Expand Up @@ -209,7 +210,7 @@ var credentials = Credentials.FromApiKeyAndSecret(

var vonageClient = new VonageClient(credentials);

var response = vonageClient.SmsClient.SendAnSms(new Vonage.Messaging.SendSmsRequest()
var response = await vonageClient.SmsClient.SendAnSmsAsync(new Vonage.Messaging.SendSmsRequest()
{
To = TO_NUMBER,
From = VONAGE_BRAND_NAME,
Expand Down Expand Up @@ -337,7 +338,7 @@ Use [Vonage's Redact API][doc_redact] to redact a SMS message.
var credentials = Credentials.FromApiKeyAndSecret(VONAGE_API_KEY, VONAGE_API_SECRET);
var client = new VonageClient(credentials);
var request = new RedactRequest() { Id = VONAGE_REDACT_ID, Type = VONAGE_REDACT_TYPE, Product = VONAGE_REDACT_PRODUCT };
var response = client.RedactClient.Redact(request);
var response = await client.RedactClient.RedactAsync(request);
```

### Initiating a Call
Expand All @@ -351,7 +352,7 @@ var creds = Credentials.FromAppIdAndPrivateKeyPath(VONAGE_APPLICATION_ID, VONAGE
var client = new VonageClient(creds);

var command = new CallCommand() { To = new Endpoint[] { toEndpoint }, From = fromEndpoint, AnswerUrl=new[] { ANSWER_URL}};
var response = client.VoiceClient.CreateCall(command);
var response = await client.VoiceClient.CreateCallAsync(command);
```

### Receiving a Call
Expand All @@ -378,7 +379,7 @@ public string Answer()
var credentials = Credentials.FromAppIdAndPrivateKeyPath(VONAGE_APPLICATION_ID, VONAGE_PRIVATE_KEY_PATH);
var client = new VonageClient(credentials);

var response = client.VoiceClient.GetCall(UUID);
var response = await client.VoiceClient.GetCallAsync(UUID);
```

### Sending 2FA Code
Expand All @@ -390,7 +391,7 @@ var credentials = Credentials.FromApiKeyAndSecret(VONAGE_API_KEY, VONAGE_API_SEC
var client = new VonageClient(credentials);

var request = new VerifyRequest() { Brand = BRAND_NAME, Number = RECIPIENT_NUMBER };
var response = client.VerifyClient.VerifyRequest(request);
var response = await client.VerifyClient.VerifyRequestAsync(request);
```

### Checking 2FA Code
Expand All @@ -402,7 +403,7 @@ var credentials = Credentials.FromApiKeyAndSecret(VONAGE_API_KEY, VONAGE_API_SEC
var client = new VonageClient(credentials);

var request = new VerifyCheckRequest() { Code = CODE, RequestId = REQUEST_ID };
var response = client.VerifyClient.VerifyCheck(request);
var response = await client.VerifyClient.VerifyCheckAsync(request);
```

### Additional Examples
Expand Down Expand Up @@ -437,7 +438,7 @@ The following is a list of Vonage APIs and whether the Vonage .NET SDK provides
## FAQ

Q: Does the .NET SDK Support the async pattern?
A: The .NET SDK does not support the async pattern at this time.
A: Yes

Contributing
------------
Expand Down
48 changes: 24 additions & 24 deletions Vonage.Test.Unit/AccountTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class AccountTest : TestBase
[Theory]
[InlineData(false)]
[InlineData(true)]
public void GetAccountBalance(bool passCreds)
public async Task GetAccountBalance(bool passCreds)
{
//ARRANGE
var expectedUri = $"{RestUrl}/account/get-balance?api_key={ApiKey}&api_secret={ApiSecret}&";
Expand All @@ -24,11 +24,11 @@ public void GetAccountBalance(bool passCreds)
var client = new VonageClient(creds);
Accounts.Balance balance;
if (passCreds) {
balance = client.AccountClient.GetAccountBalance(creds);
balance = await client.AccountClient.GetAccountBalanceAsync(creds);
}
else
{
balance = client.AccountClient.GetAccountBalance();
balance = await client.AccountClient.GetAccountBalanceAsync();
}

//ASSERT
Expand All @@ -39,7 +39,7 @@ public void GetAccountBalance(bool passCreds)
[Theory]
[InlineData(false)]
[InlineData(true)]
public void SetSettings(bool passCreds)
public async Task SetSettings(bool passCreds)
{
//ARRANGE
var expectedUri = $"{RestUrl}/account/settings";
Expand All @@ -53,11 +53,11 @@ public void SetSettings(bool passCreds)
Accounts.AccountSettingsResult result;
if (passCreds)
{
result = client.AccountClient.ChangeAccountSettings(new Accounts.AccountSettingsRequest { MoCallBackUrl = "https://example.com/webhooks/inbound-sms", DrCallBackUrl = "https://example.com/webhooks/delivery-receipt" }, creds);
result = await client.AccountClient.ChangeAccountSettingsAsync(new Accounts.AccountSettingsRequest { MoCallBackUrl = "https://example.com/webhooks/inbound-sms", DrCallBackUrl = "https://example.com/webhooks/delivery-receipt" }, creds);
}
else
{
result = client.AccountClient.ChangeAccountSettings(new Accounts.AccountSettingsRequest { MoCallBackUrl = "https://example.com/webhooks/inbound-sms", DrCallBackUrl = "https://example.com/webhooks/delivery-receipt" });
result = await client.AccountClient.ChangeAccountSettingsAsync(new Accounts.AccountSettingsRequest { MoCallBackUrl = "https://example.com/webhooks/inbound-sms", DrCallBackUrl = "https://example.com/webhooks/delivery-receipt" });
}


Expand All @@ -72,7 +72,7 @@ public void SetSettings(bool passCreds)
[Theory]
[InlineData(false)]
[InlineData(true)]
public void TopUp(bool passCreds)
public async Task TopUp(bool passCreds)
{
//ARRANGE
var expectedUri = $"{RestUrl}/account/top-up?trx=00X123456Y7890123Z&api_key={ApiKey}&api_secret={ApiSecret}&";
Expand All @@ -85,11 +85,11 @@ public void TopUp(bool passCreds)
Accounts.TopUpResult response;
if (passCreds)
{
response = client.AccountClient.TopUpAccountBalance(new Accounts.TopUpRequest { Trx = "00X123456Y7890123Z" },creds);
response = await client.AccountClient.TopUpAccountBalanceAsync(new Accounts.TopUpRequest { Trx = "00X123456Y7890123Z" },creds);
}
else
{
response = client.AccountClient.TopUpAccountBalance(new Accounts.TopUpRequest { Trx = "00X123456Y7890123Z" });
response = await client.AccountClient.TopUpAccountBalanceAsync(new Accounts.TopUpRequest { Trx = "00X123456Y7890123Z" });
}

Assert.Equal("abc123",response.Response);
Expand All @@ -98,7 +98,7 @@ public void TopUp(bool passCreds)
[Theory]
[InlineData(false)]
[InlineData(true)]
public void GetNumbers(bool passCreds)
public async Task GetNumbers(bool passCreds)
{
//ARRANGE
var expectedUri = $"{RestUrl}/account/numbers?api_key={ApiKey}&api_secret={ApiSecret}&";
Expand All @@ -110,11 +110,11 @@ public void GetNumbers(bool passCreds)
var client = new VonageClient(creds);
Numbers.NumbersSearchResponse numbers;
if (passCreds){
numbers = client.NumbersClient.GetOwnedNumbers(new Numbers.NumberSearchRequest(), creds);
numbers = await client.NumbersClient.GetOwnedNumbersAsync(new Numbers.NumberSearchRequest(), creds);
}
else
{
numbers = client.NumbersClient.GetOwnedNumbers(new Numbers.NumberSearchRequest());
numbers = await client.NumbersClient.GetOwnedNumbersAsync(new Numbers.NumberSearchRequest());
}

//ASSERT
Expand All @@ -128,7 +128,7 @@ public void GetNumbers(bool passCreds)
[Theory]
[InlineData(false)]
[InlineData(true)]
public void RetrieveApiSecrets(bool passCreds)
public async Task RetrieveApiSecrets(bool passCreds)
{
//ARRANGE
var expectedResponse = @"{
Expand Down Expand Up @@ -160,11 +160,11 @@ public void RetrieveApiSecrets(bool passCreds)
Accounts.SecretsRequestResult secrets;
if (passCreds)
{
secrets = client.AccountClient.RetrieveApiSecrets(ApiKey,creds);
secrets = await client.AccountClient.RetrieveApiSecretsAsync(ApiKey,creds);
}
else
{
secrets = client.AccountClient.RetrieveApiSecrets(ApiKey);
secrets = await client.AccountClient.RetrieveApiSecretsAsync(ApiKey);
}


Expand All @@ -178,7 +178,7 @@ public void RetrieveApiSecrets(bool passCreds)
[Theory]
[InlineData(false)]
[InlineData(true)]
public void CreateApiSecret(bool passCreds)
public async Task CreateApiSecret(bool passCreds)
{
//ARRANGE
var expectedUri = $"https://api.nexmo.com/accounts/{ApiKey}/secrets";
Expand All @@ -199,11 +199,11 @@ public void CreateApiSecret(bool passCreds)
Accounts.Secret secret;
if (passCreds)
{
secret = client.AccountClient.CreateApiSecret(new Accounts.CreateSecretRequest { Secret = "password" }, ApiKey, creds);
secret = await client.AccountClient.CreateApiSecretAsync(new Accounts.CreateSecretRequest { Secret = "password" }, ApiKey, creds);
}
else
{
secret = client.AccountClient.CreateApiSecret(new Accounts.CreateSecretRequest { Secret = "password" }, ApiKey);
secret = await client.AccountClient.CreateApiSecretAsync(new Accounts.CreateSecretRequest { Secret = "password" }, ApiKey);
}


Expand All @@ -216,7 +216,7 @@ public void CreateApiSecret(bool passCreds)
[Theory]
[InlineData(false)]
[InlineData(true)]
public void RetrieveSecret(bool passCreds)
public async Task RetrieveSecret(bool passCreds)
{

//ARRANGE
Expand All @@ -240,11 +240,11 @@ public void RetrieveSecret(bool passCreds)
Accounts.Secret secret;
if (passCreds)
{
secret = client.AccountClient.RetrieveApiSecret(secretId, ApiKey, creds);
secret = await client.AccountClient.RetrieveApiSecretAsync(secretId, ApiKey, creds);
}
else
{
secret = client.AccountClient.RetrieveApiSecret(secretId, ApiKey);
secret = await client.AccountClient.RetrieveApiSecretAsync(secretId, ApiKey);
}


Expand All @@ -257,7 +257,7 @@ public void RetrieveSecret(bool passCreds)
[Theory]
[InlineData(false)]
[InlineData(true)]
public void RevokeSecret(bool passCreds)
public async Task RevokeSecret(bool passCreds)
{
//ARRANGE
var secretId = "ad6dc56f-07b5-46e1-a527-85530e625800";
Expand All @@ -271,11 +271,11 @@ public void RevokeSecret(bool passCreds)
bool response;
if (passCreds)
{
response = client.AccountClient.RevokeApiSecret(secretId, ApiKey, creds);
response = await client.AccountClient.RevokeApiSecretAsync(secretId, ApiKey, creds);
}
else
{
response = client.AccountClient.RevokeApiSecret(secretId, ApiKey);
response = await client.AccountClient.RevokeApiSecretAsync(secretId, ApiKey);
}


Expand Down
30 changes: 15 additions & 15 deletions Vonage.Test.Unit/ApplicationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class ApplicationTests : TestBase
[Theory]
[InlineData(false)]
[InlineData(true)]
public void CreateApplication(bool passCreds)
public async Task CreateApplication(bool passCreds)
{
//ARRANGE
var uri = $"{ApiUrl}/v2/applications";
Expand Down Expand Up @@ -101,11 +101,11 @@ public void CreateApplication(bool passCreds)
Application response;
if (passCreds)
{
response = client.ApplicationClient.CreateApplicaiton(request);
response = await client.ApplicationClient.CreateApplicaitonAsync(request);
}
else
{
response = client.ApplicationClient.CreateApplicaiton(request, creds);
response = await client.ApplicationClient.CreateApplicaitonAsync(request, creds);
}


Expand Down Expand Up @@ -134,7 +134,7 @@ public void CreateApplication(bool passCreds)
[Theory]
[InlineData(false)]
[InlineData(true)]
public void UpdateApplication(bool passCredentials)
public async Task UpdateApplication(bool passCredentials)
{
var id = "78d335fa323d01149c3dd6f0d48968cf";
var uri = $"{ApiUrl}/v2/applications/{id}";
Expand Down Expand Up @@ -217,11 +217,11 @@ public void UpdateApplication(bool passCredentials)
Application response;
if (passCredentials)
{
response = client.ApplicationClient.UpdateApplication(id, application);
response = await client.ApplicationClient.UpdateApplicationAsync(id, application);
}
else
{
response = client.ApplicationClient.UpdateApplication(id, application,creds);
response = await client.ApplicationClient.UpdateApplicationAsync(id, application,creds);
}


Expand Down Expand Up @@ -250,7 +250,7 @@ public void UpdateApplication(bool passCredentials)
[Theory]
[InlineData(false, false)]
[InlineData(true, true)]
public void ListApplications(bool passCreds, bool passParameters)
public async Task ListApplications(bool passCreds, bool passParameters)
{
var expectedResult = @"{
""page_size"": 10,
Expand Down Expand Up @@ -327,11 +327,11 @@ public void ListApplications(bool passCreds, bool passParameters)
ApplicationPage applications;
if (passCreds)
{
applications = client.ApplicationClient.ListApplications(request,creds);
applications = await client.ApplicationClient.ListApplicationsAsync(request,creds);
}
else
{
applications = client.ApplicationClient.ListApplications(request);
applications = await client.ApplicationClient.ListApplicationsAsync(request);
}

Application application = applications.Embedded.Applications[0];
Expand Down Expand Up @@ -366,7 +366,7 @@ public void ListApplications(bool passCreds, bool passParameters)
[Theory]
[InlineData(false)]
[InlineData(true)]
public void GetApplication(bool passCreds)
public async Task GetApplication(bool passCreds)
{
var id = "78d335fa323d01149c3dd6f0d48968cf";
var uri = $"{ApiUrl}/v2/applications/{id}";
Expand Down Expand Up @@ -425,11 +425,11 @@ public void GetApplication(bool passCreds)
Application application;
if (passCreds)
{
application = client.ApplicationClient.GetApplication(id, creds);
application = await client.ApplicationClient.GetApplicationAsync(id, creds);
}
else
{
application = client.ApplicationClient.GetApplication(id);
application = await client.ApplicationClient.GetApplicationAsync(id);
}

Assert.Equal("78d335fa323d01149c3dd6f0d48968cf", application.Id);
Expand Down Expand Up @@ -457,7 +457,7 @@ public void GetApplication(bool passCreds)
[Theory]
[InlineData(false)]
[InlineData(true)]
public void DeleteApplication(bool passCreds)
public async Task DeleteApplication(bool passCreds)
{
var id = "78d335fa323d01149c3dd6f0d48968cf";
var uri = $"{ApiUrl}/v2/applications/{id}";
Expand All @@ -468,11 +468,11 @@ public void DeleteApplication(bool passCreds)
bool result;
if(passCreds)
{
result = client.ApplicationClient.DeleteApplication(id, creds);
result = await client.ApplicationClient.DeleteApplicationAsync(id, creds);
}
else
{
result = client.ApplicationClient.DeleteApplication(id);
result = await client.ApplicationClient.DeleteApplicationAsync(id);
}
Assert.True(result);
}
Expand Down
Loading

0 comments on commit cbf2e85

Please sign in to comment.