Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: make sync-only methods obsolete #538

Merged
merged 6 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 65 additions & 48 deletions Vonage/Accounts/AccountClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@

namespace Vonage.Accounts;

public class AccountClient : IAccountClient

Check warning on line 9 in Vonage/Accounts/AccountClient.cs

View workflow job for this annotation

GitHub Actions / build

Missing XML comment for publicly visible type or member 'AccountClient'
{
private readonly Configuration configuration;
private readonly ITimeProvider timeProvider = new TimeProvider();
public Credentials Credentials { get; set; }

Check warning on line 13 in Vonage/Accounts/AccountClient.cs

View workflow job for this annotation

GitHub Actions / build

Missing XML comment for publicly visible type or member 'AccountClient.Credentials'

public AccountClient(Credentials creds = null)

Check warning on line 15 in Vonage/Accounts/AccountClient.cs

View workflow job for this annotation

GitHub Actions / build

Missing XML comment for publicly visible type or member 'AccountClient.AccountClient(Credentials)'
{
this.Credentials = creds;
this.configuration = Configuration.Instance;
Expand All @@ -26,6 +26,7 @@
}

/// <inheritdoc/>
[Obsolete("Favor asynchronous version instead.")]
public AccountSettingsResult ChangeAccountSettings(AccountSettingsRequest request, Credentials creds = null) =>
ApiRequest.Build(this.GetCredentials(creds), this.configuration, this.timeProvider)
.DoPostRequestUrlContentFromObject<AccountSettingsResult>
Expand All @@ -45,23 +46,26 @@
);

/// <inheritdoc/>
[Obsolete("Favor asynchronous version instead.")]
public Secret CreateApiSecret(CreateSecretRequest request, string apiKey = null, Credentials creds = null) =>
ApiRequest.Build(this.GetCredentials(creds), this.configuration, this.timeProvider).DoRequestWithJsonContent<Secret>(
HttpMethod.Post,
ApiRequest.GetBaseUri(ApiRequest.UriType.Api, $"/accounts/{apiKey}/secrets"),
request,
AuthType.Basic
);
ApiRequest.Build(this.GetCredentials(creds), this.configuration, this.timeProvider)
.DoRequestWithJsonContent<Secret>(
HttpMethod.Post,
ApiRequest.GetBaseUri(ApiRequest.UriType.Api, $"/accounts/{apiKey}/secrets"),
request,
AuthType.Basic
);

/// <inheritdoc/>
public Task<Secret> CreateApiSecretAsync(CreateSecretRequest request, string apiKey = null,
Credentials creds = null) =>
ApiRequest.Build(this.GetCredentials(creds), this.configuration, this.timeProvider).DoRequestWithJsonContentAsync<Secret>(
HttpMethod.Post,
ApiRequest.GetBaseUri(ApiRequest.UriType.Api, $"/accounts/{apiKey}/secrets"),
request,
AuthType.Basic
);
ApiRequest.Build(this.GetCredentials(creds), this.configuration, this.timeProvider)
.DoRequestWithJsonContentAsync<Secret>(
HttpMethod.Post,
ApiRequest.GetBaseUri(ApiRequest.UriType.Api, $"/accounts/{apiKey}/secrets"),
request,
AuthType.Basic
);

/// <inheritdoc/>
[Obsolete("Use SubAccountsClient instead.")]
Expand All @@ -70,12 +74,13 @@
{
var credentials = this.GetCredentials(creds);
var accountId = apiKey ?? credentials.ApiKey;
return ApiRequest.Build(this.GetCredentials(creds), this.configuration, this.timeProvider).DoRequestWithJsonContent<SubAccount>(
HttpMethod.Post,
ApiRequest.GetBaseUri(ApiRequest.UriType.Api, $"/accounts/{accountId}/subaccounts"),
request,
AuthType.Basic
);
return ApiRequest.Build(this.GetCredentials(creds), this.configuration, this.timeProvider)
.DoRequestWithJsonContent<SubAccount>(
HttpMethod.Post,
ApiRequest.GetBaseUri(ApiRequest.UriType.Api, $"/accounts/{accountId}/subaccounts"),
request,
AuthType.Basic
);
}

/// <inheritdoc/>
Expand All @@ -95,32 +100,39 @@
}

