-
Notifications
You must be signed in to change notification settings - Fork 0
/
tripsforroute.go
364 lines (324 loc) · 14.9 KB
/
tripsforroute.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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
package onebusaway
import (
"context"
"errors"
"fmt"
"net/http"
"net/url"
"github.com/OneBusAway/go-sdk/internal/apijson"
"github.com/OneBusAway/go-sdk/internal/apiquery"
"github.com/OneBusAway/go-sdk/internal/param"
"github.com/OneBusAway/go-sdk/internal/requestconfig"
"github.com/OneBusAway/go-sdk/option"
"github.com/OneBusAway/go-sdk/shared"
)
// TripsForRouteService contains methods and other services that help with
// interacting with the onebusaway-sdk API.
//
// Note, unlike clients, this service does not read variables from the environment
// automatically. You should not instantiate this service directly, and instead use
// the [NewTripsForRouteService] method instead.
type TripsForRouteService struct {
Options []option.RequestOption
}
// NewTripsForRouteService generates a new service that applies the given options
// to each request. These options are applied after the parent client's options (if
// there is one), and before any request-specific options.
func NewTripsForRouteService(opts ...option.RequestOption) (r *TripsForRouteService) {
r = &TripsForRouteService{}
r.Options = opts
return
}
// Search for active trips for a specific route.
func (r *TripsForRouteService) List(ctx context.Context, routeID string, query TripsForRouteListParams, opts ...option.RequestOption) (res *TripsForRouteListResponse, err error) {
opts = append(r.Options[:], opts...)
if routeID == "" {
err = errors.New("missing required routeID parameter")
return
}
path := fmt.Sprintf("api/where/trips-for-route/%s.json", routeID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, query, &res, opts...)
return
}
type TripsForRouteListResponse struct {
Data TripsForRouteListResponseData `json:"data,required"`
JSON tripsForRouteListResponseJSON `json:"-"`
shared.ResponseWrapper
}
// tripsForRouteListResponseJSON contains the JSON metadata for the struct
// [TripsForRouteListResponse]
type tripsForRouteListResponseJSON struct {
Data apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *TripsForRouteListResponse) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r tripsForRouteListResponseJSON) RawJSON() string {
return r.raw
}
type TripsForRouteListResponseData struct {
LimitExceeded bool `json:"limitExceeded,required"`
List []TripsForRouteListResponseDataList `json:"list,required"`
References shared.References `json:"references,required"`
JSON tripsForRouteListResponseDataJSON `json:"-"`
}
// tripsForRouteListResponseDataJSON contains the JSON metadata for the struct
// [TripsForRouteListResponseData]
type tripsForRouteListResponseDataJSON struct {
LimitExceeded apijson.Field
List apijson.Field
References apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *TripsForRouteListResponseData) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r tripsForRouteListResponseDataJSON) RawJSON() string {
return r.raw
}
type TripsForRouteListResponseDataList struct {
Schedule TripsForRouteListResponseDataListSchedule `json:"schedule,required"`
Status TripsForRouteListResponseDataListStatus `json:"status,required"`
TripID string `json:"tripId,required"`
Frequency string `json:"frequency,nullable"`
ServiceDate int64 `json:"serviceDate"`
SituationIDs []string `json:"situationIds"`
JSON tripsForRouteListResponseDataListJSON `json:"-"`
}
// tripsForRouteListResponseDataListJSON contains the JSON metadata for the struct
// [TripsForRouteListResponseDataList]
type tripsForRouteListResponseDataListJSON struct {
Schedule apijson.Field
Status apijson.Field
TripID apijson.Field
Frequency apijson.Field
ServiceDate apijson.Field
SituationIDs apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *TripsForRouteListResponseDataList) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r tripsForRouteListResponseDataListJSON) RawJSON() string {
return r.raw
}
type TripsForRouteListResponseDataListSchedule struct {
NextTripID string `json:"nextTripId,required"`
PreviousTripID string `json:"previousTripId,required"`
StopTimes []TripsForRouteListResponseDataListScheduleStopTime `json:"stopTimes,required"`
TimeZone string `json:"timeZone,required"`
Frequency string `json:"frequency,nullable"`
JSON tripsForRouteListResponseDataListScheduleJSON `json:"-"`
}
// tripsForRouteListResponseDataListScheduleJSON contains the JSON metadata for the
// struct [TripsForRouteListResponseDataListSchedule]
type tripsForRouteListResponseDataListScheduleJSON struct {
NextTripID apijson.Field
PreviousTripID apijson.Field
StopTimes apijson.Field
TimeZone apijson.Field
Frequency apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *TripsForRouteListResponseDataListSchedule) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r tripsForRouteListResponseDataListScheduleJSON) RawJSON() string {
return r.raw
}
type TripsForRouteListResponseDataListScheduleStopTime struct {
ArrivalTime int64 `json:"arrivalTime"`
DepartureTime int64 `json:"departureTime"`
DistanceAlongTrip float64 `json:"distanceAlongTrip"`
HistoricalOccupancy string `json:"historicalOccupancy"`
StopHeadsign string `json:"stopHeadsign"`
StopID string `json:"stopId"`
JSON tripsForRouteListResponseDataListScheduleStopTimeJSON `json:"-"`
}
// tripsForRouteListResponseDataListScheduleStopTimeJSON contains the JSON metadata
// for the struct [TripsForRouteListResponseDataListScheduleStopTime]
type tripsForRouteListResponseDataListScheduleStopTimeJSON struct {
ArrivalTime apijson.Field
DepartureTime apijson.Field
DistanceAlongTrip apijson.Field
HistoricalOccupancy apijson.Field
StopHeadsign apijson.Field
StopID apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *TripsForRouteListResponseDataListScheduleStopTime) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r tripsForRouteListResponseDataListScheduleStopTimeJSON) RawJSON() string {
return r.raw
}
type TripsForRouteListResponseDataListStatus struct {
// Trip ID of the trip the vehicle is actively serving.
ActiveTripID string `json:"activeTripId,required"`
// Index of the active trip into the sequence of trips for the active block.
BlockTripSequence int64 `json:"blockTripSequence,required"`
// ID of the closest stop to the current location of the transit vehicle.
ClosestStop string `json:"closestStop,required"`
// Distance, in meters, the transit vehicle has progressed along the active trip.
DistanceAlongTrip float64 `json:"distanceAlongTrip,required"`
// Last known distance along the trip received in real-time from the transit
// vehicle.
LastKnownDistanceAlongTrip float64 `json:"lastKnownDistanceAlongTrip,required"`
// Timestamp of the last known real-time location update from the transit vehicle.
LastLocationUpdateTime int64 `json:"lastLocationUpdateTime,required"`
// Timestamp of the last known real-time update from the transit vehicle.
LastUpdateTime int64 `json:"lastUpdateTime,required"`
// Capacity of the transit vehicle in terms of occupancy.
OccupancyCapacity int64 `json:"occupancyCapacity,required"`
// Current count of occupants in the transit vehicle.
OccupancyCount int64 `json:"occupancyCount,required"`
// Current occupancy status of the transit vehicle.
OccupancyStatus string `json:"occupancyStatus,required"`
// Current journey phase of the trip.
Phase string `json:"phase,required"`
// Indicates if real-time arrival info is available for this trip.
Predicted bool `json:"predicted,required"`
// Deviation from the schedule in seconds (positive for late, negative for early).
ScheduleDeviation int64 `json:"scheduleDeviation,required"`
// Time, in milliseconds since the Unix epoch, of midnight for the start of the
// service date for the trip.
ServiceDate int64 `json:"serviceDate,required"`
// Current status modifiers for the trip.
Status string `json:"status,required"`
// Total length of the trip, in meters.
TotalDistanceAlongTrip float64 `json:"totalDistanceAlongTrip,required"`
// Time offset from the closest stop to the current position of the transit vehicle
// (in seconds).
ClosestStopTimeOffset int64 `json:"closestStopTimeOffset"`
// Information about frequency-based scheduling, if applicable to the trip.
Frequency string `json:"frequency"`
// Last known location of the transit vehicle.
LastKnownLocation TripsForRouteListResponseDataListStatusLastKnownLocation `json:"lastKnownLocation"`
// Last known orientation value received in real-time from the transit vehicle.
LastKnownOrientation float64 `json:"lastKnownOrientation"`
// ID of the next stop the transit vehicle is scheduled to arrive at.
NextStop string `json:"nextStop"`
// Time offset from the next stop to the current position of the transit vehicle
// (in seconds).
NextStopTimeOffset int64 `json:"nextStopTimeOffset"`
// Orientation of the transit vehicle, represented as an angle in degrees.
Orientation float64 `json:"orientation"`
// Current position of the transit vehicle.
Position TripsForRouteListResponseDataListStatusPosition `json:"position"`
// Distance, in meters, the transit vehicle is scheduled to have progressed along
// the active trip.
ScheduledDistanceAlongTrip float64 `json:"scheduledDistanceAlongTrip"`
// References to situation elements (if any) applicable to this trip.
SituationIDs []string `json:"situationIds"`
// ID of the transit vehicle currently serving the trip.
VehicleID string `json:"vehicleId"`
JSON tripsForRouteListResponseDataListStatusJSON `json:"-"`
}
// tripsForRouteListResponseDataListStatusJSON contains the JSON metadata for the
// struct [TripsForRouteListResponseDataListStatus]
type tripsForRouteListResponseDataListStatusJSON struct {
ActiveTripID apijson.Field
BlockTripSequence apijson.Field
ClosestStop apijson.Field
DistanceAlongTrip apijson.Field
LastKnownDistanceAlongTrip apijson.Field
LastLocationUpdateTime apijson.Field
LastUpdateTime apijson.Field
OccupancyCapacity apijson.Field
OccupancyCount apijson.Field
OccupancyStatus apijson.Field
Phase apijson.Field
Predicted apijson.Field
ScheduleDeviation apijson.Field
ServiceDate apijson.Field
Status apijson.Field
TotalDistanceAlongTrip apijson.Field
ClosestStopTimeOffset apijson.Field
Frequency apijson.Field
LastKnownLocation apijson.Field
LastKnownOrientation apijson.Field
NextStop apijson.Field
NextStopTimeOffset apijson.Field
Orientation apijson.Field
Position apijson.Field
ScheduledDistanceAlongTrip apijson.Field
SituationIDs apijson.Field
VehicleID apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *TripsForRouteListResponseDataListStatus) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r tripsForRouteListResponseDataListStatusJSON) RawJSON() string {
return r.raw
}
// Last known location of the transit vehicle.
type TripsForRouteListResponseDataListStatusLastKnownLocation struct {
// Latitude of the last known location of the transit vehicle.
Lat float64 `json:"lat"`
// Longitude of the last known location of the transit vehicle.
Lon float64 `json:"lon"`
JSON tripsForRouteListResponseDataListStatusLastKnownLocationJSON `json:"-"`
}
// tripsForRouteListResponseDataListStatusLastKnownLocationJSON contains the JSON
// metadata for the struct
// [TripsForRouteListResponseDataListStatusLastKnownLocation]
type tripsForRouteListResponseDataListStatusLastKnownLocationJSON struct {
Lat apijson.Field
Lon apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *TripsForRouteListResponseDataListStatusLastKnownLocation) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r tripsForRouteListResponseDataListStatusLastKnownLocationJSON) RawJSON() string {
return r.raw
}
// Current position of the transit vehicle.
type TripsForRouteListResponseDataListStatusPosition struct {
// Latitude of the current position of the transit vehicle.
Lat float64 `json:"lat"`
// Longitude of the current position of the transit vehicle.
Lon float64 `json:"lon"`
JSON tripsForRouteListResponseDataListStatusPositionJSON `json:"-"`
}
// tripsForRouteListResponseDataListStatusPositionJSON contains the JSON metadata
// for the struct [TripsForRouteListResponseDataListStatusPosition]
type tripsForRouteListResponseDataListStatusPositionJSON struct {
Lat apijson.Field
Lon apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *TripsForRouteListResponseDataListStatusPosition) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r tripsForRouteListResponseDataListStatusPositionJSON) RawJSON() string {
return r.raw
}
type TripsForRouteListParams struct {
// Determine whether full schedule elements are included. Defaults to false.
IncludeSchedule param.Field[bool] `query:"includeSchedule"`
// Determine whether full tripStatus elements with real-time information are
// included. Defaults to false.
IncludeStatus param.Field[bool] `query:"includeStatus"`
// Query the system at a specific time. Useful for testing.
Time param.Field[int64] `query:"time"`
}
// URLQuery serializes [TripsForRouteListParams]'s query parameters as
// `url.Values`.
func (r TripsForRouteListParams) URLQuery() (v url.Values) {
return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
ArrayFormat: apiquery.ArrayQueryFormatRepeat,
NestedFormat: apiquery.NestedQueryFormatBrackets,
})
}