using AS1024.GeoFeed.Models;
using System.Text;
namespace AS1024.GeoFeed.Core.Tools
{
public static class GeoFeedTools
{
///
/// Returns a CSV string for a given GeoFeed retreived from various sources
///
/// GeoFeed returned from the source of truth
/// If a timestamp should be appended at the header
/// If the result is cached
///
public static string ToGeoFeedCsv(this List geoFeeds, bool timeStamp = false, bool isCached = false)
{
StringBuilder csvContent = new();
if (timeStamp)
csvContent.AppendLine($"# GeoFeed generated on {DateTime.UtcNow:R}");
if (isCached)
csvContent.AppendLine($"# Geofeed data is returned from local in memory cache");
foreach (IPGeoFeed feed in geoFeeds)
{
csvContent.AppendLine($"{feed.Prefix},{feed.GeolocCountry},{feed.GeolocRegion},{feed.GeolocCity},{feed.GeolocPostalCode}");
}
return csvContent.ToString();
}
}
}