Skip to content

Commit

Permalink
refactor: make sync-only methods obsolete (#538)
Browse files Browse the repository at this point in the history
* Flag sync methods as obsolete for AccountClient

* Flag sync methods (and CreateApplication typo) as obsolete for ApplicationClient

* Flag sync methods as obsolete

* Flag sync methods as obsolete

* Flag sync methods as obsolete

* Flag sync methods as obsolete
  • Loading branch information
Tr00d authored Oct 17, 2023
1 parent efb342e commit 1b96b6b
Show file tree
Hide file tree
Showing 12 changed files with 432 additions and 302 deletions.
113 changes: 65 additions & 48 deletions Vonage/Accounts/AccountClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ internal AccountClient(Credentials creds, Configuration configuration, ITimeProv
}

/// <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 @@ public Task<AccountSettingsResult> ChangeAccountSettingsAsync(AccountSettingsReq
);

/// <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 @@ public SubAccount CreateSubAccount(CreateSubAccountRequest request, string apiKe
{
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 @@ public Task<SubAccount> CreateSubAccountAsync(CreateSubAccountRequest request, s
}

/// <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 @@ public Task<SubAccount> RetrieveSubAccountAsync(string subAccountKey, string api
}

/// <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

0 comments on commit 1b96b6b

Please # to comment.