Compare commits
2 Commits
2d5c318689
...
9c5fbc314f
| Author | SHA1 | Date |
|---|---|---|
|
|
9c5fbc314f | |
|
|
1f3778095c |
|
|
@ -31,7 +31,7 @@ namespace AS1024.GeoFeed.GeoFeedBuilder
|
|||
|
||||
public async Task<List<IPGeoFeed>> GetGeoFeedData()
|
||||
{
|
||||
List<IPGeoFeed> geoFeed = new List<IPGeoFeed>();
|
||||
List<IPGeoFeed> geoFeed = [];
|
||||
using HttpClient client = httpClientFactory.CreateClient();
|
||||
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Token", configuration["APIKey"]);
|
||||
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
|
||||
|
|
@ -46,45 +46,47 @@ namespace AS1024.GeoFeed.GeoFeedBuilder
|
|||
logger.LogDebug($"Making request to {uri}...");
|
||||
|
||||
using HttpResponseMessage result = await client.GetAsync(uri);
|
||||
if (result.IsSuccessStatusCode)
|
||||
if (!result.IsSuccessStatusCode)
|
||||
{
|
||||
string stringResult = await result.Content.ReadAsStringAsync();
|
||||
jsonData = JsonSerializer.Deserialize<NetboxData>(stringResult, new JsonSerializerOptions {
|
||||
PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseLower
|
||||
});
|
||||
break;
|
||||
}
|
||||
string stringResult = await result.Content.ReadAsStringAsync();
|
||||
jsonData = JsonSerializer.Deserialize<NetboxData>(stringResult, new JsonSerializerOptions
|
||||
{
|
||||
PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseLower
|
||||
});
|
||||
|
||||
if (jsonData?.Results == null || jsonData.Results.Count == 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
if (jsonData?.Results == null || jsonData.Results.Count == 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
foreach (Result data in jsonData.Results)
|
||||
foreach (Result data in jsonData.Results)
|
||||
{
|
||||
try
|
||||
{
|
||||
try
|
||||
geoFeed.Add(new IPGeoFeed
|
||||
{
|
||||
geoFeed.Add(new IPGeoFeed
|
||||
{
|
||||
Prefix = data.Prefix,
|
||||
GeolocCity = data.CustomFields.GeolocCity,
|
||||
GeolocRegion = data.CustomFields.GeolocRegion,
|
||||
GeolocCountry = data.CustomFields.GeolocCountry,
|
||||
GeolocHasLocation = data.CustomFields.GeolocHasLocation,
|
||||
GeolocPostalCode = data.CustomFields.GeolocPostalCode
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex.ToString());
|
||||
}
|
||||
Prefix = data.Prefix,
|
||||
GeolocCity = data.CustomFields.GeolocCity,
|
||||
GeolocRegion = data.CustomFields.GeolocRegion,
|
||||
GeolocCountry = data.CustomFields.GeolocCountry,
|
||||
GeolocHasLocation = data.CustomFields.GeolocHasLocation,
|
||||
GeolocPostalCode = data.CustomFields.GeolocPostalCode
|
||||
});
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(jsonData.Next))
|
||||
catch (Exception ex)
|
||||
{
|
||||
uri = new Uri(jsonData.Next);
|
||||
continue;
|
||||
logger.LogError(ex.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(jsonData.Next))
|
||||
{
|
||||
uri = new Uri(jsonData.Next);
|
||||
continue;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue