Skip to content

Commit

Permalink
removing GetAwaiter().GetResult() pattern from sync methods
Browse files Browse the repository at this point in the history
  • Loading branch information
slorello89 committed Jan 20, 2021
1 parent ae5816b commit 1831275
Show file tree
Hide file tree
Showing 12 changed files with 635 additions and 49 deletions.
48 changes: 41 additions & 7 deletions Vonage/Accounts/AccountClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,37 +83,71 @@ await ApiRequest.DoDeleteRequestWithUrlContentAsync(

public Balance GetAccountBalance(Credentials creds = null)
{
return GetAccountBalanceAsync(creds).GetAwaiter().GetResult();
return ApiRequest.DoGetRequestWithQueryParameters<Balance>(
ApiRequest.GetBaseUriFor(typeof(AccountClient),
"/account/get-balance"),
ApiRequest.AuthType.Query,
credentials: creds ?? Credentials);
}

public TopUpResult TopUpAccountBalance(TopUpRequest request, Credentials creds = null)
{
return TopUpAccountBalanceAsync(request, creds).GetAwaiter().GetResult();
return ApiRequest.DoGetRequestWithQueryParameters<TopUpResult>(
ApiRequest.GetBaseUriFor(typeof(AccountClient), "/account/top-up"),
ApiRequest.AuthType.Query,
request,
credentials: creds ?? Credentials
);
}

public AccountSettingsResult ChangeAccountSettings(AccountSettingsRequest request, Credentials creds = null)
{
return ChangeAccountSettingsAsync(request, creds).GetAwaiter().GetResult();
return ApiRequest.DoPostRequestUrlContentFromObject<AccountSettingsResult>
(
ApiRequest.GetBaseUriFor(typeof(AccountClient), "/account/settings"),
request,
creds ?? Credentials
);
}

public SecretsRequestResult RetrieveApiSecrets(string apiKey = null, Credentials creds = null)
{
return RetrieveApiSecretsAsync(apiKey, creds).GetAwaiter().GetResult();
return ApiRequest.DoGetRequestWithQueryParameters<SecretsRequestResult>(
ApiRequest.GetBaseUri(ApiRequest.UriType.Api, $"/accounts/{apiKey}/secrets"),
ApiRequest.AuthType.Basic,
credentials: creds ?? Credentials
);
}

public Secret CreateApiSecret(CreateSecretRequest request, string apiKey = null, Credentials creds = null)
{
return CreateApiSecretAsync(request, apiKey, creds).GetAwaiter().GetResult();
return ApiRequest.DoRequestWithJsonContent<Secret>(
"POST",
ApiRequest.GetBaseUri(ApiRequest.UriType.Api, $"/accounts/{apiKey}/secrets"),
request,
ApiRequest.AuthType.Basic,
creds: creds ?? Credentials
);
}

public Secret RetrieveApiSecret(string secretId, string apiKey = null, Credentials creds = null)
{
return RetrieveApiSecretAsync(secretId, apiKey, creds).GetAwaiter().GetResult();
return ApiRequest.DoGetRequestWithQueryParameters<Secret>(
ApiRequest.GetBaseUri(ApiRequest.UriType.Api, $"/accounts/{apiKey}/secrets/{secretId}"),
ApiRequest.AuthType.Basic,
credentials: creds ?? Credentials
);
}

public bool RevokeApiSecret(string secretId, string apiKey = null, Credentials creds = null)
{
return RevokeApiSecretAsync(secretId, apiKey, creds).GetAwaiter().GetResult();
ApiRequest.DoDeleteRequestWithUrlContent(
ApiRequest.GetBaseUri(ApiRequest.UriType.Api, $"/accounts/{apiKey}/secrets/{secretId}"),
null,
ApiRequest.AuthType.Basic,
creds ?? Credentials
);
return true;
}
}
}
37 changes: 32 additions & 5 deletions Vonage/Applications/ApplicationClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,27 +64,54 @@ await ApiRequest.DoDeleteRequestWithUrlContentAsync(

public Application CreateApplicaiton(CreateApplicationRequest request, Credentials creds = null)
{
return CreateApplicaitonAsync(request, creds).GetAwaiter().GetResult();
return ApiRequest.DoRequestWithJsonContent<Application>(
"POST",
ApiRequest.GetBaseUri(ApiRequest.UriType.Api, "/v2/applications"),
request,
ApiRequest.AuthType.Basic,
creds ?? Credentials
);
}

public ApplicationPage ListApplications(ListApplicationsRequest request, Credentials creds = null)
{
return ListApplicationsAsync(request, creds).GetAwaiter().GetResult();
return ApiRequest.DoGetRequestWithQueryParameters<ApplicationPage>(
ApiRequest.GetBaseUri(ApiRequest.UriType.Api, "/v2/applications"),
ApiRequest.AuthType.Basic,
request,
creds ?? Credentials
);
}

public Application GetApplication(string id, Credentials creds = null)
{
return GetApplicationAsync(id, creds).GetAwaiter().GetResult();
return ApiRequest.DoGetRequestWithQueryParameters<Application>(
ApiRequest.GetBaseUri(ApiRequest.UriType.Api, $"/v2/applications/{id}"),
ApiRequest.AuthType.Basic,
credentials: creds ?? Credentials
);
}

public Application UpdateApplication(string id, CreateApplicationRequest request, Credentials creds = null)
{
return UpdateApplicationAsync(id, request, creds).GetAwaiter().GetResult();
return ApiRequest.DoRequestWithJsonContent<Application>(
"PUT",
ApiRequest.GetBaseUri(ApiRequest.UriType.Api, $"/v2/applications/{id}"),
request,
ApiRequest.AuthType.Basic,
creds ?? Credentials
);
}

public bool DeleteApplication(string id, Credentials creds = null)
{
return DeleteApplicationAsync(id, creds).GetAwaiter().GetResult();
ApiRequest.DoDeleteRequestWithUrlContent(
ApiRequest.GetBaseUri(ApiRequest.UriType.Api, $"/v2/applications/{id}"),
null,
ApiRequest.AuthType.Basic,
creds ?? Credentials
);
return true;
}
}
}
16 changes: 14 additions & 2 deletions Vonage/Conversions/ConversionClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,24 @@ await ApiRequest.DoPostRequestUrlContentFromObjectAsync<object>

