diff options
| author | Ariel Costas Guerrero <ariel@costas.dev> | 2025-12-26 15:56:09 +0100 |
|---|---|---|
| committer | Ariel Costas Guerrero <ariel@costas.dev> | 2025-12-26 15:56:09 +0100 |
| commit | ef2df90ffb195edcddd701511dc5953c7baa63af (patch) | |
| tree | 68ab850068e686647beccec8036e6905ecbab242 /src/Costasdev.Busurbano.Sources.OpenTripPlannerGql/OpenTripPlannerClient.cs | |
| parent | 70b5788269845bbf368af5b13b495c70a08927f2 (diff) | |
Move OpenTripPlanner source to separate package
Diffstat (limited to 'src/Costasdev.Busurbano.Sources.OpenTripPlannerGql/OpenTripPlannerClient.cs')
| -rw-r--r-- | src/Costasdev.Busurbano.Sources.OpenTripPlannerGql/OpenTripPlannerClient.cs | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/src/Costasdev.Busurbano.Sources.OpenTripPlannerGql/OpenTripPlannerClient.cs b/src/Costasdev.Busurbano.Sources.OpenTripPlannerGql/OpenTripPlannerClient.cs new file mode 100644 index 0000000..eed78d6 --- /dev/null +++ b/src/Costasdev.Busurbano.Sources.OpenTripPlannerGql/OpenTripPlannerClient.cs @@ -0,0 +1,47 @@ +using System.Net.Http.Json; +using Costasdev.Busurbano.Sources.OpenTripPlannerGql.Queries; +using Microsoft.Extensions.Logging; + +namespace Costasdev.Busurbano.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() + ); + } + } +} |
