-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: code snippets for SubAccounts (#92)
* Code snippets for SubAccounts * Add TransferNumberRequest snippet
- Loading branch information
Showing
11 changed files
with
279 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
DotNetCliCodeSnippets/SubAccounts/CreateSubAccountRequest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using Vonage; | ||
using Vonage.Request; | ||
|
||
namespace DotnetCliCodeSnippets.SubAccounts; | ||
|
||
public class CreateSubAccountRequest : ICodeSnippet | ||
{ | ||
public async Task Execute() | ||
{ | ||
var vonageApiKey = Environment.GetEnvironmentVariable("VONAGE_API_KEY") ?? "VONAGE_API_KEY"; | ||
var vonageApiSecret = Environment.GetEnvironmentVariable("VONAGE_API_SECRET") ?? "VONAGE_API_SECRET"; | ||
var newSubAccountName = Environment.GetEnvironmentVariable("NEW_SUBACCOUNT_NAME") ?? "NEW_SUBACCOUNT_NAME"; | ||
var newSubAccountSecret = | ||
Environment.GetEnvironmentVariable("NEW_SUBACCOUNT_SECRET") ?? "NEW_SUBACCOUNT_SECRET"; | ||
var credentials = Credentials.FromApiKeyAndSecret(vonageApiKey, vonageApiSecret); | ||
var client = new VonageClient(credentials); | ||
var request = Vonage.SubAccounts.CreateSubAccount.CreateSubAccountRequest.Build() | ||
.WithName(newSubAccountName) | ||
.WithSecret(newSubAccountSecret) | ||
.Create(); | ||
var response = await client.SubAccountsClient.CreateSubAccountAsync(request); | ||
var message = response.Match( | ||
success => $"SubAccount created - {success.ApiKey}", | ||
failure => $"SubAccount creation failed: {failure.GetFailureMessage()}"); | ||
Console.WriteLine(message); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using Vonage; | ||
using Vonage.Request; | ||
using Vonage.SubAccounts.UpdateSubAccount; | ||
|
||
namespace DotnetCliCodeSnippets.SubAccounts; | ||
|
||
public class EnableAccountRequest : ICodeSnippet | ||
{ | ||
public async Task Execute() | ||
{ | ||
var vonageApiKey = Environment.GetEnvironmentVariable("VONAGE_API_KEY") ?? "VONAGE_API_KEY"; | ||
var vonageApiSecret = Environment.GetEnvironmentVariable("VONAGE_API_SECRET") ?? "VONAGE_API_SECRET"; | ||
var subAccountKey = Environment.GetEnvironmentVariable("SUBACCOUNT_KEY") ?? "SUBACCOUNT_KEY"; | ||
var credentials = Credentials.FromApiKeyAndSecret(vonageApiKey, vonageApiSecret); | ||
var client = new VonageClient(credentials); | ||
var request = UpdateSubAccountRequest.Build().WithSubAccountKey(subAccountKey) | ||
.EnableAccount() | ||
.Create(); | ||
var response = await client.SubAccountsClient.UpdateSubAccountAsync(request); | ||
var message = response.Match( | ||
success => $"SubAccount enabled - {success.ApiKey}", | ||
failure => $"SubAccount activation failed: {failure.GetFailureMessage()}"); | ||
Console.WriteLine(message); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
DotNetCliCodeSnippets/SubAccounts/GetBalanceTransfersRequest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using Vonage; | ||
using Vonage.Request; | ||
using Vonage.SubAccounts.GetTransfers; | ||
|
||
namespace DotnetCliCodeSnippets.SubAccounts; | ||
|
||
public class GetBalanceTransfersRequest : ICodeSnippet | ||
{ | ||
public async Task Execute() | ||
{ | ||
var vonageApiKey = Environment.GetEnvironmentVariable("VONAGE_API_KEY") ?? "VONAGE_API_KEY"; | ||
var vonageApiSecret = Environment.GetEnvironmentVariable("VONAGE_API_SECRET") ?? "VONAGE_API_SECRET"; | ||
var startDate = DateTimeOffset.Parse(Environment.GetEnvironmentVariable("START_DATE") ?? "START_DATE"); | ||
var credentials = Credentials.FromApiKeyAndSecret(vonageApiKey, vonageApiSecret); | ||
var client = new VonageClient(credentials); | ||
var request = GetTransfersRequest.Build() | ||
.WithStartDate(startDate) | ||
.Create(); | ||
var response = await client.SubAccountsClient.GetBalanceTransfersAsync(request); | ||
var message = response.Match( | ||
success => $"Balance transfers retrieved - {success.Length}", | ||
failure => $"Balance transfers failed: {failure.GetFailureMessage()}"); | ||
Console.WriteLine(message); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
DotNetCliCodeSnippets/SubAccounts/GetCreditTransfersRequest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using Vonage; | ||
using Vonage.Request; | ||
using Vonage.SubAccounts.GetTransfers; | ||
|
||
namespace DotnetCliCodeSnippets.SubAccounts; | ||
|
||
public class GetCreditTransfersRequest : ICodeSnippet | ||
{ | ||
public async Task Execute() | ||
{ | ||
var vonageApiKey = Environment.GetEnvironmentVariable("VONAGE_API_KEY") ?? "VONAGE_API_KEY"; | ||
var vonageApiSecret = Environment.GetEnvironmentVariable("VONAGE_API_SECRET") ?? "VONAGE_API_SECRET"; | ||
var startDate = DateTimeOffset.Parse(Environment.GetEnvironmentVariable("START_DATE") ?? "START_DATE"); | ||
var credentials = Credentials.FromApiKeyAndSecret(vonageApiKey, vonageApiSecret); | ||
var client = new VonageClient(credentials); | ||
var request = GetTransfersRequest.Build() | ||
.WithStartDate(startDate) | ||
.Create(); | ||
var response = await client.SubAccountsClient.GetCreditTransfersAsync(request); | ||
var message = response.Match( | ||
success => $"Credit transfers retrieved - {success.Length}", | ||
failure => $"Credit transfers failed: {failure.GetFailureMessage()}"); | ||
Console.WriteLine(message); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using Vonage; | ||
using Vonage.Request; | ||
|
||
namespace DotnetCliCodeSnippets.SubAccounts; | ||
|
||
public class GetSubAccountRequest : ICodeSnippet | ||
{ | ||
public async Task Execute() | ||
{ | ||
var vonageApiKey = Environment.GetEnvironmentVariable("VONAGE_API_KEY") ?? "VONAGE_API_KEY"; | ||
var vonageApiSecret = Environment.GetEnvironmentVariable("VONAGE_API_SECRET") ?? "VONAGE_API_SECRET"; | ||
var subAccountKey = Environment.GetEnvironmentVariable("SUBACCOUNT_KEY") ?? "SUBACCOUNT_KEY"; | ||
var credentials = Credentials.FromApiKeyAndSecret(vonageApiKey, vonageApiSecret); | ||
var client = new VonageClient(credentials); | ||
var request = Vonage.SubAccounts.GetSubAccount.GetSubAccountRequest.Parse(subAccountKey); | ||
var response = await client.SubAccountsClient.GetSubAccountAsync(request); | ||
var message = response.Match( | ||
success => $"SubAccount retrieved - {success.ApiKey}", | ||
failure => $"SubAccount retrieval failed: {failure.GetFailureMessage()}"); | ||
Console.WriteLine(message); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
DotNetCliCodeSnippets/SubAccounts/GetSubAccountsRequest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using Vonage; | ||
using Vonage.Request; | ||
|
||
namespace DotnetCliCodeSnippets.SubAccounts; | ||
|
||
public class GetSubAccountsRequest : ICodeSnippet | ||
{ | ||
public async Task Execute() | ||
{ | ||
var vonageApiKey = Environment.GetEnvironmentVariable("VONAGE_API_KEY") ?? "VONAGE_API_KEY"; | ||
var vonageApiSecret = Environment.GetEnvironmentVariable("VONAGE_API_SECRET") ?? "VONAGE_API_SECRET"; | ||
var credentials = Credentials.FromApiKeyAndSecret(vonageApiKey, vonageApiSecret); | ||
var client = new VonageClient(credentials); | ||
var response = await client.SubAccountsClient.GetSubAccountsAsync(); | ||
var message = response.Match( | ||
success => $"SubAccounts retrieved - {success.SubAccounts}", | ||
failure => $"SubAccounts retrieval failed: {failure.GetFailureMessage()}"); | ||
Console.WriteLine(message); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
DotNetCliCodeSnippets/SubAccounts/SuspendAccountRequest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using Vonage; | ||
using Vonage.Request; | ||
using Vonage.SubAccounts.TransferAmount; | ||
using Vonage.SubAccounts.UpdateSubAccount; | ||
|
||
namespace DotnetCliCodeSnippets.SubAccounts; | ||
|
||
public class SuspendAccountRequest : ICodeSnippet | ||
{ | ||
public async Task Execute() | ||
{ | ||
var vonageApiKey = Environment.GetEnvironmentVariable("VONAGE_API_KEY") ?? "VONAGE_API_KEY"; | ||
var vonageApiSecret = Environment.GetEnvironmentVariable("VONAGE_API_SECRET") ?? "VONAGE_API_SECRET"; | ||
var subAccountKey = Environment.GetEnvironmentVariable("SUBACCOUNT_KEY") ?? "SUBACCOUNT_KEY"; | ||
var credentials = Credentials.FromApiKeyAndSecret(vonageApiKey, vonageApiSecret); | ||
var client = new VonageClient(credentials); | ||
var request = UpdateSubAccountRequest.Build().WithSubAccountKey(subAccountKey) | ||
.SuspendAccount() | ||
.Create(); | ||
var response = await client.SubAccountsClient.UpdateSubAccountAsync(request); | ||
var message = response.Match( | ||
success => $"SubAccount suspended - {success.ApiKey}", | ||
failure => $"SubAccount suspension failed: {failure.GetFailureMessage()}"); | ||
Console.WriteLine(message); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
DotNetCliCodeSnippets/SubAccounts/TransferBalanceRequest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using Vonage; | ||
using Vonage.Request; | ||
using Vonage.SubAccounts.TransferAmount; | ||
|
||
namespace DotnetCliCodeSnippets.SubAccounts; | ||
|
||
public class TransferBalanceRequest : ICodeSnippet | ||
{ | ||
public async Task Execute() | ||
{ | ||
var vonageApiKey = Environment.GetEnvironmentVariable("VONAGE_API_KEY") ?? "VONAGE_API_KEY"; | ||
var vonageApiSecret = Environment.GetEnvironmentVariable("VONAGE_API_SECRET") ?? "VONAGE_API_SECRET"; | ||
var subAccountKey = Environment.GetEnvironmentVariable("SUBACCOUNT_KEY") ?? "SUBACCOUNT_KEY"; | ||
var amount = | ||
decimal.Parse(Environment.GetEnvironmentVariable("AMOUNT") ?? "AMOUNT"); | ||
var credentials = Credentials.FromApiKeyAndSecret(vonageApiKey, vonageApiSecret); | ||
var client = new VonageClient(credentials); | ||
var request = TransferAmountRequest.Build() | ||
.WithFrom(vonageApiKey) | ||
.WithTo(subAccountKey) | ||
.WithAmount(amount) | ||
.Create(); | ||
var response = await client.SubAccountsClient.TransferBalanceAsync(request); | ||
var message = response.Match( | ||
success => $"Balance transferred - {success.Id}", | ||
failure => $"Balance transfer failed: {failure.GetFailureMessage()}"); | ||
Console.WriteLine(message); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
DotNetCliCodeSnippets/SubAccounts/TransferCreditRequest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using Vonage; | ||
using Vonage.Request; | ||
using Vonage.SubAccounts.TransferAmount; | ||
|
||
namespace DotnetCliCodeSnippets.SubAccounts; | ||
|
||
public class TransferCreditRequest : ICodeSnippet | ||
{ | ||
public async Task Execute() | ||
{ | ||
var vonageApiKey = Environment.GetEnvironmentVariable("VONAGE_API_KEY") ?? "VONAGE_API_KEY"; | ||
var vonageApiSecret = Environment.GetEnvironmentVariable("VONAGE_API_SECRET") ?? "VONAGE_API_SECRET"; | ||
var subAccountKey = Environment.GetEnvironmentVariable("SUBACCOUNT_KEY") ?? "SUBACCOUNT_KEY"; | ||
var amount = | ||
decimal.Parse(Environment.GetEnvironmentVariable("AMOUNT") ?? "AMOUNT"); | ||
var credentials = Credentials.FromApiKeyAndSecret(vonageApiKey, vonageApiSecret); | ||
var client = new VonageClient(credentials); | ||
var request = TransferAmountRequest.Build() | ||
.WithFrom(vonageApiKey) | ||
.WithTo(subAccountKey) | ||
.WithAmount(amount) | ||
.Create(); | ||
var response = await client.SubAccountsClient.TransferCreditAsync(request); | ||
var message = response.Match( | ||
success => $"Credit transferred - {success.Id}", | ||
failure => $"Credit transfer failed: {failure.GetFailureMessage()}"); | ||
Console.WriteLine(message); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
DotNetCliCodeSnippets/SubAccounts/TransferNumberRequest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using Vonage; | ||
using Vonage.Request; | ||
using Vonage.SubAccounts.GetTransfers; | ||
|
||
namespace DotnetCliCodeSnippets.SubAccounts; | ||
|
||
public class TransferNumberRequest : ICodeSnippet | ||
{ | ||
public async Task Execute() | ||
{ | ||
var vonageApiKey = Environment.GetEnvironmentVariable("VONAGE_API_KEY") ?? "VONAGE_API_KEY"; | ||
var vonageApiSecret = Environment.GetEnvironmentVariable("VONAGE_API_SECRET") ?? "VONAGE_API_SECRET"; | ||
var subAccountKey = Environment.GetEnvironmentVariable("SUBACCOUNT_KEY") ?? "SUBACCOUNT_KEY"; | ||
var phoneNumber = Environment.GetEnvironmentVariable("PHONE_NUMBER") ?? "PHONE_NUMBER"; | ||
var country = Environment.GetEnvironmentVariable("COUNTRY") ?? "COUNTRY"; | ||
var credentials = Credentials.FromApiKeyAndSecret(vonageApiKey, vonageApiSecret); | ||
var client = new VonageClient(credentials); | ||
var request = Vonage.SubAccounts.TransferNumber.TransferNumberRequest.Build() | ||
.WithFrom(vonageApiKey) | ||
.WithTo(subAccountKey) | ||
.WithNumber(phoneNumber) | ||
.WithCountry(country) | ||
.Create(); | ||
var response = await client.SubAccountsClient.TransferNumberAsync(request); | ||
var message = response.Match( | ||
success => $"Number transferred - {success.Number}", | ||
failure => $"Number transfer failed: {failure.GetFailureMessage()}"); | ||
Console.WriteLine(message); | ||
} | ||
} |