public bool SmsConversion(ConversionRequest request, Credentials creds = null)
{
return SmsConversionAsync(request, creds).GetAwaiter().GetResult();
ApiRequest.DoPostRequestUrlContentFromObject<object>
(
ApiRequest.GetBaseUri(ApiRequest.UriType.Api, "/conversions/sms"),
request,
creds ?? Credentials
);
return true;
}

public bool VoiceConversion(ConversionRequest request, Credentials creds = null)
{
return VoiceConversionAsync(request, creds).GetAwaiter().GetResult();
ApiRequest.DoPostRequestUrlContentFromObject<object>
(
ApiRequest.GetBaseUri(ApiRequest.UriType.Api, "/conversions/voice"),
request,
creds ?? Credentials
);
return true;
}
}
}
9 changes: 8 additions & 1 deletion Vonage/Messaging/SmsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,14 @@ public async Task<SendSmsResponse> SendAnSmsAsync(SendSmsRequest request, Creden

public SendSmsResponse SendAnSms(SendSmsRequest request, Credentials creds = null)
{
return SendAnSmsAsync(request, creds).GetAwaiter().GetResult();
var result = ApiRequest.DoPostRequestUrlContentFromObject<SendSmsResponse>(
ApiRequest.GetBaseUri(ApiRequest.UriType.Rest, "/sms/json"),
request,
creds ?? Credentials
);

ValidSmsResponse(result);
return result;
}

public Task<SendSmsResponse> SendAnSmsAsync(string from, string to, string text, SmsType type = SmsType.text, Credentials creds = null)
Expand Down
36 changes: 32 additions & 4 deletions Vonage/NumberInsights/NumberInsightClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,22 +77,50 @@ public void ValidateNumberInsightResponse(NumberInsightResponseBase response)

public BasicInsightResponse GetNumberInsightBasic(BasicNumberInsightRequest request, Credentials creds = null)
{
return GetNumberInsightBasicAsync(request, creds).GetAwaiter().GetResult();
var response = ApiRequest.DoGetRequestWithQueryParameters<BasicInsightResponse>(
ApiRequest.GetBaseUri(ApiRequest.UriType.Api, "/ni/basic/json"),
ApiRequest.AuthType.Query,
request,
creds ?? Credentials
);
ValidateNumberInsightResponse(response);
return response;
}

public StandardInsightResponse GetNumberInsightStandard(StandardNumberInsightRequest request, Credentials creds = null)
{
return GetNumberInsightStandardAsync(request, creds).GetAwaiter().GetResult();
var response = ApiRequest.DoGetRequestWithQueryParameters<StandardInsightResponse>(
ApiRequest.GetBaseUri(ApiRequest.UriType.Api, "/ni/standard/json"),
ApiRequest.AuthType.Query,
request,
creds ?? Credentials
);
ValidateNumberInsightResponse(response);
return response;
}

public AdvancedInsightsResponse GetNumberInsightAdvanced(AdvancedNumberInsightRequest request, Credentials creds = null)
{
return GetNumberInsightAdvancedAsync(request, creds).GetAwaiter().GetResult();
var response = ApiRequest.DoGetRequestWithQueryParameters<AdvancedInsightsResponse>(
ApiRequest.GetBaseUri(ApiRequest.UriType.Api, "/ni/advanced/json"),
ApiRequest.AuthType.Query,
request,
creds ?? Credentials
);
ValidateNumberInsightResponse(response);
return response;
}

public AdvancedInsightsAsyncResponse GetNumberInsightAsync(AdvancedNumberInsightAsynchronousRequest request, Credentials creds = null)
{
return GetNumberInsightAsyncAsync(request, creds).GetAwaiter().GetResult();
var response = ApiRequest.DoGetRequestWithQueryParameters<AdvancedInsightsAsyncResponse>(
ApiRequest.GetBaseUri(ApiRequest.UriType.Api, "/ni/advanced/async/json"),
ApiRequest.AuthType.Query,
request,
creds ?? Credentials
);
ValidateNumberInsightResponse(response);
return response;
}
}
}
38 changes: 33 additions & 5 deletions Vonage/Numbers/NumbersClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,27 +77,55 @@ public static void ValidateNumbersResponse(NumberTransactionResponse response)

