diff --git a/README.md b/README.md index 90ef2724f..e6a711570 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,4 @@ + Vonage Client Library for .NET =================================== @@ -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, @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 ------------ diff --git a/Vonage.Test.Unit/AccountTest.cs b/Vonage.Test.Unit/AccountTest.cs index 926475b3f..91c12086b 100644 --- a/Vonage.Test.Unit/AccountTest.cs +++ b/Vonage.Test.Unit/AccountTest.cs @@ -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}&"; @@ -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 @@ -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"; @@ -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" }); } @@ -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}&"; @@ -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); @@ -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}&"; @@ -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 @@ -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 = @"{ @@ -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); } @@ -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"; @@ -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); } @@ -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 @@ -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); } @@ -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"; @@ -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); } diff --git a/Vonage.Test.Unit/ApplicationTests.cs b/Vonage.Test.Unit/ApplicationTests.cs index 5138ea89d..ea781053c 100644 --- a/Vonage.Test.Unit/ApplicationTests.cs +++ b/Vonage.Test.Unit/ApplicationTests.cs @@ -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"; @@ -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); } @@ -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}"; @@ -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); } @@ -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, @@ -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]; @@ -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}"; @@ -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); @@ -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}"; @@ -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); } diff --git a/Vonage.Test.Unit/ConversionTest.cs b/Vonage.Test.Unit/ConversionTest.cs index 652d14b27..652a6e3c1 100644 --- a/Vonage.Test.Unit/ConversionTest.cs +++ b/Vonage.Test.Unit/ConversionTest.cs @@ -12,7 +12,7 @@ public class ConversionTest : TestBase [Theory] [InlineData(false)] [InlineData(true)] - public void SmsConversion(bool passCreds) + public async Task SmsConversion(bool passCreds) { var expectedUri = $"${ApiUrl}/conversions/sms"; var expectedContent = "message-id=00A0B0C0&delivered=true×tamp=2020-01-01+12%3A00%3A00&api_key=testkey&api_secret=testSecret&"; @@ -24,11 +24,11 @@ public void SmsConversion(bool passCreds) bool response; if (passCreds) { - response = client.ConversionClient.SmsConversion(request, creds); + response = await client.ConversionClient.SmsConversionAsync(request, creds); } else { - response = client.ConversionClient.SmsConversion(request); + response = await client.ConversionClient.SmsConversionAsync(request); } Assert.True(response); } @@ -36,7 +36,7 @@ public void SmsConversion(bool passCreds) [Theory] [InlineData(false)] [InlineData(true)] - public void VoiceConversion(bool passCreds) + public async Task VoiceConversion(bool passCreds) { var expectedUri = $"${ApiUrl}/conversions/sms"; var expectedContent = "message-id=00A0B0C0&delivered=true×tamp=2020-01-01+12%3A00%3A00&api_key=testkey&api_secret=testSecret&"; @@ -48,11 +48,11 @@ public void VoiceConversion(bool passCreds) bool response; if (passCreds) { - response = client.ConversionClient.VoiceConversion(request, creds); + response = await client.ConversionClient.VoiceConversionAsync(request, creds); } else { - response = client.ConversionClient.VoiceConversion(request); + response = await client.ConversionClient.VoiceConversionAsync(request); } Assert.True(response); } diff --git a/Vonage.Test.Unit/MessagingTests.cs b/Vonage.Test.Unit/MessagingTests.cs index 7651f2aba..9ef084675 100644 --- a/Vonage.Test.Unit/MessagingTests.cs +++ b/Vonage.Test.Unit/MessagingTests.cs @@ -15,7 +15,7 @@ public class MessagingTests : TestBase [Theory] [InlineData(false)] [InlineData(true)] - public void KitcenSinkSendSms(bool passCreds) + public async Task KitcenSinkSendSms(bool passCreds) { var expectedResponse = @"{ ""message-count"": ""1"", @@ -65,11 +65,11 @@ public void KitcenSinkSendSms(bool passCreds) Messaging.SendSmsResponse response; if (passCreds) { - response = client.SmsClient.SendAnSms(request, creds); + response = await client.SmsClient.SendAnSmsAsync(request, creds); } else { - response = client.SmsClient.SendAnSms(request); + response = await client.SmsClient.SendAnSmsAsync(request); } Assert.Equal("1", response.MessageCount); @@ -82,7 +82,7 @@ public void KitcenSinkSendSms(bool passCreds) } [Fact] - public void SendSmsTypicalUsage() + public async Task SendSmsTypicalUsage() { var expectedResponse = @"{ ""message-count"": ""1"", @@ -102,7 +102,7 @@ public void SendSmsTypicalUsage() var expectedRequestContent = $"from=AcmeInc&to=447700900000&text={HttpUtility.UrlEncode("Hello World!")}&api_key={ApiKey}&api_secret={ApiSecret}&"; Setup(expectedUri, expectedResponse, expectedRequestContent); var client = new VonageClient(Request.Credentials.FromApiKeyAndSecret(ApiKey, ApiSecret)); - var response = client.SmsClient.SendAnSms(new Messaging.SendSmsRequest { From = "AcmeInc", To = "447700900000", Text = "Hello World!" }); + var response = await client.SmsClient.SendAnSmsAsync(new Messaging.SendSmsRequest { From = "AcmeInc", To = "447700900000", Text = "Hello World!" }); Assert.Equal("1", response.MessageCount); Assert.Equal("447700900000", response.Messages[0].To); Assert.Equal("0A0000000123ABCD1", response.Messages[0].MessageId); @@ -114,7 +114,7 @@ public void SendSmsTypicalUsage() } [Fact] - public void SendSmsUnicode() + public async Task SendSmsUnicode() { var expectedResponse = @"{ ""message-count"": ""1"", @@ -134,7 +134,7 @@ public void SendSmsUnicode() var expectedRequestContent = $"from=AcmeInc&to=447700900000&text={HttpUtility.UrlEncode("こんにちは世界")}&api_key={ApiKey}&api_secret={ApiSecret}&"; Setup(expectedUri, expectedResponse, expectedRequestContent); var client = new VonageClient(Request.Credentials.FromApiKeyAndSecret(ApiKey, ApiSecret)); - var response = client.SmsClient.SendAnSms(new Messaging.SendSmsRequest { From = "AcmeInc", To = "447700900000", Text = "こんにちは世界" }); + var response = await client.SmsClient.SendAnSmsAsync(new Messaging.SendSmsRequest { From = "AcmeInc", To = "447700900000", Text = "こんにちは世界" }); Assert.Equal("1", response.MessageCount); Assert.Equal("447700900000", response.Messages[0].To); Assert.Equal("0A0000000123ABCD1", response.Messages[0].MessageId); @@ -146,7 +146,7 @@ public void SendSmsUnicode() } [Fact] - public void SendSmsBadResponse() + public async Task SendSmsBadResponse() { var expectedResponse = @"{ ""message-count"": ""1"", @@ -163,7 +163,7 @@ public void SendSmsBadResponse() var client = new VonageClient(Request.Credentials.FromApiKeyAndSecret(ApiKey, ApiSecret)); try { - var response = client.SmsClient.SendAnSms(new Messaging.SendSmsRequest { From = "AcmeInc", To = "447700900000", Text = "Hello World!" }); + var response = await client.SmsClient.SendAnSmsAsync(new Messaging.SendSmsRequest { From = "AcmeInc", To = "447700900000", Text = "Hello World!" }); Assert.True(false); } catch(Messaging.VonageSmsResponseException nex) @@ -174,7 +174,7 @@ public void SendSmsBadResponse() } [Fact] - public void NullMessagesResponse() + public async Task NullMessagesResponse() { var expectedResponse = @""; var expectedUri = $"{RestUrl}/sms/json?"; @@ -183,7 +183,7 @@ public void NullMessagesResponse() var client = new VonageClient(Request.Credentials.FromApiKeyAndSecret(ApiKey, ApiSecret)); try { - var response = client.SmsClient.SendAnSms(new Messaging.SendSmsRequest { From = "AcmeInc", To = "447700900000", Text = "Hello World!" }); + var response = await client.SmsClient.SendAnSmsAsync(new Messaging.SendSmsRequest { From = "AcmeInc", To = "447700900000", Text = "Hello World!" }); Assert.True(false); } catch (Messaging.VonageSmsResponseException nex) diff --git a/Vonage.Test.Unit/NumberInsightsTests.cs b/Vonage.Test.Unit/NumberInsightsTests.cs index bd7d1eb6d..dc2fa18f4 100644 --- a/Vonage.Test.Unit/NumberInsightsTests.cs +++ b/Vonage.Test.Unit/NumberInsightsTests.cs @@ -14,7 +14,7 @@ public class NumberInsightsTests : TestBase [Theory] [InlineData(true,true)] [InlineData(false,false)] - public void TestBasicNIRequest(bool passCreds, bool kitchenSink) + public async Task TestBasicNIRequest(bool passCreds, bool kitchenSink) { //ARRANGE var expectedUri = $"{ApiUrl}/ni/basic/json"; @@ -47,11 +47,11 @@ public void TestBasicNIRequest(bool passCreds, bool kitchenSink) var client = new VonageClient(creds); if (passCreds) { - response = client.NumberInsightClient.GetNumberInsightBasic(request, creds); + response = await client.NumberInsightClient.GetNumberInsightBasicAsync(request, creds); } else { - response = client.NumberInsightClient.GetNumberInsightBasic(request); + response = await client.NumberInsightClient.GetNumberInsightBasicAsync(request); } //ASSERT @@ -69,7 +69,7 @@ public void TestBasicNIRequest(bool passCreds, bool kitchenSink) [Theory] [InlineData(true, true)] [InlineData(false, false)] - public void TestStandardNIRequest(bool passCreds, bool kitchenSink) + public async Task TestStandardNIRequest(bool passCreds, bool kitchenSink) { //ARRANGE var expectedResponse = @"{ @@ -139,11 +139,11 @@ public void TestStandardNIRequest(bool passCreds, bool kitchenSink) StandardInsightResponse response; if (passCreds) { - response = client.NumberInsightClient.GetNumberInsightStandard(request, creds); + response = await client.NumberInsightClient.GetNumberInsightStandardAsync(request, creds); } else { - response = client.NumberInsightClient.GetNumberInsightStandard(request); + response = await client.NumberInsightClient.GetNumberInsightStandardAsync(request); } Assert.Equal("John", response.FirstName); Assert.Equal(CallerType.consumer, response.CallerType); @@ -183,7 +183,7 @@ public void TestStandardNIRequest(bool passCreds, bool kitchenSink) [Theory] [InlineData(true, true)] [InlineData(false, false)] - public void TestAdvancedNIRequestSync(bool passCreds, bool kitchenSink) + public async Task TestAdvancedNIRequestSync(bool passCreds, bool kitchenSink) {//ARRANGE var expectedResponse = @"{ ""status"": 0, @@ -257,11 +257,11 @@ public void TestAdvancedNIRequestSync(bool passCreds, bool kitchenSink) AdvancedInsightsResponse response; if (passCreds) { - response = client.NumberInsightClient.GetNumberInsightAdvanced(request, creds); + response = await client.NumberInsightClient.GetNumberInsightAdvancedAsync(request, creds); } else { - response = client.NumberInsightClient.GetNumberInsightAdvanced(request); + response = await client.NumberInsightClient.GetNumberInsightAdvancedAsync(request); } //ASSERT @@ -307,7 +307,7 @@ public void TestAdvancedNIRequestSync(bool passCreds, bool kitchenSink) [Theory] [InlineData(true, true)] [InlineData(false, false)] - public void TestAdvancedAsync(bool passCreds, bool kitchenSink) + public async Task TestAdvancedAsync(bool passCreds, bool kitchenSink) { var expectedResponse = @"{ ""request_id"": ""aaaaaaaa-bbbb-cccc-dddd-0123456789ab"", @@ -340,11 +340,11 @@ public void TestAdvancedAsync(bool passCreds, bool kitchenSink) AdvancedInsightsAsyncResponse response; if (passCreds) { - response = client.NumberInsightClient.GetNumberInsightAsync(request, creds); + response = await client.NumberInsightClient.GetNumberInsightAsyncAsync(request, creds); } else { - response = client.NumberInsightClient.GetNumberInsightAsync(request); + response = await client.NumberInsightClient.GetNumberInsightAsyncAsync(request); } //ASSERT @@ -356,7 +356,7 @@ public void TestAdvancedAsync(bool passCreds, bool kitchenSink) } [Fact] - public void TestFailedAsyncRequest() + public async Task TestFailedAsyncRequest() { //ARRANGE var expectedResponse = @"{ @@ -370,7 +370,7 @@ public void TestFailedAsyncRequest() var client = new VonageClient(creds); try { - client.NumberInsightClient.GetNumberInsightAsync(request); + await client.NumberInsightClient.GetNumberInsightAsyncAsync(request); //ASSERT Assert.True(false, "Auto fail because request returned without throwing exception"); } @@ -382,7 +382,7 @@ public void TestFailedAsyncRequest() } [Fact] - public void TestFailedAdvancedRequest() + public async Task TestFailedAdvancedRequest() { //ARRANGE var expectedResponse = @"{ @@ -397,7 +397,7 @@ public void TestFailedAdvancedRequest() var client = new VonageClient(creds); try { - client.NumberInsightClient.GetNumberInsightAdvanced(request); + await client.NumberInsightClient.GetNumberInsightAdvancedAsync(request); //ASSERT Assert.True(false, "Auto fail because request returned without throwing exception"); } diff --git a/Vonage.Test.Unit/NumbersTests.cs b/Vonage.Test.Unit/NumbersTests.cs index bb3bdf926..6b5180325 100644 --- a/Vonage.Test.Unit/NumbersTests.cs +++ b/Vonage.Test.Unit/NumbersTests.cs @@ -13,7 +13,7 @@ public class NumbersTests : TestBase [Theory] [InlineData(true,true)] [InlineData(false,false)] - public void TestSearchNumbers(bool passCreds, bool kitchenSink) + public async Task TestSearchNumbers(bool passCreds, bool kitchenSink) { var expetedResponse = @"{ ""count"": 1234, @@ -49,11 +49,11 @@ public void TestSearchNumbers(bool passCreds, bool kitchenSink) NumbersSearchResponse response; if (passCreds) { - response = client.NumbersClient.GetAvailableNumbers(request, creds); + response = await client.NumbersClient.GetAvailableNumbersAsync(request, creds); } else { - response = client.NumbersClient.GetAvailableNumbers(request); + response = await client.NumbersClient.GetAvailableNumbersAsync(request); } var number = response.Numbers[0]; @@ -69,7 +69,7 @@ public void TestSearchNumbers(bool passCreds, bool kitchenSink) [Theory] [InlineData(true,true)] [InlineData(false,false)] - public void TestBuyNumber(bool passCreds, bool kitchenSink) + public async Task TestBuyNumber(bool passCreds, bool kitchenSink) { var expectedResponse = @"{ ""error-code"": ""200"", @@ -97,11 +97,11 @@ public void TestBuyNumber(bool passCreds, bool kitchenSink) NumberTransactionResponse response; if (passCreds) { - response = client.NumbersClient.BuyANumber(request, creds); + response = await client.NumbersClient.BuyANumberAsync(request, creds); } else { - response = client.NumbersClient.BuyANumber(request); + response = await client.NumbersClient.BuyANumberAsync(request); } Assert.Equal("200",response.ErrorCode); @@ -111,7 +111,7 @@ public void TestBuyNumber(bool passCreds, bool kitchenSink) [Theory] [InlineData(true, true)] [InlineData(false, false)] - public void TestCancelNumber(bool passCreds, bool kitchenSink) + public async Task TestCancelNumber(bool passCreds, bool kitchenSink) { var expectedResponse = @"{ ""error-code"": ""200"", @@ -139,11 +139,11 @@ public void TestCancelNumber(bool passCreds, bool kitchenSink) NumberTransactionResponse response; if (passCreds) { - response = client.NumbersClient.CancelANumber(request, creds); + response = await client.NumbersClient.CancelANumberAsync(request, creds); } else { - response = client.NumbersClient.CancelANumber(request); + response = await client.NumbersClient.CancelANumberAsync(request); } Assert.Equal("200", response.ErrorCode); @@ -153,7 +153,7 @@ public void TestCancelNumber(bool passCreds, bool kitchenSink) [Theory] [InlineData(true,true)] [InlineData(false,false)] - public void TestUpdateNumber(bool passCreds, bool kitchenSink) + public async Task TestUpdateNumber(bool passCreds, bool kitchenSink) { var expectedResponse = @"{ ""error-code"": ""200"", @@ -193,11 +193,11 @@ public void TestUpdateNumber(bool passCreds, bool kitchenSink) NumberTransactionResponse response; if (passCreds) { - response = client.NumbersClient.UpdateANumber(request, creds); + response = await client.NumbersClient.UpdateANumberAsync(request, creds); } else { - response = client.NumbersClient.UpdateANumber(request); + response = await client.NumbersClient.UpdateANumberAsync(request); } Assert.Equal("200", response.ErrorCode); @@ -205,7 +205,7 @@ public void TestUpdateNumber(bool passCreds, bool kitchenSink) } [Fact] - public void TestFailedPurchase() + public async Task TestFailedPurchase() { var expectedResponse = @"{ ""error-code"": ""401"", @@ -219,7 +219,7 @@ public void TestFailedPurchase() var client = new VonageClient(creds); try { - client.NumbersClient.BuyANumber(request); + await client.NumbersClient.BuyANumberAsync(request); Assert.True(false, "Failin because exception was not thrown"); } catch (VonageNumberResponseException ex) diff --git a/Vonage.Test.Unit/PricingTests.cs b/Vonage.Test.Unit/PricingTests.cs index 57fb9ce81..e91f8d5d8 100644 --- a/Vonage.Test.Unit/PricingTests.cs +++ b/Vonage.Test.Unit/PricingTests.cs @@ -11,7 +11,7 @@ public class PricingTests : TestBase [Theory] [InlineData(true)] [InlineData(false)] - public void GetPricingForCountry(bool passCreds) + public async Task GetPricingForCountry(bool passCreds) { //ARRANGE var expectedUri = $"{RestUrl}/account/get-pricing/outbound/sms?country=CA&api_key={ApiKey}&api_secret={ApiSecret}&"; @@ -43,11 +43,11 @@ public void GetPricingForCountry(bool passCreds) if (passCreds) { - country = client.PricingClient.RetrievePricingCountry("sms", new Pricing.PricingCountryRequest { Country = "CA" }, creds); + country = await client.PricingClient.RetrievePricingCountryAsync("sms", new Pricing.PricingCountryRequest { Country = "CA" }, creds); } else { - country = client.PricingClient.RetrievePricingCountry("sms", new Pricing.PricingCountryRequest { Country = "CA" }); + country = await client.PricingClient.RetrievePricingCountryAsync("sms", new Pricing.PricingCountryRequest { Country = "CA" }); } //ASSERT @@ -70,7 +70,7 @@ public void GetPricingForCountry(bool passCreds) [Theory] [InlineData(true)] [InlineData(false)] - public void GetPricingForPrefix(bool passCreds) + public async Task GetPricingForPrefix(bool passCreds) { //ARRANGE var expectedUri = $"{RestUrl}/account/get-prefix-pricing/outbound/sms?prefix=1&api_key={ApiKey}&api_secret={ApiSecret}&"; @@ -105,11 +105,11 @@ public void GetPricingForPrefix(bool passCreds) Pricing.PricingResult pricing; if (passCreds) { - pricing = client.PricingClient.RetrievePrefixPricing("sms", new Pricing.PricingPrefixRequest { Prefix = "1" }, creds); + pricing = await client.PricingClient.RetrievePrefixPricingAsync("sms", new Pricing.PricingPrefixRequest { Prefix = "1" }, creds); } else { - pricing = client.PricingClient.RetrievePrefixPricing("sms", new Pricing.PricingPrefixRequest { Prefix = "1" }); + pricing = await client.PricingClient.RetrievePrefixPricingAsync("sms", new Pricing.PricingPrefixRequest { Prefix = "1" }); } //ASSERT @@ -131,7 +131,7 @@ public void GetPricingForPrefix(bool passCreds) [Theory] [InlineData(true)] [InlineData(false)] - public void GetPricingAllCountries(bool passCreds) + public async Task GetPricingAllCountries(bool passCreds) { //ARRANGE var expectedUri = $"{RestUrl}/account/get-pricing/outbound/sms?api_key={ApiKey}&api_secret={ApiSecret}&"; @@ -166,11 +166,11 @@ public void GetPricingAllCountries(bool passCreds) Pricing.PricingResult pricing; if (passCreds) { - pricing = client.PricingClient.RetrievePricingAllCountries("sms",creds); + pricing = await client.PricingClient.RetrievePricingAllCountriesAsync("sms",creds); } else { - pricing = client.PricingClient.RetrievePricingAllCountries("sms"); + pricing = await client.PricingClient.RetrievePricingAllCountriesAsync("sms"); } //ASSERT diff --git a/Vonage.Test.Unit/VerifyTest.cs b/Vonage.Test.Unit/VerifyTest.cs index d47fcb420..d26041a9f 100644 --- a/Vonage.Test.Unit/VerifyTest.cs +++ b/Vonage.Test.Unit/VerifyTest.cs @@ -13,7 +13,7 @@ public class VerifyTest : TestBase [Theory] [InlineData(true, true)] [InlineData(false, false)] - public void RequestVerification(bool passCreds, bool kitchenSink) + public async Task RequestVerification(bool passCreds, bool kitchenSink) { var expectedResponse = @"{ ""request_id"": ""abcdef0123456789abcdef0123456789"", @@ -44,11 +44,11 @@ public void RequestVerification(bool passCreds, bool kitchenSink) VerifyResponse response; if (passCreds) { - response = client.VerifyClient.VerifyRequest(request, creds); + response = await client.VerifyClient.VerifyRequestAsync(request, creds); } else { - response = client.VerifyClient.VerifyRequest(request); + response = await client.VerifyClient.VerifyRequestAsync(request); } Assert.Equal("abcdef0123456789abcdef0123456789", response.RequestId); @@ -58,7 +58,7 @@ public void RequestVerification(bool passCreds, bool kitchenSink) [Theory] [InlineData(true, true)] [InlineData(false, false)] - public void TestCheckVerification(bool passCreds, bool kitchenSink) + public async Task TestCheckVerification(bool passCreds, bool kitchenSink) { var expectedResponse = @"{ ""request_id"": ""abcdef0123456789abcdef0123456789"", @@ -87,11 +87,11 @@ public void TestCheckVerification(bool passCreds, bool kitchenSink) VerifyCheckResponse response; if (passCreds) { - response = client.VerifyClient.VerifyCheck(request, creds); + response = await client.VerifyClient.VerifyCheckAsync(request, creds); } else { - response = client.VerifyClient.VerifyCheck(request); + response = await client.VerifyClient.VerifyCheckAsync(request); } Assert.Equal("0.10000000", response.Price); Assert.Equal("0.03330000", response.EstimatedPriceMessagesSent); @@ -104,7 +104,7 @@ public void TestCheckVerification(bool passCreds, bool kitchenSink) [Theory] [InlineData(false)] [InlineData(true)] - public void TestVerifySearch(bool passCreds) + public async Task TestVerifySearch(bool passCreds) { var expectedResponse = @"{ ""request_id"": ""abcdef0123456789abcdef0123456789"", @@ -142,11 +142,11 @@ public void TestVerifySearch(bool passCreds) VerifySearchResponse response; if (passCreds) { - response = client.VerifyClient.VerifySearch(request, creds); + response = await client.VerifyClient.VerifySearchAsync(request, creds); } else { - response = client.VerifyClient.VerifySearch(request); + response = await client.VerifyClient.VerifySearchAsync(request); } var req = response; @@ -173,7 +173,7 @@ public void TestVerifySearch(bool passCreds) [Theory] [InlineData(true)] [InlineData(false)] - public void TestControlVerify(bool passCreds) + public async Task TestControlVerify(bool passCreds) { var expectedResponse = @"{ ""status"": ""0"", @@ -190,18 +190,18 @@ public void TestControlVerify(bool passCreds) VerifyControlResponse response; if (passCreds) { - response = client.VerifyClient.VerifyControl(request, creds); + response = await client.VerifyClient.VerifyControlAsync(request, creds); } else { - response = client.VerifyClient.VerifyControl(request, creds); + response = await client.VerifyClient.VerifyControlAsync(request, creds); } Assert.Equal("0", response.Status); Assert.Equal("cancel", response.Command); } [Fact] - public void TestControlVerifyInvalidCredentials() + public async Task TestControlVerifyInvalidCredentials() { var expectedResponse = @"{ ""status"": ""4"", @@ -217,7 +217,7 @@ public void TestControlVerifyInvalidCredentials() var client = new VonageClient(creds); try { - var response = client.VerifyClient.VerifyControl(request, creds); + var response = await client.VerifyClient.VerifyControlAsync(request, creds); Assert.True(false, "Automatically failing because exception wasn't thrown"); } catch(VonageVerifyResponseException ex) @@ -230,7 +230,7 @@ public void TestControlVerifyInvalidCredentials() [Theory] [InlineData(true, true)] [InlineData(false, false)] - public void Psd2Verification(bool passCreds, bool kitchenSink) + public async Task Psd2Verification(bool passCreds, bool kitchenSink) { var expectedResponse = @"{ ""request_id"": ""abcdef0123456789abcdef0123456789"", @@ -261,11 +261,11 @@ public void Psd2Verification(bool passCreds, bool kitchenSink) VerifyResponse response; if (passCreds) { - response = client.VerifyClient.VerifyRequestWithPSD2(request, creds); + response = await client.VerifyClient.VerifyRequestWithPSD2Async(request, creds); } else { - response = client.VerifyClient.VerifyRequestWithPSD2(request); + response = await client.VerifyClient.VerifyRequestWithPSD2Async(request); } Assert.Equal("abcdef0123456789abcdef0123456789", response.RequestId); diff --git a/Vonage.Test.Unit/VoiceClientTests.cs b/Vonage.Test.Unit/VoiceClientTests.cs index eaf8909e5..5d4958d4b 100644 --- a/Vonage.Test.Unit/VoiceClientTests.cs +++ b/Vonage.Test.Unit/VoiceClientTests.cs @@ -15,7 +15,7 @@ public class VoiceClientTests : TestBase [Theory] [InlineData(true)] [InlineData(false)] - public void CreateCall(bool passCreds) + public async Task CreateCall(bool passCreds) { var expectedUri = "https://api.nexmo.com/v1/calls/"; var expectedResponse = @"{ @@ -57,11 +57,11 @@ public void CreateCall(bool passCreds) CallResponse response; if (passCreds) { - response = client.VoiceClient.CreateCall(request, creds); + response = await client.VoiceClient.CreateCallAsync(request, creds); } else { - response = client.VoiceClient.CreateCall(request); + response = await client.VoiceClient.CreateCallAsync(request); } Assert.Equal("63f61863-4a51-4f6b-86e1-46edebcf9356", response.Uuid); Assert.Equal("CON-f972836a-550f-45fa-956c-12a2ab5b7d22", response.ConversationUuid); @@ -72,7 +72,7 @@ public void CreateCall(bool passCreds) [Theory] [InlineData(true, true)] [InlineData(false, false)] - public void TestListCalls(bool passCreds, bool kitchenSink) + public async Task TestListCalls(bool passCreds, bool kitchenSink) { var expectedResponse = @"{ ""count"": 100, @@ -148,11 +148,11 @@ public void TestListCalls(bool passCreds, bool kitchenSink) Common.PageResponse callList; if (passCreds) { - callList = client.VoiceClient.GetCalls(filter, creds); + callList = await client.VoiceClient.GetCallsAsync(filter, creds); } else { - callList = client.VoiceClient.GetCalls(filter); + callList = await client.VoiceClient.GetCallsAsync(filter); } var callRecord = callList.Embedded.Calls[0]; @@ -182,7 +182,7 @@ public void TestListCalls(bool passCreds, bool kitchenSink) [Theory] [InlineData(true)] [InlineData(false)] - public void TestGetSpecificCall(bool passCreds) + public async Task TestGetSpecificCall(bool passCreds) { var uuid = "63f61863-4a51-4f6b-86e1-46edebcf9356"; var expectedResponse = @"{ @@ -224,11 +224,11 @@ public void TestGetSpecificCall(bool passCreds) CallRecord callRecord; if (passCreds) { - callRecord = client.VoiceClient.GetCall(uuid, creds); + callRecord = await client.VoiceClient.GetCallAsync(uuid, creds); } else { - callRecord = client.VoiceClient.GetCall(uuid); + callRecord = await client.VoiceClient.GetCallAsync(uuid); } Assert.Equal("63f61863-4a51-4f6b-86e1-46edebcf9356", callRecord.Uuid); @@ -253,7 +253,7 @@ public void TestGetSpecificCall(bool passCreds) [InlineData(true, true, true)] [InlineData(false, false, true )] [InlineData(false, false, false)] - public void TestUpdateCall(bool passCreds, bool inlineNcco, bool testTransfer) + public async Task TestUpdateCall(bool passCreds, bool inlineNcco, bool testTransfer) { var uuid = "63f61863-4a51-4f6b-86e1-46edebcf9356"; var expectedUri = $"{ApiUrl}/v1/calls/{uuid}"; @@ -286,11 +286,11 @@ public void TestUpdateCall(bool passCreds, bool inlineNcco, bool testTransfer) var client = new VonageClient(creds); if (passCreds) { - response = client.VoiceClient.UpdateCall(uuid, request, creds); + response = await client.VoiceClient.UpdateCallAsync(uuid, request, creds); } else { - response = client.VoiceClient.UpdateCall(uuid, request); + response = await client.VoiceClient.UpdateCallAsync(uuid, request); } Assert.True(response); } @@ -298,7 +298,7 @@ public void TestUpdateCall(bool passCreds, bool inlineNcco, bool testTransfer) [Theory] [InlineData(true, true)] [InlineData(false, false)] - public void TestStartStream(bool passCreds, bool kitchenSink) + public async Task TestStartStream(bool passCreds, bool kitchenSink) { var uuid = "63f61863-4a51-4f6b-86e1-46edebcf9356"; var expectedUri = $"{ApiUrl}/v1/calls/{uuid}/stream"; @@ -334,11 +334,11 @@ public void TestStartStream(bool passCreds, bool kitchenSink) CallCommandResponse response; if (passCreds) { - response = client.VoiceClient.StartStream(uuid,command, creds); + response = await client.VoiceClient.StartStreamAsync(uuid,command, creds); } else { - response = client.VoiceClient.StartStream(uuid, command); + response = await client.VoiceClient.StartStreamAsync(uuid, command); } Assert.Equal("Stream started", response.Message); Assert.Equal(uuid, response.Uuid); @@ -347,7 +347,7 @@ public void TestStartStream(bool passCreds, bool kitchenSink) [Theory] [InlineData(true)] [InlineData(false)] - public void StopStream(bool passCreds) + public async Task StopStream(bool passCreds) { var uuid = "63f61863-4a51-4f6b-86e1-46edebcf9356"; var expectedUri = $"{ApiUrl}/v1/calls/{uuid}/stream"; @@ -364,11 +364,11 @@ public void StopStream(bool passCreds) CallCommandResponse response; if (passCreds) { - response = client.VoiceClient.StopStream(uuid, creds); + response = await client.VoiceClient.StopStreamAsync(uuid, creds); } else { - response = client.VoiceClient.StopStream(uuid); + response = await client.VoiceClient.StopStreamAsync(uuid); } Assert.Equal("Stream stopped", response.Message); Assert.Equal(uuid, response.Uuid); @@ -377,7 +377,7 @@ public void StopStream(bool passCreds) [Theory] [InlineData(true, true)] [InlineData(false, false)] - public void TestStartTalk(bool passCreds, bool kitchenSink) + public async Task TestStartTalk(bool passCreds, bool kitchenSink) { var uuid = "63f61863-4a51-4f6b-86e1-46edebcf9356"; var expectedUri = $"{ApiUrl}/v1/calls/{uuid}/talk"; @@ -414,11 +414,11 @@ public void TestStartTalk(bool passCreds, bool kitchenSink) CallCommandResponse response; if (passCreds) { - response = client.VoiceClient.StartTalk(uuid, command, creds); + response = await client.VoiceClient.StartTalkAsync(uuid, command, creds); } else { - response = client.VoiceClient.StartTalk(uuid, command); + response = await client.VoiceClient.StartTalkAsync(uuid, command); } Assert.Equal("Talk started", response.Message); Assert.Equal(uuid, response.Uuid); @@ -427,7 +427,7 @@ public void TestStartTalk(bool passCreds, bool kitchenSink) [Theory] [InlineData(true)] [InlineData(false)] - public void StopTalk(bool passCreds) + public async Task StopTalk(bool passCreds) { var uuid = "63f61863-4a51-4f6b-86e1-46edebcf9356"; var expectedUri = $"{ApiUrl}/v1/calls/{uuid}/talk"; @@ -444,11 +444,11 @@ public void StopTalk(bool passCreds) CallCommandResponse response; if (passCreds) { - response = client.VoiceClient.StopStream(uuid, creds); + response = await client.VoiceClient.StopStreamAsync(uuid, creds); } else { - response = client.VoiceClient.StopStream(uuid); + response = await client.VoiceClient.StopStreamAsync(uuid); } Assert.Equal("Talk stopped", response.Message); Assert.Equal(uuid, response.Uuid); @@ -457,7 +457,7 @@ public void StopTalk(bool passCreds) [Theory] [InlineData(true)] [InlineData(false)] - public void TestStartDtmf(bool passCreds) + public async Task TestStartDtmf(bool passCreds) { var uuid = "63f61863-4a51-4f6b-86e1-46edebcf9356"; var expectedUri = $"{ApiUrl}/v1/calls/{uuid}/talk"; @@ -475,11 +475,11 @@ public void TestStartDtmf(bool passCreds) CallCommandResponse response; if (passCreds) { - response = client.VoiceClient.StartDtmf(uuid, command, creds); + response = await client.VoiceClient.StartDtmfAsync(uuid, command, creds); } else { - response = client.VoiceClient.StartDtmf(uuid, command); + response = await client.VoiceClient.StartDtmfAsync(uuid, command); } Assert.Equal("DTMF sent", response.Message); Assert.Equal(uuid, response.Uuid); @@ -488,7 +488,7 @@ public void TestStartDtmf(bool passCreds) [Theory] [InlineData(true)] [InlineData(false)] - public void TestGetRecordings(bool passCreds) + public async Task TestGetRecordings(bool passCreds) { var expectedUri = $"{ApiUrl}/v1/calls/63f61863-4a51-4f6b-86e1-46edebcf9356"; var creds = Request.Credentials.FromAppIdAndPrivateKey(AppId, PrivateKey); @@ -499,11 +499,11 @@ public void TestGetRecordings(bool passCreds) GetRecordingResponse response; if (passCreds) { - response = client.VoiceClient.GetRecording(expectedUri, creds); + response = await client.VoiceClient.GetRecordingAsync(expectedUri, creds); } else { - response = client.VoiceClient.GetRecording(expectedUri); + response = await client.VoiceClient.GetRecordingAsync(expectedUri); } @@ -512,7 +512,7 @@ public void TestGetRecordings(bool passCreds) } [Fact] - public void CreateCallWithUnicodeCharecters() + public async Task CreateCallWithUnicodeCharecters() { var expectedUri = "https://api.nexmo.com/v1/calls/"; var expectedResponse = @"{ @@ -552,7 +552,7 @@ public void CreateCallWithUnicodeCharecters() var creds = Request.Credentials.FromAppIdAndPrivateKey(AppId, PrivateKey); var client = new VonageClient(creds); CallResponse response; - response = client.VoiceClient.CreateCall(request); + response = await client.VoiceClient.CreateCallAsync(request); Assert.Equal("63f61863-4a51-4f6b-86e1-46edebcf9356", response.Uuid); Assert.Equal("CON-f972836a-550f-45fa-956c-12a2ab5b7d22", response.ConversationUuid); Assert.Equal("outbound", response.Direction); diff --git a/Vonage/Accounts/AccountClient.cs b/Vonage/Accounts/AccountClient.cs index 662cacf72..eaa2ef3cc 100644 --- a/Vonage/Accounts/AccountClient.cs +++ b/Vonage/Accounts/AccountClient.cs @@ -1,4 +1,5 @@ using System; +using System.Threading.Tasks; using Vonage.Request; namespace Vonage.Accounts @@ -11,18 +12,18 @@ public AccountClient(Credentials creds = null) Credentials = creds; } - public Balance GetAccountBalance(Credentials creds = null) + public Task GetAccountBalanceAsync(Credentials creds = null) { - return ApiRequest.DoGetRequestWithQueryParameters( + return ApiRequest.DoGetRequestWithQueryParametersAsync( ApiRequest.GetBaseUriFor(typeof(AccountClient), "/account/get-balance"), ApiRequest.AuthType.Query, credentials: creds ?? Credentials); } - public TopUpResult TopUpAccountBalance(TopUpRequest request, Credentials creds = null) + public Task TopUpAccountBalanceAsync(TopUpRequest request, Credentials creds = null) { - return ApiRequest.DoGetRequestWithQueryParameters( + return ApiRequest.DoGetRequestWithQueryParametersAsync( ApiRequest.GetBaseUriFor(typeof(AccountClient), "/account/top-up"), ApiRequest.AuthType.Query, request, @@ -30,9 +31,9 @@ public TopUpResult TopUpAccountBalance(TopUpRequest request, Credentials creds = ); } - public AccountSettingsResult ChangeAccountSettings(AccountSettingsRequest request, Credentials creds = null) + public Task ChangeAccountSettingsAsync(AccountSettingsRequest request, Credentials creds = null) { - return ApiRequest.DoPostRequestUrlContentFromObject + return ApiRequest.DoPostRequestUrlContentFromObjectAsync ( ApiRequest.GetBaseUriFor(typeof(AccountClient), "/account/settings"), request, @@ -40,18 +41,18 @@ public AccountSettingsResult ChangeAccountSettings(AccountSettingsRequest reques ); } - public SecretsRequestResult RetrieveApiSecrets(string apiKey, Credentials creds = null) + public Task RetrieveApiSecretsAsync(string apiKey, Credentials creds = null) { - return ApiRequest.DoGetRequestWithQueryParameters( + return ApiRequest.DoGetRequestWithQueryParametersAsync( ApiRequest.GetBaseUri(ApiRequest.UriType.Api, $"/accounts/{apiKey}/secrets"), ApiRequest.AuthType.Basic, credentials: creds ?? Credentials ); } - public Secret CreateApiSecret(CreateSecretRequest request, string apiKey, Credentials creds = null) + public Task CreateApiSecretAsync(CreateSecretRequest request, string apiKey, Credentials creds = null) { - return ApiRequest.DoRequestWithJsonContent( + return ApiRequest.DoRequestWithJsonContentAsync( "POST", ApiRequest.GetBaseUri(ApiRequest.UriType.Api, $"/accounts/{apiKey}/secrets"), request, @@ -60,18 +61,18 @@ public Secret CreateApiSecret(CreateSecretRequest request, string apiKey, Creden ); } - public Secret RetrieveApiSecret(string secretId, string apiKey, Credentials creds = null) + public Task RetrieveApiSecretAsync(string secretId, string apiKey, Credentials creds = null) { - return ApiRequest.DoGetRequestWithQueryParameters( + return ApiRequest.DoGetRequestWithQueryParametersAsync( ApiRequest.GetBaseUri(ApiRequest.UriType.Api, $"/accounts/{apiKey}/secrets/{secretId}"), ApiRequest.AuthType.Basic, credentials: creds ?? Credentials ); } - public bool RevokeApiSecret(string secretId, string apiKey, Credentials creds = null) + public async Task RevokeApiSecretAsync(string secretId, string apiKey, Credentials creds = null) { - ApiRequest.DoDeleteRequestWithUrlContent( + await ApiRequest.DoDeleteRequestWithUrlContentAsync( ApiRequest.GetBaseUri(ApiRequest.UriType.Api, $"/accounts/{apiKey}/secrets/{secretId}"), null, ApiRequest.AuthType.Basic, diff --git a/Vonage/Accounts/IAccountClient.cs b/Vonage/Accounts/IAccountClient.cs index 832c4c619..8f209194d 100644 --- a/Vonage/Accounts/IAccountClient.cs +++ b/Vonage/Accounts/IAccountClient.cs @@ -1,3 +1,4 @@ +using System.Threading.Tasks; using Vonage.Request; namespace Vonage.Accounts @@ -9,7 +10,7 @@ public interface IAccountClient /// /// /// - Balance GetAccountBalance(Credentials creds = null); + Task GetAccountBalanceAsync(Credentials creds = null); /// /// You can top up your account using this API when you have enabled auto-reload in the dashboard. @@ -21,7 +22,7 @@ public interface IAccountClient /// /// /// - TopUpResult TopUpAccountBalance(TopUpRequest request, Credentials creds = null); + Task TopUpAccountBalanceAsync(TopUpRequest request, Credentials creds = null); /// /// Update the default callback URLs (where the webhooks are sent to) associated with your account: @@ -31,7 +32,7 @@ public interface IAccountClient /// /// /// - AccountSettingsResult ChangeAccountSettings(AccountSettingsRequest request, Credentials creds = null); + Task ChangeAccountSettingsAsync(AccountSettingsRequest request, Credentials creds = null); /// /// Many of Vonage's APIs are accessed using an API key and secret. It is recommended that you change or "rotate" @@ -42,7 +43,7 @@ public interface IAccountClient /// /// /// - SecretsRequestResult RetrieveApiSecrets(string apiKey=null, Credentials creds = null); + Task RetrieveApiSecretsAsync(string apiKey=null, Credentials creds = null); /// /// Createse an API Secret @@ -51,7 +52,7 @@ public interface IAccountClient /// The Api Key to create a secret for /// /// - Secret CreateApiSecret(CreateSecretRequest request, string apiKey=null, Credentials creds = null); + Task CreateApiSecretAsync(CreateSecretRequest request, string apiKey=null, Credentials creds = null); /// /// retrieves info about an api secret at the given id @@ -60,7 +61,7 @@ public interface IAccountClient /// Api Key the secret is for /// /// - Secret RetrieveApiSecret(string secretId, string apiKey=null, Credentials creds = null); + Task RetrieveApiSecretAsync(string secretId, string apiKey=null, Credentials creds = null); /// /// Deletes an Api Secret @@ -69,6 +70,6 @@ public interface IAccountClient /// the api key the secret is for /// /// - bool RevokeApiSecret(string secretId, string apiKey=null, Credentials creds = null); + Task RevokeApiSecretAsync(string secretId, string apiKey=null, Credentials creds = null); } } \ No newline at end of file diff --git a/Vonage/Applications/ApplicationClient.cs b/Vonage/Applications/ApplicationClient.cs index 690f37931..05eb41969 100644 --- a/Vonage/Applications/ApplicationClient.cs +++ b/Vonage/Applications/ApplicationClient.cs @@ -1,3 +1,4 @@ +using System.Threading.Tasks; using Vonage.Request; namespace Vonage.Applications @@ -9,9 +10,9 @@ public ApplicationClient(Credentials creds = null) { Credentials = creds; } - public Application CreateApplicaiton(CreateApplicationRequest request, Credentials creds = null) + public Task CreateApplicaitonAsync(CreateApplicationRequest request, Credentials creds = null) { - return ApiRequest.DoRequestWithJsonContent( + return ApiRequest.DoRequestWithJsonContentAsync( "POST", ApiRequest.GetBaseUri(ApiRequest.UriType.Api, "/v2/applications"), request, @@ -20,9 +21,9 @@ public Application CreateApplicaiton(CreateApplicationRequest request, Credentia ); } - public ApplicationPage ListApplications(ListApplicationsRequest request, Credentials creds = null) + public Task ListApplicationsAsync(ListApplicationsRequest request, Credentials creds = null) { - return ApiRequest.DoGetRequestWithQueryParameters( + return ApiRequest.DoGetRequestWithQueryParametersAsync( ApiRequest.GetBaseUri(ApiRequest.UriType.Api, "/v2/applications"), ApiRequest.AuthType.Basic, request, @@ -30,18 +31,18 @@ public ApplicationPage ListApplications(ListApplicationsRequest request, Credent ); } - public Application GetApplication(string id, Credentials creds = null) + public Task GetApplicationAsync(string id, Credentials creds = null) { - return ApiRequest.DoGetRequestWithQueryParameters( + return ApiRequest.DoGetRequestWithQueryParametersAsync( ApiRequest.GetBaseUri(ApiRequest.UriType.Api, $"/v2/applications/{id}"), ApiRequest.AuthType.Basic, credentials: creds ?? Credentials ); } - public Application UpdateApplication(string id, CreateApplicationRequest request, Credentials creds = null) + public Task UpdateApplicationAsync(string id, CreateApplicationRequest request, Credentials creds = null) { - return ApiRequest.DoRequestWithJsonContent( + return ApiRequest.DoRequestWithJsonContentAsync( "PUT", ApiRequest.GetBaseUri(ApiRequest.UriType.Api, $"/v2/applications/{id}"), request, @@ -50,9 +51,9 @@ public Application UpdateApplication(string id, CreateApplicationRequest request ); } - public bool DeleteApplication(string id, Credentials creds = null) + public async Task DeleteApplicationAsync(string id, Credentials creds = null) { - ApiRequest.DoDeleteRequestWithUrlContent( + await ApiRequest.DoDeleteRequestWithUrlContentAsync( ApiRequest.GetBaseUri(ApiRequest.UriType.Api, $"/v2/applications/{id}"), null, ApiRequest.AuthType.Basic, diff --git a/Vonage/Applications/IApplicationClient.cs b/Vonage/Applications/IApplicationClient.cs index f78016ffb..39a19859b 100644 --- a/Vonage/Applications/IApplicationClient.cs +++ b/Vonage/Applications/IApplicationClient.cs @@ -1,3 +1,4 @@ +using System.Threading.Tasks; using Vonage.Request; namespace Vonage.Applications @@ -10,7 +11,7 @@ public interface IApplicationClient /// /// /// - Application CreateApplicaiton(CreateApplicationRequest request, Credentials creds = null); + Task CreateApplicaitonAsync(CreateApplicationRequest request, Credentials creds = null); /// /// List applications @@ -18,7 +19,7 @@ public interface IApplicationClient /// /// /// - ApplicationPage ListApplications(ListApplicationsRequest request, Credentials creds = null); + Task ListApplicationsAsync(ListApplicationsRequest request, Credentials creds = null); /// /// Retrieves information about an application @@ -26,7 +27,7 @@ public interface IApplicationClient /// Id of the application to be retrieved /// /// - Application GetApplication(string id, Credentials creds = null); + Task GetApplicationAsync(string id, Credentials creds = null); /// /// Updates an Application @@ -35,7 +36,7 @@ public interface IApplicationClient /// /// /// - Application UpdateApplication(string id, CreateApplicationRequest request, Credentials creds = null); + Task UpdateApplicationAsync(string id, CreateApplicationRequest request, Credentials creds = null); /// /// Deletes an application: Cannot be undone @@ -43,6 +44,6 @@ public interface IApplicationClient /// Id of the application to be deleted /// /// - bool DeleteApplication(string id, Credentials creds = null); + Task DeleteApplicationAsync(string id, Credentials creds = null); } } \ No newline at end of file diff --git a/Vonage/Conversions/ConversionClient.cs b/Vonage/Conversions/ConversionClient.cs index 95874e371..616e641f5 100644 --- a/Vonage/Conversions/ConversionClient.cs +++ b/Vonage/Conversions/ConversionClient.cs @@ -1,3 +1,4 @@ +using System.Threading.Tasks; using Vonage.Request; namespace Vonage.Conversions @@ -10,9 +11,9 @@ public ConversionClient(Credentials creds = null) { Credentials = creds; } - public bool SmsConversion(ConversionRequest request, Credentials creds = null) + public async Task SmsConversionAsync(ConversionRequest request, Credentials creds = null) { - ApiRequest.DoPostRequestUrlContentFromObject + await ApiRequest.DoPostRequestUrlContentFromObjectAsync ( ApiRequest.GetBaseUri(ApiRequest.UriType.Api, "/conversions/sms"), request, @@ -21,9 +22,9 @@ public bool SmsConversion(ConversionRequest request, Credentials creds = null) return true; } - public bool VoiceConversion(ConversionRequest request, Credentials creds = null) + public async Task VoiceConversionAsync(ConversionRequest request, Credentials creds = null) { - ApiRequest.DoPostRequestUrlContentFromObject + await ApiRequest.DoPostRequestUrlContentFromObjectAsync ( ApiRequest.GetBaseUri(ApiRequest.UriType.Api, "/conversions/voice"), request, diff --git a/Vonage/Conversions/IConversionClient.cs b/Vonage/Conversions/IConversionClient.cs index e26212016..cb502ab52 100644 --- a/Vonage/Conversions/IConversionClient.cs +++ b/Vonage/Conversions/IConversionClient.cs @@ -1,3 +1,4 @@ +using System.Threading.Tasks; using Vonage.Request; namespace Vonage.Conversions @@ -11,7 +12,7 @@ public interface IConversionClient /// /// /// - bool SmsConversion(ConversionRequest request, Credentials creds = null); + Task SmsConversionAsync(ConversionRequest request, Credentials creds = null); /// /// Send a Conversion API request with information about the Call or Text-To-Speech identified by message-id. /// Vonage uses your conversion data and internal information about message-id to help improve our routing of messages in the future. @@ -19,6 +20,6 @@ public interface IConversionClient /// /// /// - bool VoiceConversion(ConversionRequest request, Credentials creds = null); + Task VoiceConversionAsync(ConversionRequest request, Credentials creds = null); } } \ No newline at end of file diff --git a/Vonage/Messaging/ISmsClient.cs b/Vonage/Messaging/ISmsClient.cs index 4b7ada8c2..3a73b9ecd 100644 --- a/Vonage/Messaging/ISmsClient.cs +++ b/Vonage/Messaging/ISmsClient.cs @@ -1,3 +1,4 @@ +using System.Threading.Tasks; using Vonage.Request; namespace Vonage.Messaging @@ -10,6 +11,6 @@ public interface ISmsClient /// /// /// - SendSmsResponse SendAnSms(SendSmsRequest request, Credentials creds = null); + Task SendAnSmsAsync(SendSmsRequest request, Credentials creds = null); } } \ No newline at end of file diff --git a/Vonage/Messaging/SmsClient.cs b/Vonage/Messaging/SmsClient.cs index 45914e034..a9b7b313b 100644 --- a/Vonage/Messaging/SmsClient.cs +++ b/Vonage/Messaging/SmsClient.cs @@ -1,3 +1,4 @@ +using System.Threading.Tasks; using Vonage.Request; namespace Vonage.Messaging @@ -18,9 +19,9 @@ public SmsClient(Credentials creds = null) /// (Optional) Overridden credentials for only this request /// Thrown when the status of a message is non-zero or response is empty /// - public SendSmsResponse SendAnSms(SendSmsRequest request, Credentials creds = null) + public async Task SendAnSmsAsync(SendSmsRequest request, Credentials creds = null) { - var result = ApiRequest.DoPostRequestUrlContentFromObject( + var result = await ApiRequest.DoPostRequestUrlContentFromObjectAsync( ApiRequest.GetBaseUri(ApiRequest.UriType.Rest, "/sms/json"), request, creds ?? Credentials diff --git a/Vonage/NumberInsights/INumberInsightClient.cs b/Vonage/NumberInsights/INumberInsightClient.cs index 34a157ee9..696bc7f64 100644 --- a/Vonage/NumberInsights/INumberInsightClient.cs +++ b/Vonage/NumberInsights/INumberInsightClient.cs @@ -1,3 +1,4 @@ +using System.Threading.Tasks; using Vonage.Request; namespace Vonage.NumberInsights @@ -10,7 +11,7 @@ public interface INumberInsightClient /// /// /// - BasicInsightResponse GetNumberInsightBasic(BasicNumberInsightRequest request, Credentials creds = null); + Task GetNumberInsightBasicAsync(BasicNumberInsightRequest request, Credentials creds = null); /// /// Provides standard number insight information about a number. @@ -18,8 +19,8 @@ public interface INumberInsightClient /// /// /// - StandardInsightResponse - GetNumberInsightStandard(StandardNumberInsightRequest request, Credentials creds = null); + Task + GetNumberInsightStandardAsync(StandardNumberInsightRequest request, Credentials creds = null); /// /// Provides advanced number insight information about a number synchronously, in the same way that the basic and standard endpoints do. @@ -28,7 +29,7 @@ public interface INumberInsightClient /// /// /// - AdvancedInsightsResponse GetNumberInsightAdvanced(AdvancedNumberInsightRequest request, + Task GetNumberInsightAdvancedAsync(AdvancedNumberInsightRequest request, Credentials creds = null); /// @@ -38,7 +39,7 @@ AdvancedInsightsResponse GetNumberInsightAdvanced(AdvancedNumberInsightRequest r /// /// /// - AdvancedInsightsAsyncResponse GetNumberInsightAsync(AdvancedNumberInsightAsynchronousRequest request, + Task GetNumberInsightAsyncAsync(AdvancedNumberInsightAsynchronousRequest request, Credentials creds = null); } } \ No newline at end of file diff --git a/Vonage/NumberInsights/NumberInsightClient.cs b/Vonage/NumberInsights/NumberInsightClient.cs index 7e46b0e71..275be8162 100644 --- a/Vonage/NumberInsights/NumberInsightClient.cs +++ b/Vonage/NumberInsights/NumberInsightClient.cs @@ -1,3 +1,4 @@ +using System.Threading.Tasks; using Vonage.Request; namespace Vonage.NumberInsights @@ -10,9 +11,9 @@ public NumberInsightClient(Credentials creds = null) { Credentials = creds; } - public BasicInsightResponse GetNumberInsightBasic(BasicNumberInsightRequest request, Credentials creds = null) + public async Task GetNumberInsightBasicAsync(BasicNumberInsightRequest request, Credentials creds = null) { - var response = ApiRequest.DoGetRequestWithQueryParameters( + var response = await ApiRequest.DoGetRequestWithQueryParametersAsync( ApiRequest.GetBaseUri(ApiRequest.UriType.Api, "/ni/basic/json"), ApiRequest.AuthType.Query, request, @@ -22,9 +23,9 @@ public BasicInsightResponse GetNumberInsightBasic(BasicNumberInsightRequest requ return response; } - public StandardInsightResponse GetNumberInsightStandard(StandardNumberInsightRequest request, Credentials creds = null) + public async Task GetNumberInsightStandardAsync(StandardNumberInsightRequest request, Credentials creds = null) { - var response = ApiRequest.DoGetRequestWithQueryParameters( + var response = await ApiRequest.DoGetRequestWithQueryParametersAsync( ApiRequest.GetBaseUri(ApiRequest.UriType.Api, "/ni/standard/json"), ApiRequest.AuthType.Query, request, @@ -34,10 +35,10 @@ public StandardInsightResponse GetNumberInsightStandard(StandardNumberInsightReq return response; } - public AdvancedInsightsResponse GetNumberInsightAdvanced(AdvancedNumberInsightRequest request, + public async Task GetNumberInsightAdvancedAsync(AdvancedNumberInsightRequest request, Credentials creds = null) { - var response = ApiRequest.DoGetRequestWithQueryParameters( + var response = await ApiRequest.DoGetRequestWithQueryParametersAsync( ApiRequest.GetBaseUri(ApiRequest.UriType.Api, "/ni/advanced/json"), ApiRequest.AuthType.Query, request, @@ -47,9 +48,9 @@ public AdvancedInsightsResponse GetNumberInsightAdvanced(AdvancedNumberInsightRe return response; } - public AdvancedInsightsAsyncResponse GetNumberInsightAsync(AdvancedNumberInsightAsynchronousRequest request, Credentials creds = null) + public async Task GetNumberInsightAsyncAsync(AdvancedNumberInsightAsynchronousRequest request, Credentials creds = null) { - var response = ApiRequest.DoGetRequestWithQueryParameters( + var response = await ApiRequest.DoGetRequestWithQueryParametersAsync( ApiRequest.GetBaseUri(ApiRequest.UriType.Api, "/ni/advanced/async/json"), ApiRequest.AuthType.Query, request, diff --git a/Vonage/Numbers/INumbersClient.cs b/Vonage/Numbers/INumbersClient.cs index 5ae640a1f..76be75235 100644 --- a/Vonage/Numbers/INumbersClient.cs +++ b/Vonage/Numbers/INumbersClient.cs @@ -1,3 +1,4 @@ +using System.Threading.Tasks; using Vonage.Request; namespace Vonage.Numbers @@ -10,7 +11,7 @@ public interface INumbersClient /// /// /// - NumbersSearchResponse GetOwnedNumbers(NumberSearchRequest request, Credentials creds = null); + Task GetOwnedNumbersAsync(NumberSearchRequest request, Credentials creds = null); /// /// Retrieve inbound numbers that are available for the specified country. @@ -18,7 +19,7 @@ public interface INumbersClient /// /// /// - NumbersSearchResponse GetAvailableNumbers(NumberSearchRequest request, Credentials creds = null); + Task GetAvailableNumbersAsync(NumberSearchRequest request, Credentials creds = null); /// /// Request to purchase a specific inbound number. @@ -26,7 +27,7 @@ public interface INumbersClient /// /// /// - NumberTransactionResponse BuyANumber(NumberTransactionRequest request, Credentials creds = null); + Task BuyANumberAsync(NumberTransactionRequest request, Credentials creds = null); /// /// Cancel your subscription for a specific inbound number. @@ -34,7 +35,7 @@ public interface INumbersClient /// /// /// - NumberTransactionResponse CancelANumber(NumberTransactionRequest request, Credentials creds = null); + Task CancelANumberAsync(NumberTransactionRequest request, Credentials creds = null); /// /// Change the behaviour of a number that you own. @@ -42,6 +43,6 @@ public interface INumbersClient /// /// /// - NumberTransactionResponse UpdateANumber(UpdateNumberRequest request, Credentials creds = null); + Task UpdateANumberAsync(UpdateNumberRequest request, Credentials creds = null); } } \ No newline at end of file diff --git a/Vonage/Numbers/NumbersClient.cs b/Vonage/Numbers/NumbersClient.cs index bcc47cd66..0f94a6cdf 100644 --- a/Vonage/Numbers/NumbersClient.cs +++ b/Vonage/Numbers/NumbersClient.cs @@ -1,4 +1,5 @@ using System; +using System.Threading.Tasks; using Vonage.Request; namespace Vonage.Numbers @@ -12,9 +13,9 @@ public NumbersClient(Credentials creds = null) public Credentials Credentials { get; set; } - public NumbersSearchResponse GetOwnedNumbers(NumberSearchRequest request, Credentials creds = null) + public Task GetOwnedNumbersAsync(NumberSearchRequest request, Credentials creds = null) { - return ApiRequest.DoGetRequestWithQueryParameters( + return ApiRequest.DoGetRequestWithQueryParametersAsync( ApiRequest.GetBaseUri(ApiRequest.UriType.Rest, "/account/numbers"), ApiRequest.AuthType.Query, request, @@ -22,9 +23,9 @@ public NumbersSearchResponse GetOwnedNumbers(NumberSearchRequest request, Creden ); } - public NumbersSearchResponse GetAvailableNumbers(NumberSearchRequest request, Credentials creds = null) + public Task GetAvailableNumbersAsync(NumberSearchRequest request, Credentials creds = null) { - return ApiRequest.DoGetRequestWithQueryParameters( + return ApiRequest.DoGetRequestWithQueryParametersAsync( ApiRequest.GetBaseUri(ApiRequest.UriType.Rest, "/number/search"), ApiRequest.AuthType.Query, request, @@ -32,9 +33,9 @@ public NumbersSearchResponse GetAvailableNumbers(NumberSearchRequest request, Cr ); } - public NumberTransactionResponse BuyANumber(NumberTransactionRequest request, Credentials creds = null) + public async Task BuyANumberAsync(NumberTransactionRequest request, Credentials creds = null) { - var response = ApiRequest.DoPostRequestUrlContentFromObject( + var response = await ApiRequest.DoPostRequestUrlContentFromObjectAsync( ApiRequest.GetBaseUri(ApiRequest.UriType.Rest, "/number/buy"), request, creds ?? Credentials @@ -43,9 +44,9 @@ public NumberTransactionResponse BuyANumber(NumberTransactionRequest request, Cr return response; } - public NumberTransactionResponse CancelANumber(NumberTransactionRequest request, Credentials creds = null) + public async Task CancelANumberAsync(NumberTransactionRequest request, Credentials creds = null) { - var response = ApiRequest.DoPostRequestUrlContentFromObject( + var response = await ApiRequest.DoPostRequestUrlContentFromObjectAsync( ApiRequest.GetBaseUri(ApiRequest.UriType.Rest, "/number/cancel"), request, creds ?? Credentials @@ -54,9 +55,9 @@ public NumberTransactionResponse CancelANumber(NumberTransactionRequest request, return response; } - public NumberTransactionResponse UpdateANumber(UpdateNumberRequest request, Credentials creds = null) + public async Task UpdateANumberAsync(UpdateNumberRequest request, Credentials creds = null) { - var response = ApiRequest.DoPostRequestUrlContentFromObject( + var response = await ApiRequest.DoPostRequestUrlContentFromObjectAsync( ApiRequest.GetBaseUri(ApiRequest.UriType.Rest, "/number/update"), request, creds ?? Credentials diff --git a/Vonage/Pricing/IPricingClient.cs b/Vonage/Pricing/IPricingClient.cs index 6f197e603..3bc61976c 100644 --- a/Vonage/Pricing/IPricingClient.cs +++ b/Vonage/Pricing/IPricingClient.cs @@ -1,3 +1,4 @@ +using System.Threading.Tasks; using Vonage.Request; namespace Vonage.Pricing @@ -12,7 +13,7 @@ public interface IPricingClient /// /// /// - Country RetrievePricingCountry(string type, PricingCountryRequest request, Credentials creds = null); + Task RetrievePricingCountryAsync(string type, PricingCountryRequest request, Credentials creds = null); /// /// Retrieves the pricing information for all countries. @@ -21,7 +22,7 @@ public interface IPricingClient /// either sms, sms-transit or voice. /// /// - PricingResult RetrievePricingAllCountries(string type, Credentials creds = null); + Task RetrievePricingAllCountriesAsync(string type, Credentials creds = null); /// /// Retrieves the pricing information based on the dialing prefix. @@ -31,6 +32,6 @@ public interface IPricingClient /// /// /// - PricingResult RetrievePrefixPricing(string type, PricingPrefixRequest request, Credentials creds = null); + Task RetrievePrefixPricingAsync(string type, PricingPrefixRequest request, Credentials creds = null); } } \ No newline at end of file diff --git a/Vonage/Pricing/PricingClient.cs b/Vonage/Pricing/PricingClient.cs index 64c34a8e2..8ec8d5cb7 100644 --- a/Vonage/Pricing/PricingClient.cs +++ b/Vonage/Pricing/PricingClient.cs @@ -1,3 +1,4 @@ +using System.Threading.Tasks; using Vonage.Request; namespace Vonage.Pricing @@ -11,9 +12,9 @@ public PricingClient(Credentials creds = null) public Credentials Credentials { get; set; } - public Country RetrievePricingCountry(string type, PricingCountryRequest request, Credentials creds = null) + public Task RetrievePricingCountryAsync(string type, PricingCountryRequest request, Credentials creds = null) { - return ApiRequest.DoGetRequestWithQueryParameters + return ApiRequest.DoGetRequestWithQueryParametersAsync ( ApiRequest.GetBaseUri(ApiRequest.UriType.Rest, $"/account/get-pricing/outbound/{type}"), ApiRequest.AuthType.Query, @@ -22,9 +23,9 @@ public Country RetrievePricingCountry(string type, PricingCountryRequest request ); } - public PricingResult RetrievePricingAllCountries(string type, Credentials creds = null) + public Task RetrievePricingAllCountriesAsync(string type, Credentials creds = null) { - return ApiRequest.DoGetRequestWithQueryParameters + return ApiRequest.DoGetRequestWithQueryParametersAsync ( ApiRequest.GetBaseUri(ApiRequest.UriType.Rest, $"/account/get-pricing/outbound/{type}"), ApiRequest.AuthType.Query, @@ -32,9 +33,9 @@ public PricingResult RetrievePricingAllCountries(string type, Credentials creds ); } - public PricingResult RetrievePrefixPricing(string type, PricingPrefixRequest request, Credentials creds = null) + public Task RetrievePrefixPricingAsync(string type, PricingPrefixRequest request, Credentials creds = null) { - return ApiRequest.DoGetRequestWithQueryParameters + return ApiRequest.DoGetRequestWithQueryParametersAsync ( ApiRequest.GetBaseUri(ApiRequest.UriType.Rest, $"/account/get-prefix-pricing/outbound/{type}"), ApiRequest.AuthType.Query, diff --git a/Vonage/Redaction/IRedactClient.cs b/Vonage/Redaction/IRedactClient.cs index 1370edc82..53ee4a1f1 100644 --- a/Vonage/Redaction/IRedactClient.cs +++ b/Vonage/Redaction/IRedactClient.cs @@ -1,3 +1,4 @@ +using System.Threading.Tasks; using Vonage.Request; namespace Vonage.Redaction @@ -10,6 +11,6 @@ public interface IRedactClient /// /// /// - bool Redact(RedactRequest request, Credentials creds = null); + Task RedactAsync(RedactRequest request, Credentials creds = null); } } \ No newline at end of file diff --git a/Vonage/Redaction/RedactClient.cs b/Vonage/Redaction/RedactClient.cs index 13227e06d..5887defb5 100644 --- a/Vonage/Redaction/RedactClient.cs +++ b/Vonage/Redaction/RedactClient.cs @@ -1,3 +1,4 @@ +using System.Threading.Tasks; using Vonage.Request; namespace Vonage.Redaction @@ -12,9 +13,9 @@ public RedactClient(Credentials creds = null) } - public bool Redact(RedactRequest request, Credentials creds = null) + public async Task RedactAsync(RedactRequest request, Credentials creds = null) { - ApiRequest.DoRequestWithJsonContent + await ApiRequest.DoRequestWithJsonContentAsync ( "POST", ApiRequest.GetBaseUri(ApiRequest.UriType.Api,"/v1/redact/transaction"), diff --git a/Vonage/Request/ApiRequest.cs b/Vonage/Request/ApiRequest.cs index 51d24a6b9..58e199f74 100644 --- a/Vonage/Request/ApiRequest.cs +++ b/Vonage/Request/ApiRequest.cs @@ -11,6 +11,7 @@ using System.Reflection; using System.Text; using Microsoft.Extensions.Logging; +using System.Threading.Tasks; namespace Vonage.Request { @@ -244,13 +245,13 @@ internal static StringBuilder GetQueryStringBuilderFor(object parameters, AuthTy /// Parameters required by the endpoint (do not include credentials) /// (Optional) Overridden credentials for only this request /// Thrown if the API encounters a non-zero result - public static T DoGetRequestWithQueryParameters(Uri uri, AuthType authType, object parameters = null, Credentials credentials = null) + public static async Task DoGetRequestWithQueryParametersAsync(Uri uri, AuthType authType, object parameters = null, Credentials credentials = null) { if (parameters == null) parameters = new Dictionary(); var sb = GetQueryStringBuilderFor(parameters, authType, credentials); var requestUri = new Uri(uri + (sb.Length != 0 ? "?" + sb : "")); - return SendGetRequest(requestUri, authType, credentials); + return await SendGetRequestAsync(requestUri, authType, credentials); } /// @@ -261,7 +262,7 @@ public static T DoGetRequestWithQueryParameters(Uri uri, AuthType authType, o /// /// /// Thrown if the API encounters a non-zero result - private static T SendGetRequest(Uri uri, AuthType authType, Credentials creds) + private static async Task SendGetRequestAsync(Uri uri, AuthType authType, Credentials creds) { var logger = Logger.LogProvider.GetLogger(LOGGER_CATEGORY); var appId = creds?.ApplicationId ?? Configuration.Instance.Settings["appSettings:Vonage.Application.Id"]; @@ -288,7 +289,7 @@ private static T SendGetRequest(Uri uri, AuthType authType, Credentials creds Jwt.CreateToken(appId, appKeyPath)); } logger.LogDebug($"GET {uri}"); - var json = SendHttpRequest(req).JsonResponse; + var json = (await SendHttpRequestAsync(req)).JsonResponse; return JsonConvert.DeserializeObject(json); } @@ -302,7 +303,7 @@ private static T SendGetRequest(Uri uri, AuthType authType, Credentials creds /// (Optional) Overridden credentials for only this request /// thrown if an error is encountered when talking to the API /// - public static VonageResponse DoRequestWithUrlContent(string method, Uri uri, Dictionary parameters, AuthType authType = AuthType.Query, Credentials creds = null) + public static async Task DoRequestWithUrlContentAsync(string method, Uri uri, Dictionary parameters, AuthType authType = AuthType.Query, Credentials creds = null) { var logger = Logger.LogProvider.GetLogger(LOGGER_CATEGORY); var sb = new StringBuilder(); @@ -332,7 +333,7 @@ public static VonageResponse DoRequestWithUrlContent(string method, Uri uri, Dic req.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/x-www-form-urlencoded"); logger.LogDebug($"{method} {uri} {sb}"); - return SendHttpRequest(req); + return await SendHttpRequestAsync(req); } /// @@ -341,11 +342,11 @@ public static VonageResponse DoRequestWithUrlContent(string method, Uri uri, Dic /// /// thrown if an error is encountered when talking to the API /// - public static VonageResponse SendHttpRequest(HttpRequestMessage req) + public static async Task SendHttpRequestAsync(HttpRequestMessage req) { var logger = Logger.LogProvider.GetLogger(LOGGER_CATEGORY); - var response = Configuration.Instance.Client.SendAsync(req).Result; - var stream = response.Content.ReadAsStreamAsync().Result; + var response = await Configuration.Instance.Client.SendAsync(req); + var stream = await response.Content.ReadAsStreamAsync(); string json; using (var sr = new StreamReader(stream)) { @@ -378,7 +379,7 @@ public static VonageResponse SendHttpRequest(HttpRequestMessage req) /// Authorization type used on the API /// (Optional) Overridden credentials for only this request /// thrown if an error is encountered when talking to the API - public static T DoRequestWithJsonContent(string method, Uri uri, object payload, AuthType authType, Credentials creds) + public static async Task DoRequestWithJsonContentAsync(string method, Uri uri, object payload, AuthType authType, Credentials creds) { var appId = creds?.ApplicationId ?? Configuration.Instance.Settings["appSettings:Vonage.Application.Id"]; var appKeyPath = creds?.ApplicationKey ?? Configuration.Instance.Settings["appSettings:Vonage.Application.Key"]; @@ -422,7 +423,7 @@ public static T DoRequestWithJsonContent(string method, Uri uri, object paylo var data = Encoding.UTF8.GetBytes(json); req.Content = new ByteArrayContent(data); req.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json"); - var json_response = SendHttpRequest(req).JsonResponse; + var json_response = (await SendHttpRequestAsync(req)).JsonResponse; return JsonConvert.DeserializeObject(json_response); } @@ -434,7 +435,7 @@ public static T DoRequestWithJsonContent(string method, Uri uri, object paylo /// /// HttpResponseMessage /// thrown if an error is encountered when talking to the API - public static HttpResponseMessage DoGetRequestWithJwt(Uri uri, Credentials creds) + public static async Task DoGetRequestWithJwtAsync(Uri uri, Credentials creds) { var logger = Logger.LogProvider.GetLogger(LOGGER_CATEGORY); var appId = creds?.ApplicationId ?? Configuration.Instance.Settings["appSettings:Vonage.Application.Id"]; @@ -453,7 +454,7 @@ public static HttpResponseMessage DoGetRequestWithJwt(Uri uri, Credentials creds logger.LogDebug($"GET {uri}"); - var result = Configuration.Instance.Client.SendAsync(req).Result; + var result = await Configuration.Instance.Client.SendAsync(req); try { @@ -477,10 +478,10 @@ public static HttpResponseMessage DoGetRequestWithJwt(Uri uri, Credentials creds /// /// /// thrown if an error is encountered when talking to the API - public static T DoPostRequestUrlContentFromObject(Uri uri, object parameters, Credentials creds = null) + public static async Task DoPostRequestUrlContentFromObjectAsync(Uri uri, object parameters, Credentials creds = null) { var apiParams = GetParameters(parameters); - return DoPostRequestWithUrlContent(uri, apiParams, creds); + return await DoPostRequestWithUrlContentAsync(uri, apiParams, creds); } /// @@ -492,9 +493,9 @@ public static T DoPostRequestUrlContentFromObject(Uri uri, object parameters, /// /// /// thrown if an error is encountered when talking to the API - public static T DoPostRequestWithUrlContent(Uri uri, Dictionary parameters, Credentials creds = null) + public static async Task DoPostRequestWithUrlContentAsync(Uri uri, Dictionary parameters, Credentials creds = null) { - var response = DoRequestWithUrlContent("POST", uri, parameters, creds:creds); + var response = await DoRequestWithUrlContentAsync("POST", uri, parameters, creds:creds); return JsonConvert.DeserializeObject(response.JsonResponse); } @@ -506,6 +507,6 @@ public static T DoPostRequestWithUrlContent(Uri uri, Dictionary /// /// thrown if an error is encountered when talking to the API - public static VonageResponse DoDeleteRequestWithUrlContent(Uri uri, Dictionary parameters, AuthType authType = AuthType.Query, Credentials creds = null) => DoRequestWithUrlContent("DELETE", uri, parameters, authType, creds); + public static async Task DoDeleteRequestWithUrlContentAsync(Uri uri, Dictionary parameters, AuthType authType = AuthType.Query, Credentials creds = null) => await DoRequestWithUrlContentAsync("DELETE", uri, parameters, authType, creds); } } \ No newline at end of file diff --git a/Vonage/ShortCodes/IShortCodesClient.cs b/Vonage/ShortCodes/IShortCodesClient.cs index b6386f13e..2f783c896 100644 --- a/Vonage/ShortCodes/IShortCodesClient.cs +++ b/Vonage/ShortCodes/IShortCodesClient.cs @@ -1,15 +1,16 @@ +using System.Threading.Tasks; using Vonage.Request; namespace Vonage.ShortCodes { public interface IShortCodesClient { - OptInSearchResponse QueryOptIns(OptInQueryRequest request, Credentials creds = null); + Task QueryOptInsAsync(OptInQueryRequest request, Credentials creds = null); - OptInRecord ManageOptIn(OptInManageRequest request, Credentials creds = null); + Task ManageOptInAsync(OptInManageRequest request, Credentials creds = null); - AlertResponse SendAlert(AlertRequest request, Credentials creds = null); + Task SendAlertAsync(AlertRequest request, Credentials creds = null); - TwoFactorAuthResponse SendTwoFactorAuth(TwoFactorAuthRequest request, Credentials creds = null); + Task SendTwoFactorAuthAsync(TwoFactorAuthRequest request, Credentials creds = null); } } \ No newline at end of file diff --git a/Vonage/ShortCodes/ShortCodesClient.cs b/Vonage/ShortCodes/ShortCodesClient.cs index 15d7bb74c..4f0c2ed23 100644 --- a/Vonage/ShortCodes/ShortCodesClient.cs +++ b/Vonage/ShortCodes/ShortCodesClient.cs @@ -1,3 +1,4 @@ +using System.Threading.Tasks; using Vonage.Request; namespace Vonage.ShortCodes @@ -10,36 +11,36 @@ public ShortCodesClient(Credentials credentials = null) { Credentials = credentials; } - public OptInSearchResponse QueryOptIns(OptInQueryRequest request, Credentials creds = null) + public Task QueryOptInsAsync(OptInQueryRequest request, Credentials creds = null) { - return ApiRequest.DoGetRequestWithQueryParameters( + return ApiRequest.DoGetRequestWithQueryParametersAsync( ApiRequest.GetBaseUri(ApiRequest.UriType.Rest, "/sc/us/alert/opt-in/query/json"), ApiRequest.AuthType.Query, request, creds ?? Credentials); } - public OptInRecord ManageOptIn(OptInManageRequest request, Credentials creds = null) + public Task ManageOptInAsync(OptInManageRequest request, Credentials creds = null) { - return ApiRequest.DoGetRequestWithQueryParameters( + return ApiRequest.DoGetRequestWithQueryParametersAsync( ApiRequest.GetBaseUri(ApiRequest.UriType.Rest, "/sc/us/alert/opt-in/manage/json"), ApiRequest.AuthType.Query, request, creds ?? Credentials); } - public AlertResponse SendAlert(AlertRequest request, Credentials creds = null) + public Task SendAlertAsync(AlertRequest request, Credentials creds = null) { - return ApiRequest.DoGetRequestWithQueryParameters( + return ApiRequest.DoGetRequestWithQueryParametersAsync( ApiRequest.GetBaseUri(ApiRequest.UriType.Rest, "/sc/us/alert/json"), ApiRequest.AuthType.Query, request, creds ?? Credentials); } - public TwoFactorAuthResponse SendTwoFactorAuth(TwoFactorAuthRequest request, Credentials creds = null) + public Task SendTwoFactorAuthAsync(TwoFactorAuthRequest request, Credentials creds = null) { - return ApiRequest.DoGetRequestWithQueryParameters( + return ApiRequest.DoGetRequestWithQueryParametersAsync( ApiRequest.GetBaseUri(ApiRequest.UriType.Rest, "/sc/us/2fa/json"), ApiRequest.AuthType.Query, request, diff --git a/Vonage/Verify/IVerifyClient.cs b/Vonage/Verify/IVerifyClient.cs index 1afe2c110..c6387885c 100644 --- a/Vonage/Verify/IVerifyClient.cs +++ b/Vonage/Verify/IVerifyClient.cs @@ -1,3 +1,4 @@ +using System.Threading.Tasks; using Vonage.Request; namespace Vonage.Verify @@ -10,7 +11,7 @@ public interface IVerifyClient /// /// /// - VerifyResponse VerifyRequest(VerifyRequest request, Credentials creds = null); + Task VerifyRequestAsync(VerifyRequest request, Credentials creds = null); /// /// Use Verify check to confirm that the PIN you received from your user matches the one sent by Vonage in your Verify request @@ -18,7 +19,7 @@ public interface IVerifyClient /// /// /// - VerifyCheckResponse VerifyCheck(VerifyCheckRequest request, Credentials creds = null); + Task VerifyCheckAsync(VerifyCheckRequest request, Credentials creds = null); /// /// Use Verify search to check the status of past or current verification requests @@ -26,7 +27,7 @@ public interface IVerifyClient /// /// /// - VerifySearchResponse VerifySearch(VerifySearchRequest request, Credentials creds = null); + Task VerifySearchAsync(VerifySearchRequest request, Credentials creds = null); /// /// Control the progress of your Verify requests. To cancel an existing Verify request, or to trigger the next verification event @@ -34,7 +35,7 @@ public interface IVerifyClient /// /// /// - VerifyControlResponse VerifyControl(VerifyControlRequest request, Credentials creds = null); + Task VerifyControlAsync(VerifyControlRequest request, Credentials creds = null); /// /// Use Verify request to generate and send a PIN to your user to authorize a payment: @@ -45,6 +46,6 @@ public interface IVerifyClient /// /// /// - VerifyResponse VerifyRequestWithPSD2(Psd2Request request, Credentials creds = null); + Task VerifyRequestWithPSD2Async(Psd2Request request, Credentials creds = null); } } \ No newline at end of file diff --git a/Vonage/Verify/VerifyClient.cs b/Vonage/Verify/VerifyClient.cs index 25a6148af..52420fb02 100644 --- a/Vonage/Verify/VerifyClient.cs +++ b/Vonage/Verify/VerifyClient.cs @@ -1,3 +1,4 @@ +using System.Threading.Tasks; using Vonage.Request; namespace Vonage.Verify @@ -10,9 +11,9 @@ public VerifyClient(Credentials creds = null) { Credentials = creds; } - public VerifyResponse VerifyRequest(VerifyRequest request, Credentials creds = null) + public async Task VerifyRequestAsync(VerifyRequest request, Credentials creds = null) { - var response = ApiRequest.DoPostRequestUrlContentFromObject( + var response = await ApiRequest.DoPostRequestUrlContentFromObjectAsync( ApiRequest.GetBaseUri(ApiRequest.UriType.Api, "/verify/json"), request, creds ?? Credentials @@ -21,9 +22,9 @@ public VerifyResponse VerifyRequest(VerifyRequest request, Credentials creds = n return response; } - public VerifyCheckResponse VerifyCheck(VerifyCheckRequest request, Credentials creds = null) + public async Task VerifyCheckAsync(VerifyCheckRequest request, Credentials creds = null) { - var response = ApiRequest.DoPostRequestUrlContentFromObject( + var response = await ApiRequest.DoPostRequestUrlContentFromObjectAsync( ApiRequest.GetBaseUri(ApiRequest.UriType.Api, "/verify/check/json"), request, creds ?? Credentials @@ -32,9 +33,9 @@ public VerifyCheckResponse VerifyCheck(VerifyCheckRequest request, Credentials c return response; } - public VerifySearchResponse VerifySearch(VerifySearchRequest request, Credentials creds = null) + public Task VerifySearchAsync(VerifySearchRequest request, Credentials creds = null) { - return ApiRequest.DoGetRequestWithQueryParameters( + return ApiRequest.DoGetRequestWithQueryParametersAsync( ApiRequest.GetBaseUri(ApiRequest.UriType.Api, "/verify/search/json"), ApiRequest.AuthType.Query, request, @@ -42,9 +43,9 @@ public VerifySearchResponse VerifySearch(VerifySearchRequest request, Credential ); } - public VerifyControlResponse VerifyControl(VerifyControlRequest request, Credentials creds = null) + public async Task VerifyControlAsync(VerifyControlRequest request, Credentials creds = null) { - var response = ApiRequest.DoPostRequestUrlContentFromObject( + var response = await ApiRequest.DoPostRequestUrlContentFromObjectAsync( ApiRequest.GetBaseUri(ApiRequest.UriType.Api, "/verify/control/json"), request, creds ?? Credentials @@ -53,9 +54,9 @@ public VerifyControlResponse VerifyControl(VerifyControlRequest request, Credent return response; } - public VerifyResponse VerifyRequestWithPSD2(Psd2Request request, Credentials creds) + public async Task VerifyRequestWithPSD2Async(Psd2Request request, Credentials creds) { - var response = ApiRequest.DoPostRequestUrlContentFromObject( + var response = await ApiRequest.DoPostRequestUrlContentFromObjectAsync( ApiRequest.GetBaseUri(ApiRequest.UriType.Api, "/verify/psd2/json"), request, creds ?? Credentials diff --git a/Vonage/Voice/IVoiceClient.cs b/Vonage/Voice/IVoiceClient.cs index 6b7f55525..c60df8be2 100644 --- a/Vonage/Voice/IVoiceClient.cs +++ b/Vonage/Voice/IVoiceClient.cs @@ -1,3 +1,4 @@ +using System.Threading.Tasks; using Vonage.Common; using Vonage.Request; @@ -12,7 +13,7 @@ public interface IVoiceClient /// (Optional) Overridden credentials for only this request /// /// thrown if an error is encountered when talking to the API - CallResponse CreateCall(CallCommand command, Credentials creds = null); + Task CreateCallAsync(CallCommand command, Credentials creds = null); /// /// GET /v1/calls - retrieve information about all your Calls @@ -20,7 +21,7 @@ public interface IVoiceClient /// (Optional) Overridden credentials for only this request /// /// thrown if an error is encountered when talking to the API - PageResponse GetCalls(CallSearchFilter filter, Credentials creds = null); + Task> GetCallsAsync(CallSearchFilter filter, Credentials creds = null); /// /// GET /v1/calls/{uuid} - retrieve information about a single Call @@ -28,7 +29,7 @@ public interface IVoiceClient /// id of call /// (Optional) Overridden credentials for only this request /// thrown if an error is encountered when talking to the API - CallRecord GetCall(string id, Credentials creds = null); + Task GetCallAsync(string id, Credentials creds = null); /// /// PUT /v1/calls/{uuid} - modify an existing Call @@ -37,7 +38,7 @@ public interface IVoiceClient /// Command to execute against call /// (Optional) Overridden credentials for only this request /// thrown if an error is encountered when talking to the API - bool UpdateCall(string id, CallEditCommand command, Credentials creds = null); + Task UpdateCallAsync(string id, CallEditCommand command, Credentials creds = null); /// /// PUT /v1/calls/{uuid}/stream - stream an audio file to an active Call @@ -46,7 +47,7 @@ public interface IVoiceClient /// Command to execute against call /// (Optional) Overridden credentials for only this request /// thrown if an error is encountered when talking to the API - CallCommandResponse StartStream(string id, StreamCommand command, Credentials creds = null); + Task StartStreamAsync(string id, StreamCommand command, Credentials creds = null); /// /// DELETE /v1/calls/{uuid}/stream - stop streaming an audio file to an active Call @@ -54,7 +55,7 @@ public interface IVoiceClient /// id of call /// (Optional) Overridden credentials for only this request /// thrown if an error is encountered when talking to the API - CallCommandResponse StopStream(string id, Credentials creds = null); + Task StopStreamAsync(string id, Credentials creds = null); /// /// PUT /v1/calls/{uuid}/talk - send a synthesized speech message to an active Call @@ -63,7 +64,7 @@ public interface IVoiceClient /// Command to execute against call /// (Optional) Overridden credentials for only this request /// thrown if an error is encountered when talking to the API - CallCommandResponse StartTalk(string id, TalkCommand cmd, Credentials creds = null); + Task StartTalkAsync(string id, TalkCommand cmd, Credentials creds = null); /// /// DELETE /v1/calls/{uuid}/talk - stop sending a synthesized speech message to an active Call @@ -71,7 +72,7 @@ public interface IVoiceClient /// id of call /// (Optional) Overridden credentials for only this request /// thrown if an error is encountered when talking to the API - CallCommandResponse StopTalk(string id, Credentials creds = null); + Task StopTalkAsync(string id, Credentials creds = null); /// /// PUT /v1/calls/{uuid}/dtmf - send Dual-tone multi-frequency(DTMF) tones to an active Call @@ -80,7 +81,7 @@ public interface IVoiceClient /// Command to execute against call /// (Optional) Overridden credentials for only this request /// thrown if an error is encountered when talking to the API - CallCommandResponse StartDtmf(string id, DtmfCommand cmd, Credentials creds = null); + Task StartDtmfAsync(string id, DtmfCommand cmd, Credentials creds = null); /// /// GET - retrieves the recording from a call based off of the input url @@ -89,6 +90,6 @@ public interface IVoiceClient /// Overridden credentials /// thrown if an error is encountered when talking to the API /// A response containing a byte array representing the file stream - GetRecordingResponse GetRecording(string recordingUrl, Credentials creds = null); + Task GetRecordingAsync(string recordingUrl, Credentials creds = null); } } \ No newline at end of file diff --git a/Vonage/Voice/VoiceClient.cs b/Vonage/Voice/VoiceClient.cs index 7771b00d9..146bb88ea 100644 --- a/Vonage/Voice/VoiceClient.cs +++ b/Vonage/Voice/VoiceClient.cs @@ -1,5 +1,6 @@ using System; using System.IO; +using System.Threading.Tasks; using Vonage.Common; using Vonage.Request; @@ -25,9 +26,9 @@ public VoiceClient(Credentials credentials = null) /// (Optional) Overridden credentials for only this request /// /// thrown if an error is encountered when talking to the API - public CallResponse CreateCall(CallCommand command, Credentials creds = null) + public Task CreateCallAsync(CallCommand command, Credentials creds = null) { - return ApiRequest.DoRequestWithJsonContent( + return ApiRequest.DoRequestWithJsonContentAsync( POST, ApiRequest.GetBaseUri(ApiRequest.UriType.Api, CALLS_ENDPOINT), command, @@ -42,9 +43,9 @@ public CallResponse CreateCall(CallCommand command, Credentials creds = null) /// (Optional) Overridden credentials for only this request /// /// thrown if an error is encountered when talking to the API - public PageResponse GetCalls(CallSearchFilter filter, Credentials creds = null) + public Task> GetCallsAsync(CallSearchFilter filter, Credentials creds = null) { - return ApiRequest.DoGetRequestWithQueryParameters>( + return ApiRequest.DoGetRequestWithQueryParametersAsync>( ApiRequest.GetBaseUri(ApiRequest.UriType.Api, CALLS_ENDPOINT), ApiRequest.AuthType.Bearer, filter, @@ -58,9 +59,9 @@ public PageResponse GetCalls(CallSearchFilter filter, Credentials cred /// id of call /// (Optional) Overridden credentials for only this request /// thrown if an error is encountered when talking to the API - public CallRecord GetCall(string id, Credentials creds = null) + public Task GetCallAsync(string id, Credentials creds = null) { - return ApiRequest.DoGetRequestWithQueryParameters( + return ApiRequest.DoGetRequestWithQueryParametersAsync( ApiRequest.GetBaseUri(ApiRequest.UriType.Api, $"{CALLS_ENDPOINT}/{id}"), ApiRequest.AuthType.Bearer, credentials: creds ?? Credentials @@ -74,9 +75,9 @@ public CallRecord GetCall(string id, Credentials creds = null) /// Command to execute against call /// (Optional) Overridden credentials for only this request /// thrown if an error is encountered when talking to the API - public bool UpdateCall(string id, CallEditCommand command, Credentials creds = null) + public async Task UpdateCallAsync(string id, CallEditCommand command, Credentials creds = null) { - ApiRequest.DoRequestWithJsonContent( + await ApiRequest.DoRequestWithJsonContentAsync( PUT, ApiRequest.GetBaseUri(ApiRequest.UriType.Api, $"{CALLS_ENDPOINT}/{id}"), command, @@ -93,9 +94,9 @@ public bool UpdateCall(string id, CallEditCommand command, Credentials creds = n /// Command to execute against call /// (Optional) Overridden credentials for only this request /// thrown if an error is encountered when talking to the API - public CallCommandResponse StartStream(string id, StreamCommand command, Credentials creds = null) + public Task StartStreamAsync(string id, StreamCommand command, Credentials creds = null) { - return ApiRequest.DoRequestWithJsonContent( + return ApiRequest.DoRequestWithJsonContentAsync( PUT, ApiRequest.GetBaseUri(ApiRequest.UriType.Api, $"{CALLS_ENDPOINT}/{id}/stream"), command, @@ -110,9 +111,9 @@ public CallCommandResponse StartStream(string id, StreamCommand command, Credent /// id of call /// (Optional) Overridden credentials for only this request /// thrown if an error is encountered when talking to the API - public CallCommandResponse StopStream(string id, Credentials creds = null) + public Task StopStreamAsync(string id, Credentials creds = null) { - return ApiRequest.DoRequestWithJsonContent( + return ApiRequest.DoRequestWithJsonContentAsync( DELETE, ApiRequest.GetBaseUri(ApiRequest.UriType.Api, $"{CALLS_ENDPOINT}/{id}/stream"), new { }, @@ -128,9 +129,9 @@ public CallCommandResponse StopStream(string id, Credentials creds = null) /// Command to execute against call /// (Optional) Overridden credentials for only this request /// thrown if an error is encountered when talking to the API - public CallCommandResponse StartTalk(string id, TalkCommand cmd, Credentials creds = null) + public Task StartTalkAsync(string id, TalkCommand cmd, Credentials creds = null) { - return ApiRequest.DoRequestWithJsonContent( + return ApiRequest.DoRequestWithJsonContentAsync( PUT, ApiRequest.GetBaseUri(ApiRequest.UriType.Api, $"{CALLS_ENDPOINT}/{id}/talk"), cmd, @@ -145,9 +146,9 @@ public CallCommandResponse StartTalk(string id, TalkCommand cmd, Credentials cre /// id of call /// (Optional) Overridden credentials for only this request /// thrown if an error is encountered when talking to the API - public CallCommandResponse StopTalk(string id, Credentials creds = null) + public Task StopTalkAsync(string id, Credentials creds = null) { - return ApiRequest.DoRequestWithJsonContent( + return ApiRequest.DoRequestWithJsonContentAsync( DELETE, ApiRequest.GetBaseUri(ApiRequest.UriType.Api, $"{CALLS_ENDPOINT}/{id}/talk"), new { }, @@ -163,9 +164,9 @@ public CallCommandResponse StopTalk(string id, Credentials creds = null) /// Command to execute against call /// (Optional) Overridden credentials for only this request /// thrown if an error is encountered when talking to the API - public CallCommandResponse StartDtmf(string id, DtmfCommand cmd, Credentials creds = null) + public Task StartDtmfAsync(string id, DtmfCommand cmd, Credentials creds = null) { - return ApiRequest.DoRequestWithJsonContent( + return ApiRequest.DoRequestWithJsonContentAsync( PUT, ApiRequest.GetBaseUri(ApiRequest.UriType.Api, $"{CALLS_ENDPOINT}/{id}/dtmf"), cmd, @@ -181,9 +182,9 @@ public CallCommandResponse StartDtmf(string id, DtmfCommand cmd, Credentials cre /// Overridden credentials /// thrown if an error is encountered when talking to the API /// A response containing a byte array representing the file stream - public GetRecordingResponse GetRecording(string recordingUrl, Credentials creds = null) + public async Task GetRecordingAsync(string recordingUrl, Credentials creds = null) { - using (var response = ApiRequest.DoGetRequestWithJwt(new Uri(recordingUrl), creds ?? Credentials)) + using (var response = await ApiRequest.DoGetRequestWithJwtAsync(new Uri(recordingUrl), creds ?? Credentials)) { var readTask = response.Content.ReadAsStreamAsync(); byte[] bytes;