/// <inheritdoc/>
[Obsolete("Favor asynchronous version instead.")]
public Balance GetAccountBalance(Credentials creds = null) =>
ApiRequest.Build(this.GetCredentials(creds), this.configuration, this.timeProvider).DoGetRequestWithQueryParameters<Balance>(
ApiRequest.GetBaseUriFor("/account/get-balance"),
AuthType.Query);
ApiRequest.Build(this.GetCredentials(creds), this.configuration, this.timeProvider)
.DoGetRequestWithQueryParameters<Balance>(
ApiRequest.GetBaseUriFor("/account/get-balance"),
AuthType.Query);

/// <inheritdoc/>
public Task<Balance> GetAccountBalanceAsync(Credentials creds = null) =>
ApiRequest.Build(this.GetCredentials(creds), this.configuration, this.timeProvider).DoGetRequestWithQueryParametersAsync<Balance>(
ApiRequest.GetBaseUriFor("/account/get-balance"),
AuthType.Query);
ApiRequest.Build(this.GetCredentials(creds), this.configuration, this.timeProvider)
.DoGetRequestWithQueryParametersAsync<Balance>(
ApiRequest.GetBaseUriFor("/account/get-balance"),
AuthType.Query);

/// <inheritdoc/>
[Obsolete("Favor asynchronous version instead.")]
public Secret RetrieveApiSecret(string secretId, string apiKey = null, Credentials creds = null) =>
ApiRequest.Build(this.GetCredentials(creds), this.configuration, this.timeProvider).DoGetRequestWithQueryParameters<Secret>(
ApiRequest.GetBaseUri(ApiRequest.UriType.Api, $"/accounts/{apiKey}/secrets/{secretId}"),
AuthType.Basic
);
ApiRequest.Build(this.GetCredentials(creds), this.configuration, this.timeProvider)
.DoGetRequestWithQueryParameters<Secret>(
ApiRequest.GetBaseUri(ApiRequest.UriType.Api, $"/accounts/{apiKey}/secrets/{secretId}"),
AuthType.Basic
);

/// <inheritdoc/>
public Task<Secret> RetrieveApiSecretAsync(string secretId, string apiKey = null, Credentials creds = null) =>
ApiRequest.Build(this.GetCredentials(creds), this.configuration, this.timeProvider).DoGetRequestWithQueryParametersAsync<Secret>(
ApiRequest.GetBaseUri(ApiRequest.UriType.Api, $"/accounts/{apiKey}/secrets/{secretId}"),
AuthType.Basic
);
ApiRequest.Build(this.GetCredentials(creds), this.configuration, this.timeProvider)
.DoGetRequestWithQueryParametersAsync<Secret>(
ApiRequest.GetBaseUri(ApiRequest.UriType.Api, $"/accounts/{apiKey}/secrets/{secretId}"),
AuthType.Basic
);

/// <inheritdoc/>
[Obsolete("Favor asynchronous version instead.")]
public SecretsRequestResult RetrieveApiSecrets(string apiKey = null, Credentials creds = null) =>
ApiRequest.Build(this.GetCredentials(creds), this.configuration, this.timeProvider)
.DoGetRequestWithQueryParameters<SecretsRequestResult>(
Expand Down Expand Up @@ -164,34 +176,39 @@
}

/// <inheritdoc/>
[Obsolete("Favor asynchronous version instead.")]
public bool RevokeApiSecret(string secretId, string apiKey = null, Credentials creds = null)
{
ApiRequest.Build(this.GetCredentials(creds), this.configuration, this.timeProvider).DoDeleteRequestWithUrlContent(
ApiRequest.GetBaseUri(ApiRequest.UriType.Api, $"/accounts/{apiKey}/secrets/{secretId}"),
null,
AuthType.Basic
);
ApiRequest.Build(this.GetCredentials(creds), this.configuration, this.timeProvider)
.DoDeleteRequestWithUrlContent(
ApiRequest.GetBaseUri(ApiRequest.UriType.Api, $"/accounts/{apiKey}/secrets/{secretId}"),
null,
AuthType.Basic
);
return true;
}