public NumbersSearchResponse GetOwnedNumbers(NumberSearchRequest request, Credentials creds = null)
{
return GetOwnedNumbersAsync(request, creds).GetAwaiter().GetResult();
return ApiRequest.DoGetRequestWithQueryParameters<NumbersSearchResponse>(
ApiRequest.GetBaseUri(ApiRequest.UriType.Rest, "/account/numbers"),
ApiRequest.AuthType.Query,
request,
creds ?? Credentials
);
}

public NumbersSearchResponse GetAvailableNumbers(NumberSearchRequest request, Credentials creds = null)
{
return GetAvailableNumbersAsync(request, creds).GetAwaiter().GetResult();
return ApiRequest.DoGetRequestWithQueryParameters<NumbersSearchResponse>(
ApiRequest.GetBaseUri(ApiRequest.UriType.Rest, "/number/search"),
ApiRequest.AuthType.Query,
request,
creds ?? Credentials
);
}

public NumberTransactionResponse BuyANumber(NumberTransactionRequest request, Credentials creds = null)
{
return BuyANumberAsync(request, creds).GetAwaiter().GetResult();
var response = ApiRequest.DoPostRequestUrlContentFromObject<NumberTransactionResponse>(
ApiRequest.GetBaseUri(ApiRequest.UriType.Rest, "/number/buy"),
request,
creds ?? Credentials
);
ValidateNumbersResponse(response);
return response;
}

public NumberTransactionResponse CancelANumber(NumberTransactionRequest request, Credentials creds = null)
{
return CancelANumberAsync(request, creds).GetAwaiter().GetResult();
var response = ApiRequest.DoPostRequestUrlContentFromObject<NumberTransactionResponse>(
ApiRequest.GetBaseUri(ApiRequest.UriType.Rest, "/number/cancel"),
request,
creds ?? Credentials
);
ValidateNumbersResponse(response);
return response;
}

public NumberTransactionResponse UpdateANumber(UpdateNumberRequest request, Credentials creds = null)
{
return UpdateANumberAsync(request, creds).GetAwaiter().GetResult();
var response = ApiRequest.DoPostRequestUrlContentFromObject<NumberTransactionResponse>(
ApiRequest.GetBaseUri(ApiRequest.UriType.Rest, "/number/update"),
request,
creds ?? Credentials
);
ValidateNumbersResponse(response);
return response;
}
}
}
23 changes: 20 additions & 3 deletions Vonage/Pricing/PricingClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,34 @@ public Task<PricingResult> RetrievePrefixPricingAsync(string type, PricingPrefix

public Country RetrievePricingCountry(string type, PricingCountryRequest request, Credentials creds = null)
{
return RetrievePricingCountryAsync(type, request, creds).GetAwaiter().GetResult();
return ApiRequest.DoGetRequestWithQueryParameters<Country>
(
ApiRequest.GetBaseUri(ApiRequest.UriType.Rest, $"/account/get-pricing/outbound/{type}"),
ApiRequest.AuthType.Query,
request,
creds ?? Credentials
);
}

public PricingResult RetrievePricingAllCountries(string type, Credentials creds = null)
{
return RetrievePricingAllCountriesAsync(type, creds).GetAwaiter().GetResult();
return ApiRequest.DoGetRequestWithQueryParameters<PricingResult>
(
ApiRequest.GetBaseUri(ApiRequest.UriType.Rest, $"/account/get-pricing/outbound/{type}"),
ApiRequest.AuthType.Query,
credentials: creds ?? Credentials
);
}

public PricingResult RetrievePrefixPricing(string type, PricingPrefixRequest request, Credentials creds = null)
{
return RetrievePrefixPricingAsync(type, request, creds).GetAwaiter().GetResult();
return ApiRequest.DoGetRequestWithQueryParameters<PricingResult>
(
ApiRequest.GetBaseUri(ApiRequest.UriType.Rest, $"/account/get-prefix-pricing/outbound/{type}"),
ApiRequest.AuthType.Query,
request,
creds ?? Credentials
);
}
}
}
10 changes: 9 additions & 1 deletion Vonage/Redaction/RedactClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,15 @@ await ApiRequest.DoRequestWithJsonContentAsync<object>

public bool Redact(RedactRequest request, Credentials creds = null)
{
return RedactAsync(request, creds).GetAwaiter().GetResult();
ApiRequest.DoRequestWithJsonContent<object>
(
"POST",
ApiRequest.GetBaseUri(ApiRequest.UriType.Api, "/v1/redact/transaction"),
request,
ApiRequest.AuthType.Basic,
creds ?? Credentials
);
return true;
}
}
}
Loading

0 comments on commit 1831275

Please sign in to comment.