Skip to content

Commit

Permalink
Fixed fields is the BulkVS order response that weren't serializing.
Browse files Browse the repository at this point in the history
  • Loading branch information
uncheckederror committed Oct 27, 2024
1 parent 534bffd commit 457d4dc
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 4 deletions.
41 changes: 39 additions & 2 deletions NumberSearch.DataAccess/BulkVS/OrderTn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,19 +138,55 @@ public class OrderTnRequestBody
/// <param name="username"></param>
/// <param name="password"></param>
/// <returns></returns>
/// example JSON responses:
// We already own the number:
//{
// "TN": "12062752462",
// "Status": "Failed",
// "Code": "7511",
// "Description": "Telephone Number already provisioned to your account"
//}
//Successful purchase:
//{
// "TN": "14255475185",
// "Status": "Active",
// "Lidb": "Accelerate Networks",
// "Portout Pin": "3591344",
// "ReferenceID": "",
// "Routing": {
// "Trunk Group": "",
// "Custom URI": null,
// "Call Forward": null
// },
// "Messaging": {
// "Sms": true,
// "Mms": false
// },
// "TN Details": {
// "Rate Center": "RENTON",
// "State": "WA",
// "Tier": "0",
// "Cnam": true,
// "Activation Date": "2024-10-26 22:06:28"
// }
//}
public async Task<OrderTnResponseBody> PostAsync(string username, string password)
{
string baseUrl = "https://portal.bulkvs.com/api/v1.0/";
string endpoint = "orderTn";
string route = $"{baseUrl}{endpoint}";
try
{
return await route.WithBasicAuth(username, password).PostJsonAsync(this).ReceiveJson<OrderTnResponseBody>().ConfigureAwait(false);
var response = await route.WithBasicAuth(username, password).PostJsonAsync(this).ReceiveString().ConfigureAwait(false);
OrderTnResponseBody? weatherForecast =
System.Text.Json.JsonSerializer.Deserialize<OrderTnResponseBody>(response);
return weatherForecast ?? new();
}
catch (FlurlHttpException ex)
{
Log.Error($"[Ingest] [BulkVS] Failed to order {TN}.");
Log.Error(await ex.GetResponseStringAsync());
var x = await ex.GetResponseStringAsync();
var error = await ex.GetResponseJsonAsync<OrderTnFailed>();

return new OrderTnResponseBody
Expand All @@ -167,6 +203,7 @@ public class OrderTnResponseBody
public string TN { get; set; } = string.Empty;
public string Status { get; set; } = string.Empty;
public string Lidb { get; set; } = string.Empty;
[JsonPropertyName("Portout Pin")]
public string PortoutPin { get; set; } = string.Empty;
public OrderTnRouting Routing { get; set; } = new();
public OrderTnMessaging Messaging { get; set; } = new();
Expand Down Expand Up @@ -201,7 +238,7 @@ public class OrderTnTNDetails
[JsonProperty("Rate Center")]
public string RateCenter { get; set; } = string.Empty;
public string State { get; set; } = string.Empty;
public int Tier { get; set; }
public string Tier { get; set; } = string.Empty;
public bool Cnam { get; set; }
[JsonPropertyName("Activation Date")]
[JsonProperty("Activation Date")]
Expand Down
2 changes: 1 addition & 1 deletion NumberSearch.Mvc/WorkerServices/MonitorLoop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public async Task MonitorAsync()
var orderResponse = await executeOrder.PostAsync(_bulkVSusername, _bulkVSpassword).ConfigureAwait(false);
nto.Purchased = string.IsNullOrWhiteSpace(orderResponse?.Failed?.Description);
nto.Purchased = string.IsNullOrWhiteSpace(orderResponse?.Failed?.Description) && orderResponse?.Status is "Active";
productOrder.DateOrdered = DateTime.Now;
// Keep the raw response as a receipt.
productOrder.OrderResponse = JsonSerializer.Serialize(orderResponse);
Expand Down
2 changes: 1 addition & 1 deletion NumberSearch.Tests/Integration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ public async Task BulkVSRESTNpaNxxGetAsyncTestAsync()
// // Arrange
// var order = new OrderTnRequestBody
// {
// TN = "13109060901",
// TN = "14255475245",
// Lidb = "Accelerate Networks",
// PortoutPin = "3591344",
// TrunkGroup = "Primary",
Expand Down

0 comments on commit 457d4dc

Please sign in to comment.