/// <inheritdoc/>
public async Task<bool> RevokeApiSecretAsync(string secretId, string apiKey = null, Credentials creds = null)
{
await ApiRequest.Build(this.GetCredentials(creds), this.configuration, this.timeProvider).DoDeleteRequestWithUrlContentAsync(
ApiRequest.GetBaseUri(ApiRequest.UriType.Api, $"/accounts/{apiKey}/secrets/{secretId}"),
null,
AuthType.Basic
);
await ApiRequest.Build(this.GetCredentials(creds), this.configuration, this.timeProvider)
.DoDeleteRequestWithUrlContentAsync(
ApiRequest.GetBaseUri(ApiRequest.UriType.Api, $"/accounts/{apiKey}/secrets/{secretId}"),
null,
AuthType.Basic
);
return true;
}

/// <inheritdoc/>
[Obsolete("Favor asynchronous version instead.")]
public TopUpResult TopUpAccountBalance(TopUpRequest request, Credentials creds = null) =>
ApiRequest.Build(this.GetCredentials(creds), this.configuration, this.timeProvider).DoGetRequestWithQueryParameters<TopUpResult>(
ApiRequest.GetBaseUriFor("/account/top-up"),
AuthType.Query,
request
);
ApiRequest.Build(this.GetCredentials(creds), this.configuration, this.timeProvider)
.DoGetRequestWithQueryParameters<TopUpResult>(
ApiRequest.GetBaseUriFor("/account/top-up"),
AuthType.Query,
request
);

/// <inheritdoc/>
public Task<TopUpResult> TopUpAccountBalanceAsync(TopUpRequest request, Credentials creds = null) =>
Expand Down
100 changes: 62 additions & 38 deletions Vonage/Applications/ApplicationClient.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Net.Http;
using System.Threading.Tasks;
using Vonage.Common;
Expand Down Expand Up @@ -25,51 +26,70 @@ internal ApplicationClient(Credentials credentials, Configuration configuration,
}

/// <inheritdoc/>
[Obsolete("Favor asynchronous version instead.")]
public Application CreateApplicaiton(CreateApplicationRequest request, Credentials creds = null) =>
ApiRequest.Build(this.GetCredentials(creds), this.configuration, this.timeProvider).DoRequestWithJsonContent<Application>(
HttpMethod.Post,
ApiRequest.GetBaseUri(ApiRequest.UriType.Api, "/v2/applications"),
request,
AuthType.Basic
);
ApiRequest.Build(this.GetCredentials(creds), this.configuration, this.timeProvider)
.DoRequestWithJsonContent<Application>(
HttpMethod.Post,
ApiRequest.GetBaseUri(ApiRequest.UriType.Api, "/v2/applications"),
request,
AuthType.Basic
);

/// <inheritdoc/>
[Obsolete("Favor typo-free method instead.")]
public Task<Application> CreateApplicaitonAsync(CreateApplicationRequest request, Credentials creds = null) =>
ApiRequest.Build(this.GetCredentials(creds), this.configuration, this.timeProvider).DoRequestWithJsonContentAsync<Application>(
HttpMethod.Post,
ApiRequest.GetBaseUri(ApiRequest.UriType.Api, "/v2/applications"),
request,
AuthType.Basic
);
ApiRequest.Build(this.GetCredentials(creds), this.configuration, this.timeProvider)
.DoRequestWithJsonContentAsync<Application>(
HttpMethod.Post,
ApiRequest.GetBaseUri(ApiRequest.UriType.Api, "/v2/applications"),
request,
AuthType.Basic
);

/// <inheritdoc />
public Task<Application> CreateApplicationAsync(CreateApplicationRequest request, Credentials creds = null) =>
ApiRequest.Build(this.GetCredentials(creds), this.configuration, this.timeProvider)
.DoRequestWithJsonContentAsync<Application>(
HttpMethod.Post,
ApiRequest.GetBaseUri(ApiRequest.UriType.Api, "/v2/applications"),
request,
AuthType.Basic
);

/// <inheritdoc/>
[Obsolete("Favor asynchronous version instead.")]
public bool DeleteApplication(string id, Credentials creds = null)
{
ApiRequest.Build(this.GetCredentials(creds), this.configuration, this.timeProvider).DoDeleteRequestWithUrlContent(
ApiRequest.GetBaseUri(ApiRequest.UriType.Api, $"/v2/applications/{id}"),
null,
AuthType.Basic
);
ApiRequest.Build(this.GetCredentials(creds), this.configuration, this.timeProvider)
.DoDeleteRequestWithUrlContent(
ApiRequest.GetBaseUri(ApiRequest.UriType.Api, $"/v2/applications/{id}"),
null,
AuthType.Basic
);
return true;
}

