Skip to content

Commit

Permalink
- Rename Request functions to RequestAsync to fit best practice for a…
Browse files Browse the repository at this point in the history
…sync function naming (#456)

- Add .ConfigureAwait(false) to HTTP request execution to avoid deadlocks
  • Loading branch information
nwithan8 committed May 2, 2023
1 parent 0530b52 commit db9928a
Show file tree
Hide file tree
Showing 28 changed files with 143 additions and 143 deletions.
14 changes: 7 additions & 7 deletions EasyPost/Services/AddressService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public async Task<Address> Create(Dictionary<string, object> parameters)
parameters.Add("verify_strict", true);
}

return await Request<Address>(Method.Post, "addresses", parameters);
return await RequestAsync<Address>(Method.Post, "addresses", parameters);
}

/// <summary>
Expand All @@ -76,7 +76,7 @@ public async Task<Address> Create(Dictionary<string, object> parameters)
public async Task<Address> Create(BetaFeatures.Parameters.Addresses.Create parameters)
{
// Because the normal Create method does wrapping internally, we can't simply pass the parameters object to it, otherwise it will wrap the parameters twice.
return await Request<Address>(Method.Post, "addresses", parameters.ToDictionary());
return await RequestAsync<Address>(Method.Post, "addresses", parameters.ToDictionary());
}

