From 9a0b1f0bd0ffa552aa9ba79c181ecca4def028e7 Mon Sep 17 00:00:00 2001 From: Martin Polden Date: Fri, 20 May 2022 17:39:04 +0200 Subject: entur: Switch to API v3 --- entur/entur.go | 14 +++++++------ entur/entur_test.go | 14 ++++++++++--- entur/testdata/ilsvika.json | 48 +++++---------------------------------------- http/http_test.go | 4 ++-- 4 files changed, 26 insertions(+), 54 deletions(-) diff --git a/entur/entur.go b/entur/entur.go index d68c764..cd35da8 100644 --- a/entur/entur.go +++ b/entur/entur.go @@ -10,8 +10,8 @@ import ( ) // DefaultURL is the default Entur Journey Planner API URL. Documentation at -// https://developer.entur.org/pages-journeyplanner-journeyplanner-v2. -const DefaultURL = "https://api.entur.io/journey-planner/v2/graphql" +// https://developer.entur.org/pages-journeyplanner-journeyplanner-v3. +const DefaultURL = "https://api.entur.io/journey-planner/v3/graphql" // Client implements a client for the Entur Journey Planner API. type Client struct{ URL string } @@ -61,7 +61,7 @@ type destinationDisplay struct { } type serviceJourney struct { - Operator operator `json:"operator"` + Operator operator `json:"operator"` JourneyPattern journeyPattern `json:"journeyPattern"` } @@ -87,7 +87,7 @@ func (c *Client) Departures(count, stopID int) ([]Departure, error) { return nil, err } req.Header.Set("Content-Type", "application/json") - // Identify this client. See https://developer.entur.org/pages-journeyplanner-journeyplanner-v2 + // Identify this client. See https://developer.entur.org/pages-journeyplanner-journeyplanner-v3 req.Header.Set("ET-Client-Name", "github_mpolden-atb") resp, err := http.DefaultClient.Do(req) if err != nil { @@ -106,8 +106,10 @@ func parseDepartures(jsonData []byte) ([]Departure, error) { if err := json.Unmarshal(jsonData, &r); err != nil { return nil, err } - const operatorPrefix = "ATB:" - const timeLayout = "2006-01-02T15:04:05-0700" + const ( + operatorPrefix = "ATB:" + timeLayout = "2006-01-02T15:04:05-07:00" + ) departures := make([]Departure, 0, len(r.Data.StopPlace.EstimatedCalls)) for _, ec := range r.Data.StopPlace.EstimatedCalls { if !strings.HasPrefix(ec.ServiceJourney.Operator.Id, operatorPrefix) { diff --git a/entur/entur_test.go b/entur/entur_test.go index dd98ea1..1555bb8 100644 --- a/entur/entur_test.go +++ b/entur/entur_test.go @@ -22,15 +22,23 @@ func TestParseDepartures(t *testing.T) { { Line: "21", RegisteredDepartureTime: time.Time{}, - ScheduledDepartureTime: time.Date(2021, 8, 11, 21, 19, 0, 0, cest), + ScheduledDepartureTime: time.Date(2022, 5, 20, 18, 19, 0, 0, cest), Destination: "Pirbadet via sentrum", - IsRealtime: false, + IsRealtime: true, + Inbound: false, + }, + { + Line: "21", + RegisteredDepartureTime: time.Time{}, + ScheduledDepartureTime: time.Date(2022, 5, 20, 19, 19, 0, 0, cest), + Destination: "Pirbadet via sentrum", + IsRealtime: true, Inbound: false, }, { Line: "21", RegisteredDepartureTime: time.Time{}, - ScheduledDepartureTime: time.Date(2021, 8, 11, 22, 19, 0, 0, cest), + ScheduledDepartureTime: time.Date(2022, 5, 20, 20, 19, 0, 0, cest), Destination: "Pirbadet via sentrum", IsRealtime: true, Inbound: false, diff --git a/entur/testdata/ilsvika.json b/entur/testdata/ilsvika.json index faa8acb..6f002fd 100644 --- a/entur/testdata/ilsvika.json +++ b/entur/testdata/ilsvika.json @@ -4,47 +4,9 @@ "id": "NSR:StopPlace:42098", "name": "Ilsvika", "estimatedCalls": [ - { - "realtime": false, - "expectedDepartureTime": "2021-08-11T21:19:00+0200", - "actualDepartureTime": null, - "destinationDisplay": { - "frontText": "Pirbadet via sentrum" - }, - "serviceJourney": { - "operator": { - "id": "ATB:Operator:171" - }, - "journeyPattern": { - "directionType": "outbound", - "line": { - "publicCode": "21" - } - } - } - }, { "realtime": true, - "expectedDepartureTime": "2021-08-11T22:19:00+0200", - "actualDepartureTime": null, - "destinationDisplay": { - "frontText": "Pirbadet via sentrum" - }, - "serviceJourney": { - "operator": { - "id": "ATB:Operator:171" - }, - "journeyPattern": { - "directionType": "outbound", - "line": { - "publicCode": "21" - } - } - } - }, - { - "realtime": false, - "expectedDepartureTime": "2021-08-11T23:19:00+0200", + "expectedDepartureTime": "2022-05-20T18:19:00+02:00", "actualDepartureTime": null, "destinationDisplay": { "frontText": "Pirbadet via sentrum" @@ -62,8 +24,8 @@ } }, { - "realtime": false, - "expectedDepartureTime": "2021-08-12T00:19:00+0200", + "realtime": true, + "expectedDepartureTime": "2022-05-20T19:19:00+02:00", "actualDepartureTime": null, "destinationDisplay": { "frontText": "Pirbadet via sentrum" @@ -81,8 +43,8 @@ } }, { - "realtime": false, - "expectedDepartureTime": "2021-08-12T06:13:00+0200", + "realtime": true, + "expectedDepartureTime": "2022-05-20T20:19:00+02:00", "actualDepartureTime": null, "destinationDisplay": { "frontText": "Pirbadet via sentrum" diff --git a/http/http_test.go b/http/http_test.go index dda932e..f74db42 100644 --- a/http/http_test.go +++ b/http/http_test.go @@ -288,7 +288,7 @@ const enturResponse = `{ "estimatedCalls": [ { "realtime": true, - "expectedDepartureTime": "2021-08-11T23:33:09+0200", + "expectedDepartureTime": "2021-08-11T23:33:09+02:00", "actualDepartureTime": null, "destinationDisplay": { "frontText": "Risvollan via sentrum" @@ -307,7 +307,7 @@ const enturResponse = `{ }, { "realtime": true, - "expectedDepartureTime": "2021-08-11T23:38:01+0200", + "expectedDepartureTime": "2021-08-11T23:38:01+02:00", "actualDepartureTime": null, "destinationDisplay": { "frontText": "Hallset" -- cgit v1.2.3