-
Notifications
You must be signed in to change notification settings - Fork 0
/
ancestors.go
165 lines (146 loc) · 4.61 KB
/
ancestors.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
package oba
// Response Element - All responses are wrapped in a response element.
// The response element carries the following fields:
// version - response version information
// code - a machine-readable response code with the following semantics:
// 200 - Success
// 400 - The request could not be understood due to an invalid request parameter or some other error
// 401 - The application key is either missing or invalid
// 404 - The specified resource was not found
// 500 - A service exception or error occurred while processing the request
// text - a human-readable version of the response code
// currentTime - current system time on the api server as milliseconds since the unix epoch
// data - the response payload
// references see the discussion of references below
type Response struct {
Code int `json:"code"`
CurrentTime int `json:"currentTime"`
Data *Data `json:"data,omitempty"`
Text string `json:"text"`
Version int `json:"version"`
}
func (r Response) String() string {
return jsonStringer(r)
}
type AltResponse struct {
Code int `json:"code"`
CurrentTime int `json:"currentTime"`
Data *AltData `json:"data,omitempty"`
Text string `json:"text"`
Version int `json:"version"`
}
func (r AltResponse) String() string {
return jsonStringer(r)
}
// References - The <references/> element contains a dictionary of objects
// referenced by the main result payload. For elements that are
// often repeated in the result payload, the elements are instead
// included in the <references/> section and the payload will refer
// to elements by and object id that can be used to lookup the
// object in the <references/> dictionary.
// They will always appear in that order, since stops and trips reference routes
// and routes reference agencies. If you are processing the result stream in
// order, you should always be able to assume that an referenced entity would
// already have been included in the references section.
// Every API method supports an optional includeReferences=true|false parameter
// that determines if the <references/> section is included in a response. If
// you don’t need the contents of the <references/> section, perhaps because
// you’ve pre-cached all the elements, then setting includeReferences=false can
// be a good way to reduce the response size.
type References struct {
Agencies List `json:"agencies"`
Routes List `json:"routes"`
Situations List `json:"situations"`
Stops List `json:"stops"`
Trips List `json:"trips"`
}
func (r References) String() string {
return jsonStringer(r)
}
// Data container object
type Data struct {
LimitExceeded *bool `json:"limitExceeded,omitempty"`
List *List `json:"list,omitempty"`
Entry *Entry `json:"entry,omitempty"`
OutOfRange *bool `json:"outOfRange,omitempty"`
References *References `json:"references"`
Time *Time `json:",omitempty"`
}
func (d Data) String() string {
return jsonStringer(d)
}
func (d Data) Agencies() []Agency {
var agencies []Agency
if d.References != nil {
ref := d.References
if ref.Agencies != nil {
agencies = ref.Agencies.toAgencies()
}
}
return agencies
}
func (d Data) Routes(ags []Agency) []Route {
var routes []Route
if d.References != nil {
ref := d.References
if ref.Routes != nil {
routes = ref.Routes.toRoutes(ags)
}
}
return routes
}
func (d Data) Situations() []Situation {
var situations []Situation
if d.References != nil {
ref := d.References
if ref.Situations != nil {
situations = ref.Situations.toSituations()
}
}
return situations
}
func (d Data) Stops(rs []Route) []Stop {
var stops []Stop
if d.References != nil {
ref := d.References
if ref.Stops != nil {
stops = ref.Stops.toStops(rs)
}
}
return stops
}
func (d Data) Trips() []Trip {
var trips []Trip
if d.References != nil {
ref := d.References
if ref.Trips != nil {
trips = ref.Trips.toTrips()
}
}
return trips
}
type AltData struct {
List []string `json:"list,omitempty"`
}
func (d AltData) String() string {
return jsonStringer(d)
}
func (d Data) toTripDetails() []TripDetails {
ss := d.References.Situations.toSituations()
ts := d.References.Trips.toTrips()
tds := d.List.toTripDetails(ts, ss)
return tds
}
func (d Data) TripDetails() *TripDetails {
ss := d.References.Situations.toSituations()
ts := d.References.Trips.toTrips()
td := d.Entry.ToTripDetails(ts, ss)
return td
}
type Time struct {
ReadableTime *string `json:"readableTime,omitempty"`
Time *int `json:"time,omitempty"`
}
func (t Time) String() string {
return jsonStringer(t)
}