aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Polden <mpolden@mpolden.no>2022-05-20 17:39:04 +0200
committerMartin Polden <mpolden@mpolden.no>2022-05-20 17:42:28 +0200
commit9a0b1f0bd0ffa552aa9ba79c181ecca4def028e7 (patch)
tree04e38dd4bb4fceb98550f5ebfbc87abc0d1e0617
parent4b19282459ad71905fa2b289e885226e855fc9e2 (diff)
entur: Switch to API v3
-rw-r--r--entur/entur.go14
-rw-r--r--entur/entur_test.go14
-rw-r--r--entur/testdata/ilsvika.json48
-rw-r--r--http/http_test.go4
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
@@ -5,46 +5,8 @@
"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"