/// <inheritdoc/>
public async Task<bool> DeleteApplicationAsync(string id, Credentials creds = null)
{
await ApiRequest.Build(this.GetCredentials(creds), this.configuration, this.timeProvider).DoDeleteRequestWithUrlContentAsync(
ApiRequest.GetBaseUri(ApiRequest.UriType.Api, $"/v2/applications/{id}"),
null,
AuthType.Basic
);
await ApiRequest.Build(this.GetCredentials(creds), this.configuration, this.timeProvider)
.DoDeleteRequestWithUrlContentAsync(
ApiRequest.GetBaseUri(ApiRequest.UriType.Api, $"/v2/applications/{id}"),
null,
AuthType.Basic
);
return true;
}

/// <inheritdoc/>
[Obsolete("Favor asynchronous version instead.")]
public Application GetApplication(string id, Credentials creds = null) =>
ApiRequest.Build(this.GetCredentials(creds), this.configuration, this.timeProvider).DoGetRequestWithQueryParameters<Application>(
ApiRequest.GetBaseUri(ApiRequest.UriType.Api, $"/v2/applications/{id}"),
AuthType.Basic
);
ApiRequest.Build(this.GetCredentials(creds), this.configuration, this.timeProvider)
.DoGetRequestWithQueryParameters<Application>(
ApiRequest.GetBaseUri(ApiRequest.UriType.Api, $"/v2/applications/{id}"),
AuthType.Basic
);

/// <inheritdoc/>
public Task<Application> GetApplicationAsync(string id, Credentials creds = null) =>
Expand All @@ -80,6 +100,7 @@ public Task<Application> GetApplicationAsync(string id, Credentials creds = null
);

/// <inheritdoc/>
[Obsolete("Favor asynchronous version instead.")]
public ApplicationPage ListApplications(ListApplicationsRequest request, Credentials creds = null) =>
ApiRequest.Build(this.GetCredentials(creds), this.configuration, this.timeProvider)
.DoGetRequestWithQueryParameters<ApplicationPage>(
Expand All @@ -98,23 +119,26 @@ public Task<ApplicationPage> ListApplicationsAsync(ListApplicationsRequest reque
);

/// <inheritdoc/>
[Obsolete("Favor asynchronous version instead.")]
public Application UpdateApplication(string id, CreateApplicationRequest request, Credentials creds = null) =>
ApiRequest.Build(this.GetCredentials(creds), this.configuration, this.timeProvider).DoRequestWithJsonContent<Application>(
HttpMethod.Put,
ApiRequest.GetBaseUri(ApiRequest.UriType.Api, $"/v2/applications/{id}"),
request,
AuthType.Basic
);
ApiRequest.Build(this.GetCredentials(creds), this.configuration, this.timeProvider)
.DoRequestWithJsonContent<Application>(
HttpMethod.Put,
ApiRequest.GetBaseUri(ApiRequest.UriType.Api, $"/v2/applications/{id}"),
request,
AuthType.Basic
);

/// <inheritdoc/>
public Task<Application> UpdateApplicationAsync(string id, CreateApplicationRequest request,
Credentials creds = null) =>
ApiRequest.Build(this.GetCredentials(creds), this.configuration, this.timeProvider).DoRequestWithJsonContentAsync<Application>(
HttpMethod.Put,
ApiRequest.GetBaseUri(ApiRequest.UriType.Api, $"/v2/applications/{id}"),
request,
AuthType.Basic
);
ApiRequest.Build(this.GetCredentials(creds), this.configuration, this.timeProvider)
.DoRequestWithJsonContentAsync<Application>(
HttpMethod.Put,
ApiRequest.GetBaseUri(ApiRequest.UriType.Api, $"/v2/applications/{id}"),
request,
AuthType.Basic
);

private Credentials GetCredentials(Credentials overridenCredentials) => overridenCredentials ?? this.Credentials;
}
Loading
Loading