/// <summary>
Expand All @@ -98,7 +98,7 @@ public async Task<Address> Create(BetaFeatures.Parameters.Addresses.Create param
/// </param>
/// <returns>An Address object.</returns>
[CrudOperations.Create]
public async Task<Address> CreateAndVerify(Dictionary<string, object> parameters) => await Request<Address>(Method.Post, "addresses/create_and_verify", parameters, "address");
public async Task<Address> CreateAndVerify(Dictionary<string, object> parameters) => await RequestAsync<Address>(Method.Post, "addresses/create_and_verify", parameters, "address");

/// <summary>
/// Create and verify an <see cref="Address"/>.
Expand All @@ -109,7 +109,7 @@ public async Task<Address> Create(BetaFeatures.Parameters.Addresses.Create param
public async Task<Address> CreateAndVerify(BetaFeatures.Parameters.Addresses.Create parameters)
{
// Because the normal Create method does wrapping internally, we can't simply pass the parameters object to it, otherwise it will wrap the parameters twice.
return await Request<Address>(Method.Post, "addresses/create_and_verify", parameters.ToDictionary(), "address");
return await RequestAsync<Address>(Method.Post, "addresses/create_and_verify", parameters.ToDictionary(), "address");
}

/// <summary>
Expand All @@ -130,7 +130,7 @@ public async Task<Address> CreateAndVerify(BetaFeatures.Parameters.Addresses.Cre
[CrudOperations.Read]
public async Task<AddressCollection> All(Dictionary<string, object>? parameters = null)
{
AddressCollection collection = await Request<AddressCollection>(Method.Get, "addresses", parameters);
AddressCollection collection = await RequestAsync<AddressCollection>(Method.Get, "addresses", parameters);
collection.Filters = BaseAllParameters.FromDictionary<BetaFeatures.Parameters.Addresses.All>(parameters);
return collection;
}
Expand Down Expand Up @@ -159,7 +159,7 @@ public async Task<AddressCollection> All(Dictionary<string, object>? parameters
/// <param name="id">String representing an Address. Starts with "adr_".</param>
/// <returns>EasyPost.Address instance.</returns>
[CrudOperations.Read]
public async Task<Address> Retrieve(string id) => await Request<Address>(Method.Get, $"addresses/{id}");
public async Task<Address> Retrieve(string id) => await RequestAsync<Address>(Method.Get, $"addresses/{id}");

/// <summary>
/// Verify an Address.
Expand All @@ -169,7 +169,7 @@ public async Task<AddressCollection> All(Dictionary<string, object>? parameters
[CrudOperations.Update]
public async Task<Address> Verify(string id)
{
return await Request<Address>(Method.Get, $"addresses/{id}/verify", null, "address");
return await RequestAsync<Address>(Method.Get, $"addresses/{id}/verify", null, "address");
}

#endregion
Expand Down
2 changes: 1 addition & 1 deletion EasyPost/Services/ApiKeyService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ internal ApiKeyService(EasyPostClient client)
/// </summary>
/// <returns>An EasyPost.ApiKeyCollection instances.</returns>
[CrudOperations.Read]
public async Task<ApiKeyCollection> All() => await Request<ApiKeyCollection>(Method.Get, "api_keys");
public async Task<ApiKeyCollection> All() => await RequestAsync<ApiKeyCollection>(Method.Get, "api_keys");

#endregion
}
Expand Down
30 changes: 15 additions & 15 deletions EasyPost/Services/BatchService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ internal BatchService(EasyPostClient client)
public async Task<Batch> Create(Dictionary<string, object>? parameters = null)
{
parameters = parameters?.Wrap("batch");
return await Request<Batch>(Method.Post, "batches", parameters);
return await RequestAsync<Batch>(Method.Post, "batches", parameters);
}

/// <summary>
Expand All @@ -47,7 +47,7 @@ public async Task<Batch> Create(Dictionary<string, object>? parameters = null)
public async Task<Batch> Create(BetaFeatures.Parameters.Batches.Create parameters)
{
// Because the normal Create method does wrapping internally, we can't simply pass the parameters object to it, otherwise it will wrap the parameters twice.
return await Request<Batch>(Method.Post, "batches", parameters.ToDictionary());
return await RequestAsync<Batch>(Method.Post, "batches", parameters.ToDictionary());
}

/// <summary>
Expand All @@ -64,7 +64,7 @@ public async Task<Batch> Create(BetaFeatures.Parameters.Batches.Create parameter
public async Task<Batch> CreateAndBuy(Dictionary<string, object> parameters)
{
parameters = parameters.Wrap("batch");
return await Request<Batch>(Method.Post, "batches/create_and_buy", parameters);
return await RequestAsync<Batch>(Method.Post, "batches/create_and_buy", parameters);
}

/// <summary>
Expand All @@ -76,7 +76,7 @@ public async Task<Batch> CreateAndBuy(Dictionary<string, object> parameters)
public async Task<Batch> CreateAndBuy(BetaFeatures.Parameters.Batches.Create parameters)
{
// Because the normal Create method does wrapping internally, we can't simply pass the parameters object to it, otherwise it will wrap the parameters twice.
return await Request<Batch>(Method.Post, "batches/create_and_buy", parameters.ToDictionary());
return await RequestAsync<Batch>(Method.Post, "batches/create_and_buy", parameters.ToDictionary());
}

/// <summary>
Expand All @@ -97,7 +97,7 @@ public async Task<Batch> CreateAndBuy(BetaFeatures.Parameters.Batches.Create par
[CrudOperations.Read]
public async Task<BatchCollection> All(Dictionary<string, object>? parameters = null)
{
BatchCollection collection = await Request<BatchCollection>(Method.Get, "batches", parameters);
BatchCollection collection = await RequestAsync<BatchCollection>(Method.Get, "batches", parameters);
collection.Filters = BaseAllParameters.FromDictionary<BetaFeatures.Parameters.Batches.All>(parameters);
return collection;
}
Expand All @@ -120,7 +120,7 @@ public async Task<BatchCollection> All(Dictionary<string, object>? parameters =
[CrudOperations.Update]
public async Task<Batch> AddShipments(string id, Dictionary<string, object> parameters)
{
return await Request<Batch>(Method.Post, $"batches/{id}/add_shipments", parameters);
return await RequestAsync<Batch>(Method.Post, $"batches/{id}/add_shipments", parameters);
}

/// <summary>
Expand All @@ -129,7 +129,7 @@ public async Task<Batch> AddShipments(string id, Dictionary<string, object> para
/// <param name="id">String representing a Batch. Starts with "batch_".</param>
/// <returns>EasyPost.Batch instance.</returns>
[CrudOperations.Read]
public async Task<Batch> Retrieve(string id) => await Request<Batch>(Method.Get, $"batches/{id}");
public async Task<Batch> Retrieve(string id) => await RequestAsync<Batch>(Method.Get, $"batches/{id}");

/// <summary>
/// Add <see cref="Shipment"/>s to this <see cref="Batch"/>.
Expand All @@ -139,7 +139,7 @@ public async Task<Batch> AddShipments(string id, Dictionary<string, object> para
[CrudOperations.Update]
public async Task<Batch> AddShipments(string id, BetaFeatures.Parameters.Batches.AddShipments parameters)
{
return await Request<Batch>(Method.Post, $"batches/{id}/add_shipments", parameters.ToDictionary());
return await RequestAsync<Batch>(Method.Post, $"batches/{id}/add_shipments", parameters.ToDictionary());
}

/// <summary>
Expand Down Expand Up @@ -173,7 +173,7 @@ public async Task<Batch> AddShipments(string id, IEnumerable<string> shipmentIds
[CrudOperations.Update]
public async Task<Batch> Buy(string id)
{
return await Request<Batch>(Method.Post, $"batches/{id}/buy");
return await RequestAsync<Batch>(Method.Post, $"batches/{id}/buy");
}

/// <summary>
Expand All @@ -185,7 +185,7 @@ public async Task<Batch> Buy(string id)
public async Task<Batch> GenerateLabel(string id, string fileFormat = "pdf") // TODO: Remove default value (breaking change)
{
Dictionary<string, object> parameters = new() { { "file_format", fileFormat } };
return await Request<Batch>(Method.Post, $"batches/{id}/label", parameters);
return await RequestAsync<Batch>(Method.Post, $"batches/{id}/label", parameters);
}

/// <summary>
Expand All @@ -196,7 +196,7 @@ public async Task<Batch> GenerateLabel(string id, string fileFormat = "pdf") //
[CrudOperations.Update]
public async Task<Batch> GenerateLabel(string id, BetaFeatures.Parameters.Batches.GenerateLabel parameters)
{
return await Request<Batch>(Method.Post, $"batches/{id}/label", parameters.ToDictionary());
return await RequestAsync<Batch>(Method.Post, $"batches/{id}/label", parameters.ToDictionary());
}

/// <summary>
Expand All @@ -208,7 +208,7 @@ public async Task<Batch> GenerateLabel(string id, BetaFeatures.Parameters.Batche
public async Task<Batch> GenerateScanForm(string id, string fileFormat = "pdf") // TODO: Remove default value (breaking change)
{
Dictionary<string, object> parameters = new() { { "file_format", fileFormat } };
return await Request<Batch>(Method.Post, $"batches/{id}/scan_form", parameters);
return await RequestAsync<Batch>(Method.Post, $"batches/{id}/scan_form", parameters);
}

/// <summary>
Expand All @@ -219,7 +219,7 @@ public async Task<Batch> GenerateScanForm(string id, string fileFormat = "pdf")
[CrudOperations.Update]
public async Task<Batch> GenerateScanForm(string id, BetaFeatures.Parameters.Batches.GenerateScanForm parameters)
{
return await Request<Batch>(Method.Post, $"batches/{id}/scan_form", parameters.ToDictionary());
return await RequestAsync<Batch>(Method.Post, $"batches/{id}/scan_form", parameters.ToDictionary());
}

/// <summary>
Expand All @@ -230,7 +230,7 @@ public async Task<Batch> GenerateScanForm(string id, BetaFeatures.Parameters.Bat
[CrudOperations.Update]
public async Task<Batch> RemoveShipments(string id, Dictionary<string, object> parameters)
{
return await Request<Batch>(Method.Post, $"batches/{id}/remove_shipments", parameters);
return await RequestAsync<Batch>(Method.Post, $"batches/{id}/remove_shipments", parameters);
}

/// <summary>
Expand All @@ -241,7 +241,7 @@ public async Task<Batch> RemoveShipments(string id, Dictionary<string, object> p
[CrudOperations.Update]
public async Task<Batch> RemoveShipments(string id, BetaFeatures.Parameters.Batches.RemoveShipments parameters)
{
return await Request<Batch>(Method.Post, $"batches/{id}/remove_shipments", parameters.ToDictionary());
return await RequestAsync<Batch>(Method.Post, $"batches/{id}/remove_shipments", parameters.ToDictionary());
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion EasyPost/Services/Beta/CarrierMetadataService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public async Task<List<Carrier>> RetrieveCarrierMetadata(BetaFeatures.Parameters
{
Dictionary<string, object> data = parameters?.ToDictionary() ?? new Dictionary<string, object>();

return await Request<List<Carrier>>(Method.Get, "metadata", data, "carriers", ApiVersion.Beta);
return await RequestAsync<List<Carrier>>(Method.Get, "metadata", data, "carriers", ApiVersion.Beta);
}

#endregion
Expand Down
4 changes: 2 additions & 2 deletions EasyPost/Services/Beta/RateService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ internal RateService(EasyPostClient client)
public async Task<List<StatelessRate>> RetrieveStatelessRates(Dictionary<string, object> parameters)
{
parameters = parameters.Wrap("shipment");
return await Request<List<StatelessRate>>(Method.Post, "rates", parameters, "rates", ApiVersion.Beta);
return await RequestAsync<List<StatelessRate>>(Method.Post, "rates", parameters, "rates", ApiVersion.Beta);
}

/// <summary>
Expand All @@ -54,7 +54,7 @@ public async Task<List<StatelessRate>> RetrieveStatelessRates(Dictionary<string,
[CrudOperations.Create]
public async Task<List<StatelessRate>> RetrieveStatelessRates(BetaFeatures.Parameters.Beta.Rates.Retrieve parameters)
{
return await Request<List<StatelessRate>>(Method.Post, "rates", parameters.ToDictionary(), "rates", ApiVersion.Beta);
return await RequestAsync<List<StatelessRate>>(Method.Post, "rates", parameters.ToDictionary(), "rates", ApiVersion.Beta);
}

#endregion
Expand Down
12 changes: 6 additions & 6 deletions EasyPost/Services/Beta/ReferralCustomerService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public async Task<PaymentMethod> AddPaymentMethod(string stripeCustomerId, strin
},
};

return await Request<PaymentMethod>(Method.Post, "referral_customers/payment_method", parameters, overrideApiVersion: ApiVersion.Beta);
return await RequestAsync<PaymentMethod>(Method.Post, "referral_customers/payment_method", parameters, overrideApiVersion: ApiVersion.Beta);
}

/// <summary>
Expand All @@ -60,7 +60,7 @@ public async Task<PaymentMethod> AddPaymentMethod(string stripeCustomerId, strin
[CrudOperations.Update]
public async Task<PaymentMethod> AddPaymentMethod(BetaFeatures.Parameters.ReferralCustomers.AddPaymentMethod parameters)
{
return await Request<PaymentMethod>(Method.Post, "referral_customers/payment_method", parameters.ToDictionary(), overrideApiVersion: ApiVersion.Beta);
return await RequestAsync<PaymentMethod>(Method.Post, "referral_customers/payment_method", parameters.ToDictionary(), overrideApiVersion: ApiVersion.Beta);
}

/// <summary>
Expand All @@ -77,7 +77,7 @@ public async Task<PaymentRefund> RefundByAmount(int amount)
{ "refund_amount", amount },
};

return await Request<PaymentRefund>(Method.Post, "referral_customers/refunds", parameters, overrideApiVersion: ApiVersion.Beta);
return await RequestAsync<PaymentRefund>(Method.Post, "referral_customers/refunds", parameters, overrideApiVersion: ApiVersion.Beta);
}

/// <summary>
Expand All @@ -88,7 +88,7 @@ public async Task<PaymentRefund> RefundByAmount(int amount)
[CrudOperations.Update]
public async Task<PaymentRefund> RefundByAmount(BetaFeatures.Parameters.ReferralCustomers.RefundByAmount parameters)
{
return await Request<PaymentRefund>(Method.Post, "referral_customers/refunds", parameters.ToDictionary(), overrideApiVersion: ApiVersion.Beta);
return await RequestAsync<PaymentRefund>(Method.Post, "referral_customers/refunds", parameters.ToDictionary(), overrideApiVersion: ApiVersion.Beta);
}

/// <summary>
Expand All @@ -105,7 +105,7 @@ public async Task<PaymentRefund> RefundByPaymentLog(string paymentLogId)
{ "payment_log_id", paymentLogId },
};

return await Request<PaymentRefund>(Method.Post, "referral_customers/refunds", parameters, overrideApiVersion: ApiVersion.Beta);
return await RequestAsync<PaymentRefund>(Method.Post, "referral_customers/refunds", parameters, overrideApiVersion: ApiVersion.Beta);
}

/// <summary>
Expand All @@ -116,7 +116,7 @@ public async Task<PaymentRefund> RefundByPaymentLog(string paymentLogId)
[CrudOperations.Update]
public async Task<PaymentRefund> RefundByPaymentLog(BetaFeatures.Parameters.ReferralCustomers.RefundByPaymentLog parameters)
{
return await Request<PaymentRefund>(Method.Post, "referral_customers/refunds", parameters.ToDictionary(), overrideApiVersion: ApiVersion.Beta);
return await RequestAsync<PaymentRefund>(Method.Post, "referral_customers/refunds", parameters.ToDictionary(), overrideApiVersion: ApiVersion.Beta);
}

#endregion
Expand Down
6 changes: 3 additions & 3 deletions EasyPost/Services/BillingService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public async Task FundWallet(string amount, PaymentMethod.Priority? priority = n

Dictionary<string, object> parameters = new() { { "amount", amount } };

await Request(Method.Post, $"{paymentMethod.Endpoint}/{paymentMethod.Id}/charges", parameters);
await RequestAsync(Method.Post, $"{paymentMethod.Endpoint}/{paymentMethod.Id}/charges", parameters);
}

/// <summary>
Expand All @@ -45,7 +45,7 @@ public async Task FundWallet(string amount, PaymentMethod.Priority? priority = n
[CrudOperations.Read]
public async Task<PaymentMethodsSummary> RetrievePaymentMethodsSummary()
{
PaymentMethodsSummary paymentMethodsSummary = await Request<PaymentMethodsSummary>(Method.Get, "payment_methods");
PaymentMethodsSummary paymentMethodsSummary = await RequestAsync<PaymentMethodsSummary>(Method.Get, "payment_methods");

return paymentMethodsSummary.Id == null
? throw new InvalidObjectError(Constants.ErrorMessages.NoPaymentMethods)
Expand All @@ -62,7 +62,7 @@ public async Task DeletePaymentMethod(PaymentMethod.Priority priority)
{
PaymentMethod paymentMethod = await GetPaymentMethodByPriority(priority);

await Request(Method.Delete, $"{paymentMethod.Endpoint}/{paymentMethod.Id}");
await RequestAsync(Method.Delete, $"{paymentMethod.Endpoint}/{paymentMethod.Id}");
}

#endregion
Expand Down
Loading

0 comments on commit db9928a

Please sign in to comment.