diff options
| author | Ariel Costas Guerrero <ariel@costas.dev> | 2025-12-29 00:41:52 +0100 |
|---|---|---|
| committer | Ariel Costas Guerrero <ariel@costas.dev> | 2025-12-29 00:41:52 +0100 |
| commit | a304c24b32c0327436bbd8c2853e60668e161b42 (patch) | |
| tree | 08f65c05daca134cf4d2e4f779bd15d98fd66370 /src/Enmarcha.Sources.OpenTripPlannerGql/OpenTripPlannerClient.cs | |
| parent | 120a3c6bddd0fb8d9fa05df4763596956554c025 (diff) | |
Rename a lot of stuff, add Santiago real time
Diffstat (limited to 'src/Enmarcha.Sources.OpenTripPlannerGql/OpenTripPlannerClient.cs')
| -rw-r--r-- | src/Enmarcha.Sources.OpenTripPlannerGql/OpenTripPlannerClient.cs | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/src/Enmarcha.Sources.OpenTripPlannerGql/OpenTripPlannerClient.cs b/src/Enmarcha.Sources.OpenTripPlannerGql/OpenTripPlannerClient.cs new file mode 100644 index 0000000..453a03e --- /dev/null +++ b/src/Enmarcha.Sources.OpenTripPlannerGql/OpenTripPlannerClient.cs @@ -0,0 +1,47 @@ +using System.Net.Http.Json; +using Enmarcha.Sources.OpenTripPlannerGql.Queries; +using Microsoft.Extensions.Logging; + +namespace Enmarcha.Sources.OpenTripPlannerGql; + +public class OpenTripPlannerClient +{ + private readonly HttpClient _httpClient; + private readonly string _baseUrl; + private readonly ILogger<OpenTripPlannerClient> _logger; + + public OpenTripPlannerClient( + HttpClient httpClient, + string baseUrl, + ILogger<OpenTripPlannerClient> logger + ) + { + _httpClient = httpClient; + _baseUrl = baseUrl; + _logger = logger; + } + + public async Task GetStopsInBbox(double minLat, double minLon, double maxLat, double maxLon) + { + var requestContent = + StopTileRequestContent.Query(new StopTileRequestContent.Bbox(minLon, minLat, maxLon, maxLat)); + + var request = new HttpRequestMessage(HttpMethod.Post, $"{_baseUrl}/gtfs/v1"); + request.Content = JsonContent.Create(new GraphClientRequest + { + Query = requestContent + }); + + var response = await _httpClient.SendAsync(request); + var responseBody = await response.Content.ReadFromJsonAsync<GraphClientResponse<StopTileResponse>>(); + + if (responseBody is not { IsSuccess: true }) + { + _logger.LogError( + "Error fetching stop data, received {StatusCode} {ResponseBody}", + response.StatusCode, + await response.Content.ReadAsStringAsync() + ); + } + } +} |
