-
Notifications
You must be signed in to change notification settings - Fork 3
/
departure.go
106 lines (91 loc) · 3.14 KB
/
departure.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/*
* Copyright (C) 2014 Michael Wendland
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Authors:
* Michael Wendland <[email protected]>
*/
package goefa
import (
"net/url"
"strconv"
"time"
)
// EFADepartureArrival represents either an arrival or a departure and is not
// directly used but embedded by EFAArrival and EFADeparture.
type EFADepartureArrival struct {
Area int `xml:"area,attr"`
Countdown int `xml:"countdown,attr"`
MapName string `xml:"mapName,attr"`
Platform string `xml:"platform,attr"`
PlatformName string `xml:"platformName,attr"`
StopID int `xml:"displayName,attr"`
StopName string `xml:"stopName,attr"`
Lat int64 `xml:"x,attr"`
Lng int64 `xml:"y,attr"`
DateTime EFATime `xml:"itdDateTime"`
ServingLine EFAServingLine `xml:"itdServingLine"`
}
// EFAArrival represents a single arrival for a specific stop.
type EFAArrival struct {
EFADepartureArrival `xml:"itdArrival"`
}
// EFADeparture represents a single departure for a specific stop.
type EFADeparture struct {
EFADepartureArrival `xml:"itdDeparture"`
}
type departureMonitorResult struct {
efaResponse
Odv struct {
OdvPlace struct {
}
OdvName struct {
State string `xml:"state,attr"`
} `xml:"itdOdvName"`
} `xml:"itdDepartureMonitorRequest>itdOdv"`
Departures []*EFADeparture `xml:"itdDepartureMonitorRequest>itdDepartureList>itdDeparture"`
}
func (d *departureMonitorResult) endpoint() string {
return "XML_DM_REQUEST"
}
// Departures performs a stateless dm_request for the corresponding stopID and
// returns an array of EFADepartures. Use time.Now() as the second argument in
// order to get the very next departures. The third argument determines how
// many results will be returned by EFA.
func (efa *EFAProvider) Departures(stopID int, due time.Time, results int) ([]*EFADeparture, error) {
var rt string
if efa.EnableRealtime {
rt = "1"
} else {
rt = "0"
}
params := url.Values{
"type_dm": {"any"},
"name_dm": {strconv.Itoa(stopID)},
"locationServerActive": {"1"},
"useRealtime": {rt},
"dmLineSelection": {"all"}, //FIXME enable line selection
"limit": {strconv.Itoa(results)},
"mode": {"direct"},
"stateless": {"1"},
"itdDate": {due.Format("20060102")},
"itdTime": {due.Format("1504")},
}
var result departureMonitorResult
if err := efa.postRequest(&result, params); err != nil {
return nil, err
}
return result.Departures, nil
}