Make the code cleaner to read

This commit is contained in:
Jeff Leung 2024-01-08 23:18:26 -08:00
parent dd643ab8ab
commit 1f3778095c
1 changed files with 32 additions and 30 deletions

View File

@ -31,7 +31,7 @@ namespace AS1024.GeoFeed.GeoFeedBuilder
public async Task<List<IPGeoFeed>> GetGeoFeedData() public async Task<List<IPGeoFeed>> GetGeoFeedData()
{ {
List<IPGeoFeed> geoFeed = new List<IPGeoFeed>(); List<IPGeoFeed> geoFeed = [];
using HttpClient client = httpClientFactory.CreateClient(); using HttpClient client = httpClientFactory.CreateClient();
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Token", configuration["APIKey"]); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Token", configuration["APIKey"]);
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
@ -46,10 +46,13 @@ namespace AS1024.GeoFeed.GeoFeedBuilder
logger.LogDebug($"Making request to {uri}..."); logger.LogDebug($"Making request to {uri}...");
using HttpResponseMessage result = await client.GetAsync(uri); using HttpResponseMessage result = await client.GetAsync(uri);
if (result.IsSuccessStatusCode) if (!result.IsSuccessStatusCode)
{ {
break;
}
string stringResult = await result.Content.ReadAsStringAsync(); string stringResult = await result.Content.ReadAsStringAsync();
jsonData = JsonSerializer.Deserialize<NetboxData>(stringResult, new JsonSerializerOptions { jsonData = JsonSerializer.Deserialize<NetboxData>(stringResult, new JsonSerializerOptions
{
PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseLower PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseLower
}); });
@ -83,7 +86,6 @@ namespace AS1024.GeoFeed.GeoFeedBuilder
uri = new Uri(jsonData.Next); uri = new Uri(jsonData.Next);
continue; continue;
} }
}
break; break;
} }