From a304c24b32c0327436bbd8c2853e60668e161b42 Mon Sep 17 00:00:00 2001 From: Ariel Costas Guerrero Date: Mon, 29 Dec 2025 00:41:52 +0100 Subject: Rename a lot of stuff, add Santiago real time --- .../SantiagoRealtimeEstimatesProvider.cs | 40 ++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/Enmarcha.Sources.Tussa/SantiagoRealtimeEstimatesProvider.cs (limited to 'src/Enmarcha.Sources.Tussa/SantiagoRealtimeEstimatesProvider.cs') diff --git a/src/Enmarcha.Sources.Tussa/SantiagoRealtimeEstimatesProvider.cs b/src/Enmarcha.Sources.Tussa/SantiagoRealtimeEstimatesProvider.cs new file mode 100644 index 0000000..7437a05 --- /dev/null +++ b/src/Enmarcha.Sources.Tussa/SantiagoRealtimeEstimatesProvider.cs @@ -0,0 +1,40 @@ +using System.Net.Http.Json; + +namespace Enmarcha.Sources.Tussa; + +public class SantiagoRealtimeEstimatesProvider +{ + private HttpClient _http; + + public SantiagoRealtimeEstimatesProvider(HttpClient http) + { + _http = http; + } + + public async Task> GetEstimatesForStop(int stopId) + { + var url = GetRequestUrl(stopId.ToString()); + + var response = await _http.GetAsync(url); + var maisbusResponse = await response.Content.ReadFromJsonAsync(); + + if (maisbusResponse is null) + { + var responseString = await response.Content.ReadAsStringAsync(); + throw new Exception("Error parsing maisbus response: " + responseString); + } + + return maisbusResponse.Routes.Select(r => new SantiagoEstimate + ( + r.Id.ToString(), + r.MinutesToArrive + )).OrderBy(a => a.Minutes).ToList(); + } + + private static string GetRequestUrl(string stopId) + { + return $"https://tussa.gal/maisbus/api/stop/{stopId}"; + } +} + +public record SantiagoEstimate(string RouteId, int Minutes); -- cgit v1.3