-
Notifications
You must be signed in to change notification settings - Fork 0
/
defaultclient.go
1544 lines (1494 loc) · 58.3 KB
/
defaultclient.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
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Package oba - One Bus Away Go Api https://onebusaway.org/
// Author: Seth T <[email protected]>
package oba
import (
"fmt"
"net/url"
"path"
)
const (
jsonPostFix = ".json"
agencyEndPoint = "agency/"
blockEndPoint = "block/"
routeEndPoint = "route/"
shapeEndPoint = "shape/"
stopEndPoint = "stop/"
tripEndPoint = "trip/"
agencyWithCoverageEndPoint = "agencies-with-coverage"
arrivalAndDepartureForStopEndPoint = "arrival-and-departure-for-stop/"
arrivalsAndDeparturesForStopEndPoint = "arrivals-and-departures-for-stop/"
cancelAlarmEndPoint = "cancel_alarm/"
currentTimeEndPoint = "current-time"
registerAlarmForArrivalAndDepartureAtStopEndPoint = "register-alarm-for-arrival-and-departure-at-stop/"
reportPoblemWithStopEndPoint = "report-problem-with-stop/"
reportPoblemWithTripEndPoint = "report-problem-with-trip/"
routeForAgencyEndPoint = "routes-for-agency/"
routeForLocationEndPoint = "routes-for-location"
scheduleForStopEndPoint = "schedule-for-stop/"
stopIDsForAgencyEndPoint = "stop-ids-for-agency/"
stopsForLocationEndPoint = "stops-for-location"
stopsForRouteEndPoint = "stops-for-route/"
tripDetailsEndPoint = "trip-details/"
tripForVehicleEndPoint = "trip-for-vehicle/"
tripsForLocationEndPoint = "trips-for-location"
tripsForRouteEndPoint = "trips-for-route/"
vehiclesForAgencyEndPoint = "vehicles-for-agency/"
routeIdsForAgencyEndPoint = "route-ids-for-agency/"
)
type DefaultClient struct {
baseURL *url.URL
apiKey string
}
// NewDefaultClient - instantiate a new instance of a Client
func NewDefaultClient(u *url.URL, apiKey string) *DefaultClient {
return &DefaultClient{baseURL: u, apiKey: apiKey}
}
func NewDefaultClientS(s string, apiKey string) *DefaultClient {
dc := &DefaultClient{apiKey: apiKey}
dc.setBaseURL(s)
return dc
}
func (c *DefaultClient) setBaseURL(b string) {
u, e := url.Parse(b)
if e != nil {
panic(e)
}
c.baseURL = u
}
// AgenciesWithCoverage - list all supported agencies along with the center of
// their coverage area
// http://developer.onebusaway.org/modules/onebusaway-application-modules/current/api/where/methods/agencies-with-coverage.html
//
// Method: agency-with-coverage
// Returns a list of all transit agencies currently supported by OneBusAway
// along with the center of their coverage area.
//
// Sample Request
// http://api.pugetsound.onebusaway.org/api/where/agencies-with-coverage.xml?key=TEST
//
// Sample Response
// <response>
// <version>2</version>
// <code>200</code>
// <text>OK</text>
// <currentTime>1270614730908</currentTime>
// <data class="listWithReferences">
// <references>...</references>
// <list>
// <agencyWithCoverage>
// <agencyId>3</agencyId>
// <lat>47.21278384769539</lat>
// <lon>-122.45624875362905</lon>
// <latSpan>0.3559410000000014</latSpan>
// <lonSpan>0.9080050000000028</lonSpan>
// </agencyWithCoverage>
// <agencyWithCoverage>...</agencyWithCoverage>
// </list>
// <limitExceeded>false</limitExceeded>
// </data>
// </response>
//
// Response
// The response has the following fields:
// agencyId - an agency id for the agency whose coverage is included.
// Should match an <agency/> element referenced in the
// <references/> section.
// lat and lon - indicates the center of the agency’s coverage area
// latSpan and lonSpan - indicate the height (lat) and width (lon) of the
// coverage bounding box for the agency.
func (c DefaultClient) AgenciesWithCoverage() ([]AgencyWithCoverage, error) {
data, err := c.getData(agencyWithCoverageEndPoint, "Agencies with Coverage", nil)
if err != nil {
return nil, err
}
agencies := data.References.Agencies.toAgencies()
awcs := data.List.toAgenciesWithCoverage(agencies)
return awcs, nil
}
// Agency - get details for a specific agency
// http://developer.onebusaway.org/modules/onebusaway-application-modules/current/api/where/methods/agency.html
//
// Method: agency
// Retrieve info for a specific transit agency identified by id
//
// Sample Request
// http://api.pugetsound.onebusaway.org/api/where/agency/1.xml?key=TEST
//
// Sample Response
// <response>
// <version>2</version>
// <code>200</code>
// <text>OK</text>
// <currentTime>1270614730908</currentTime>
// <data class="entryWithReferences">
// <references/>
// <entry class="agency">
// <id>1</id>
// <name>Metro Transit</name>
// <url>America/Los_Angeles</url>
// <timezone>America/Los_Angeles</timezone>
// <lang>en</lang>
// <phone>206-553-3000</phone>
// <disclaimer>Transit scheduling, geographic, and real-time data provided by permission of King County</disclaimer>
// </entry>
// </data>
// </response>
//
// Request Parameters
// id - the id of the agency, encoded directly in the URL:
// http://api.pugetsound.onebusaway.org/api/where/agency/[ID GOES HERE].xml
//
// Response
// For more details on the fields returned for an agency, see the documentation
// for the <agency/> element.
//
func (c DefaultClient) Agency(id string) (*Agency, error) {
entry, err := c.getEntry(fmt.Sprint(agencyEndPoint, id), "Agency", nil)
if err != nil {
return nil, err
}
agency := entry.ToAgency()
return agency, nil
}
// ArrivalAndDepartureForStop - details about a specific arrival/departure at a
// stop
// http://developer.onebusaway.org/modules/onebusaway-application-modules/current/api/where/methods/arrival-and-departure-for-stop.html
//
// Method: arrival-and-departure-for-stop
// Get info about a single arrival and departure for a stop
// Sample Request
// http://api.pugetsound.onebusaway.org/api/where/arrival-and-departure-for-stop/1_75403.xml?key=TEST&tripId=1_15551341&serviceDate=1291536000000&vehicleId=1_3521&stopSequence=42
//
// Sample Response
// <response>
// <version>2</version>
// <code>200</code>
// <text>OK</text>
// <currentTime>1270614730908</currentTime>
// <data class="entryWithReferences">
// <references>...</references>
// <entry class="arrivalAndDeparture">
// <!-- See documentation for the arrivalAndDeparture element, linked below -->
// </entry>
// </data>
// </response>
//
// Request Parameters
// id - the stop id, encoded directly in the URL:
// http://api.pugetsound.onebusaway.org/api/where/arrival-and-departure-for-stop/[ID GOES HERE].xml
// tripId - the trip id of the arriving transit vehicle
// serviceDate - the service date of the arriving transit vehicle
// vehicleId - the vehicle id of the arriving transit vehicle (optional)
// stopSequence - the stop sequence index of the stop in the transit vehicle’s trip
// time - by default, the method returns the status of the system
// right now. However, the system can also be queried at a
// specific time. This can be useful for testing. See
// timestamps for details on the format of the time parameter.
//
// The key here is uniquely identifying which arrival you are interested in.
// Typically, you would first make a call to arrivals-and-departures-for-stop to
// get a list of upcoming arrivals and departures at a particular stop. You can
// then use information from those results to specify a particular arrival. At
// minimum, you must specify the trip id and service date. Additionally, you are
// also encouraged to specify the vehicle id if available to help disambiguate
// between multiple vehicles serving the same trip instance. Finally, you are
// encouraged to specify the stop sequence. This helps in the situation when a
// vehicle visits a stop multiple times during a trip (it happens) plus there is
// performance benefit on the back-end as well.
//
// Response
// The method returns an <arrivalAndDeparture/> element as its content.
//
func (c DefaultClient) ArrivalAndDepartureForStop(id string, params map[string]string) (*ArrivalAndDeparture, error) {
data, err := c.getData(fmt.Sprint(arrivalAndDepartureForStopEndPoint, id), "Arrival and Departure for Stop", params)
if err != nil {
return nil, err
}
agencies := data.Agencies()
routes := data.Routes(agencies)
stops := data.Stops(routes)
trips := data.Trips()
situations := data.Situations()
aad := data.Entry.ToArrivalAndDeparture(situations, stops, trips)
return aad, nil
}
// ArrivalsAndDeparturesForStop - get current arrivals and departures for a stop
// http://developer.onebusaway.org/modules/onebusaway-application-modules/current/api/where/methods/arrivals-and-departures-for-stop.html
//
// Method: arrivals-and-departures-for-stop
// Get current arrivals and departures for a stop identified by id
//
// Sample Request
// http://api.pugetsound.onebusaway.org/api/where/arrivals-and-departures-for-stop/1_75403.xml?key=TEST
//
// Sample Response
// <response>
// <version>2</version>
// <code>200</code>
// <text>OK</text>
// <currentTime>1270614730908</currentTime>
// <data class="listWithReferences">
// <references>...</references>
// <entry class="stopWithArrivalsAndDepartures">
// <stopId>1_75403</stopId>
// <arrivalsAndDepartures>
// <arrivalAndDeparture>...</arrivalAndDeparture>
// <arrivalAndDeparture>...</arrivalAndDeparture>
// <arrivalAndDeparture>...</arrivalAndDeparture>
// </arrivalsAndDepartures>
// <nearbyStopIds>
// <string>1_75414</string>
// <string>...</string>
// </nearbyStopIds>
// </entry>
// </data>
// </response>
//
// Request Parameters
// id - the stop id, encoded directly in the URL:
// http://api.pugetsound.onebusaway.org/api/where/arrivals-and-departures-for-stop/[ID GOES HERE].xml
// minutesBefore=n - include vehicles having arrived or departed in the
// previous n minutes (default=5)
// minutesAfter=n - include vehicles arriving or departing in the next n
// minutes (default=35)
// time - by default, the method returns the status of the system
// right now. However, the system can also be queried at a
// specific time. This can be useful for testing. See
// timestamps for details on the format of the time parameter.
//
// Response
// The response is primarily composed of <arrivalAndDeparture/> elements, so see
// the element documentation for specific details.
// The nearby stop list is designed to capture stops that are very close by
// (like across the street) for quick navigation.
//
func (c DefaultClient) ArrivalsAndDeparturesForStop(id string, params map[string]string) (*StopWithArrivalsAndDepartures, error) {
data, err := c.getData(fmt.Sprint(arrivalsAndDeparturesForStopEndPoint, id), "Arrivals and Departures for Stop", params)
if err != nil {
return nil, err
}
agencies := data.Agencies()
routes := data.Routes(agencies)
stops := data.Stops(routes)
trips := data.Trips()
situations := data.Situations()
var swaad *StopWithArrivalsAndDepartures
if data.Entry != nil {
entry := data.Entry
var aads []ArrivalAndDeparture
if entry.ArrivalsAndDepartures != nil {
aads = data.Entry.ArrivalsAndDepartures.toArrivalAndDepartures(situations, stops, trips)
}
swaad = data.Entry.ToStopWithArrivalsAndDepartures(aads)
}
return swaad, nil
}
// Block - get block configuration for a specific block
// http://developer.onebusaway.org/modules/onebusaway-application-modules/current/api/where/methods/block.html
//
// Method: block
// Get details of a specific block by id\
//
// Sample Request
// <response>
// <version>2</version>
// <code>200</code>
// <text>OK</text>
// <currentTime>1391465493476</currentTime>
// <data class="entryWithReferences">
// <references />
// <entry class="block">
// <id>MTA NYCT_GH_A4-Sunday_D_GH_21000_BX12-15</id>
// <configurations>
// <blockConfiguration>
// <!-- See documentation for the blockConfiguration element, linked below -->
// </blockConfiguration>
// </configurations>
// </entry>
// </data>
// </response>
//
// Request Parameters
// id - the id of the block, encoded directly in the url:
// http://api.pugetsound.onebusaway.org/api/where/block/[ID GOES HERE].xml
//
// Response
// See details about the various properties of the <blockConfiguration/> element.
//
func (c DefaultClient) Block(id string) (*Block, error) {
entry, err := c.getEntry(fmt.Sprint(blockEndPoint, id), "Block", nil)
if err != nil {
return nil, err
}
block := entry.ToBlock()
return block, nil
}
// CancelAlarm - cancel a registered alarm
// http://developer.onebusaway.org/modules/onebusaway-application-modules/current/api/where/methods/cancel-alarm.html
//
// Method: cancel-alarm
// Cancel a registered alarm.
//
// Sample Request
// http://api.pugetsound.onebusaway.org/api/where/cancel_alarm/1_00859082-9b9d-4f72-a89f-c4be0e2cf01a.xml
//
// Sample Response
// <response>
// <version>2</version>
// <code>200</code>
// <text>OK</text>
// <currentTime>1270614730908</currentTime>
// <data>
// <references/>
// </data>
// </response>
//
// Request Parameters
// id - the alarm id is encoded directly in the URL
// http://api.pugetsound.onebusaway.org/api/where/cancel_alarm/[ID GOES HERE].xml
// The alarm id is returned in the call to
// register-alarm-for-arrival-and-departure-at-stop API method.
//
func (c DefaultClient) CancelAlarm(id string) error {
u := c.buildRequestURL(fmt.Sprint(cancelAlarmEndPoint, id), nil)
_, err := requestAndHandle(u, "Failed to Cancel Alarm for ID: ")
return err
}
// CurrentTime - retrieve the current system time
// http://developer.onebusaway.org/modules/onebusaway-application-modules/current/api/where/methods/current-time.html
//
// Method: current-time
// Retrieve the current system time
//
// Sample Request
// http://api.pugetsound.onebusaway.org/api/where/current-time.xml?key=TEST
//
// Sample Response
// <response>
// <version>2</version>
// <code>200</code>
// <text>OK</text>
// <currentTime>1270614730908</currentTime>
// <data class="time">
// <references/>
// <time>
// <time>1270614730908</time>
// <readableTime>2010-04-06T21:32:10-07:00</readableTime>
// </time>
// </data>
// </response>
//
// Response
// time - current system time as milliseconds since the Unix epoch
// readableTime - current system time in ISO 8601 format
//
func (c DefaultClient) CurrentTime() (*CurrentTime, error) {
entry, err := c.getEntry(currentTimeEndPoint, "CurrentTime", nil)
if err != nil {
return nil, err
}
ct := entry.ToCurrentTime()
return ct, nil
}
// RegisterAlarmForArrivalAndDepartureAtStop - register an alarm for an
// arrival-departure event
// http://developer.onebusaway.org/modules/onebusaway-application-modules/current/api/where/methods/register-alarm-for-arrival-and-departure-at-stop.html
//
// Method: register-alarm-for-arrival-and-departure-at-stop
// Register an alarm for a single arrival and departure at a stop, with a
// callback URL to be requested when the alarm is fired.
//
// Sample Request
// http://api.pugetsound.onebusaway.org/api/where/register-alarm-for-arrival-and-departure-at-stop/1_75403.xml?key=TEST&tripId=1_15551341&serviceDate=1291536000000&vehicleId=1_3521&stopSequence=42&alarmTimeOffset=120&url=http://host/callback_url
//
// Sample Response:
// <response>
// <version>2</version>
// <code>200</code>
// <currentTime>1318879898047</currentTime>
// <text>OK</text>
// <data class="entryWithReferences">
// <references/>
// <entry class="registeredAlarm">
// <alarmId>1_7deee53d-9eb5-4f6b-8623-8bff398fcd5b</alarmId>
// </entry>
// </data>
// </response>
//
// Request Parameters
// id, tripId, serviceDate, vehicleId, stopSequence - see discussion in
// arrival-and-departure-for-stop
// API method for discussion
// of how to specify a
// particular arrival or
// departure
// url - callback URL that will
// be requested when the
// alarm is fired
// alarmTimeOffset - time, in seconds, that
// controls how long before
// the arrival/departure
// the alarm will be fired.
// Default is zero.
// onArrival - set to true to indicate
// the alarm should be
// fired relative to
// vehicle arrival, false
// for departure. The
// default is false for
// departure.
// We provide an arrival-departure alarm callback mechanism that allows you to
// register an alarm for an arrival or departure event and received a callback
// in the form of a GET request to a URL you specify.
// In order to specify an alarm for something like "5 minutes before a bus
// departs, we provide the alarmTimeOffset which specifies when the alarm should
// be fired relative to the actual arrival or departure event. A value of 60
// indicates that the alarm should be fired 60 seconds before, while a value of
// -30 would be fired 30 seconds after.
// A note about scheduled vs real-time arrivals and departures: You can register
// alarms for trips where we don’t have any real-time data (aka a scheduled
// arrival and departure) and we will fire the alarm at the appropriate time.
// Things get a bit trickier when you’ve registered an alarm for a scheduled
// arrival and we suddenly have real-time for the trip after you’ve registered.
// In these situations, we will automatically link your alarm to the real-time
// arrival and departure.
//
// Response
// The response is the alarm id. Note that if you include #ALARM_ID# anywhere in
// your callback URL, we will automatically replace it with the id of the alarm
// being fired. This can be useful when you register multiple alarms and need to
// be able to distinguish between them.
// Also see the cancel-alarm API method, which also accepts the alarm id as an
// argument.
//
func (c DefaultClient) RegisterAlarmForArrivalAndDepartureAtStop(id string, params map[string]string) (*RegisteredAlarm, error) {
entry, err := c.getEntry(fmt.Sprint(registerAlarmForArrivalAndDepartureAtStopEndPoint, id),
"RegisterAlarmForArrivalAndDepartureAtStop",
params)
if err != nil {
return nil, err
}
ra := entry.ToRegisteredAlarm()
return ra, nil
}
// ReportProblemWithStop - submit a user-generated problem for a stop
// This is an assumption
func (c DefaultClient) ReportProblemWithStop(id string, params map[string]string) error {
_, err := c.getResponse(fmt.Sprint(reportPoblemWithStopEndPoint, id), "ReportProblemWithStop", params)
return err
}
// ReportProblemWithTrip - submit a user-generated problem for a trip
// http://developer.onebusaway.org/modules/onebusaway-application-modules/current/api/where/methods/report-problem-with-trip.html
//
// Method: report-problem-with-trip
// Submit a user-generated problem report for a particular trip. The reporting
// mechanism provides lots of fields that can be specified to give more context
// about the details of the problem (which trip, stop, vehicle, etc was
// involved), making it easier for a developer or transit agency staff to
// diagnose the problem. These reports feed into the problem reporting admin
// interface.
//
// Sample Request
// http://api.pugetsound.onebusaway.org/api/where/report-problem-with-trip/1_79430293.xml?key=TEST&serviceDate=1291536000000&vehicleId=1_3521&stopId=1_75403&code=vehicle_never_came
//
// Sample Response
// <response>
// <version>2</version>
// <code>200</code>
// <currentTime>1318879898047</currentTime>
// <text>OK</text>
// <data/>
// </response>
//
// Request Parameters
// tripId - the trip id, encoded directly in the URL:
// http://api.pugetsound.onebusaway.org/api/where/report-problem-with-trip/[ID GOES HERE].xml
// serviceDate - the service date of the trip
// vehicleId - the vehicle actively serving the trip
// stopId - a stop id indicating the stop where the user is experiencing
// the problem
// code - a string code identifying the nature of the problem
// vehicle_never_came
// vehicle_came_early - the vehicle arrived earlier
// than predicted
// vehicle_came_late - the vehicle arrived later
// than predicted
// wrong_headsign - the headsign reported by
// OneBusAway differed from the
// vehicle’s actual headsign
// vehicle_does_not_stop_here - the trip in question does
// not actually service the
// indicated stop
// other - catch-all for everythign else
// userComment - additional comment text supplied by the user describing the
// problem
// userOnVehicle - true/false to indicate if the user is on the transit vehicle
// experiencing the problem
// userVehicleNumber - the vehicle number, as reported by the user
// userLat - the reporting user’s current latitude
// userLon - the reporting user’s current longitude
// userLocationAccuracy - the reporting user’s location accuracy, in meters
//
// In general, everything but the trip id itself is optional, but generally
// speaking, providing more fields in the report will make it easier to diagnose
// the actual underlying problem. Note that while we record specific location
// information for the user, we do not store any identifying information for the
// user in order to make it hard to link the user to their location as some
// point in the future.
//
func (c DefaultClient) ReportProblemWithTrip(id string, params map[string]string) error {
_, err := c.getResponse(fmt.Sprint(reportPoblemWithTripEndPoint, id), "ReportProblemWithTrip", params)
return err
}
// RouteIdsForAgency - get a list of all route ids for an agency
// http://developer.onebusaway.org/modules/onebusaway-application-modules/current/api/where/methods/route-ids-for-agency.html
//
// Method: route-ids-for-agency
// Retrieve the list of all route ids for a particular agency.
//
// Sample Request
// http://api.pugetsound.onebusaway.org/api/where/route-ids-for-agency/40.xml?key=TEST
//
// Sample Respsone
// <response>
// <version>2</version>
// <code>200</code>
// <text>OK</text>
// <currentTime>1270614730908</currentTime>
// <data class="listWithReferences">
// <references/>
// <list>
// <string>40_510</string>
// <string>40_511</string>
// <string>40_513</string>
// <string>...</string>
// </list>
// <limitExceeded>false</limitExceeded>
// </data>
// </response>
//
// Request Parameters
// id - the id of the agency, encoded directly in the URL:
// http://api.pugetsound.onebusaway.org/api/where/route-ids-for-agency/[ID GOES HERE].xml?key=TEST
//
// Response
// Returns a list of all route ids for routes served by the specified agency.
// Note that <route/> elements for the referenced routes will NOT be included
// in the <references/> section, since there are potentially a large number of
// routes for an agency.
//
func (c DefaultClient) RouteIdsForAgency(id string) ([]string, error) {
u := c.buildRequestURL(fmt.Sprint(routeIdsForAgencyEndPoint, id), nil)
response, err := requestAndHandleAlt(u, "RouteIdsForAgency")
if err != nil {
return nil, err
}
rs := response.Data.List
return rs, nil
}
// Route - get details for a specific route
// http://developer.onebusaway.org/modules/onebusaway-application-modules/current/api/where/methods/route.html
//
// Method: route
// Retrieve info for a specific route by id.
//
// Sample Request
// http://api.pugetsound.onebusaway.org/api/where/route/1_100224.xml?key=TEST
//
// Sample Response
// <response>
// <version>2</version>
// <code>200</code>
// <currentTime>1461441898217</currentTime>
// <text>OK</text>
// <data class="entryWithReferences">
// <references>
// <agencies>
// <agency>
// <id>1</id>
// <name>Metro Transit</name>
// <url>http://metro.kingcounty.gov</url>
// <timezone>America/Los_Angeles</timezone>
// <lang>EN</lang>
// <phone>206-553-3000</phone>
// <privateService>false</privateService>
// </agency>
// </agencies>
// </references>
// <entry class="route">
// <id>1_100224</id>
// <shortName>44</shortName>
// <description>Ballard - Montlake</description>
// <type>3</type>
// <url>http://metro.kingcounty.gov/schedules/044/n0.html</url>
// <agencyId>1</agencyId>
// </entry>
// </data>
// </response>
//
// Request Parameters
// id - the id of the route, encoded directly in the URL:
// http://api.pugetsound.onebusaway.org/api/where/route/[ID GOES HERE].xml
//
// Response
// See details about the various properties of the <route/> element.
//
func (c DefaultClient) Route(id string) (*Route, error) {
data, err := c.getData(fmt.Sprint(routeEndPoint, id), "Route", nil)
if err != nil {
return nil, err
}
agencies := data.References.Agencies.toAgencies()
route := data.Entry.ToRoute(agencies)
return route, nil
}
// RoutesForAgency - get a list of all routes for an agency
// http://developer.onebusaway.org/modules/onebusaway-application-modules/current/api/where/methods/routes-for-agency.html
//
// Method: routes-for-agency
// Retrieve the list of all routes for a particular agency by id
//
// Sample Request
// http://api.pugetsound.onebusaway.org/api/where/routes-for-agency/1.xml?key=TEST
//
// Sample Response
// <response>
// <version>2</version>
// <code>200</code>
// <text>OK</text>
// <currentTime>1270614730908</currentTime>
// <data class="listWithReferences">
// <references/>
// <list>
// <route>
// <id>1_1</id>
// <shortName>1</shortName>
// <description>kinnear</description>
// <type>3</type>
// <url>http://metro.kingcounty.gov/tops/bus/schedules/s001_0_.html</url>
// <agencyId>1</agencyId>
// </route>
// ...
// </list>
// <limitExceeded>false</limitExceeded>
// </data>
// </response>
//
// Request Parameters
// id - the id of the agency, encoded directly in the URL:
// http://api.pugetsound.onebusaway.org/api/where/routes-for-agency/[ID GOES HERE].xml
//
// Response
// Returns a list of all route ids for routes served by the specified agency.
// See the full description for the <route/> element.
//
func (c DefaultClient) RoutesForAgency(id string) ([]Route, error) {
data, err := c.getData(fmt.Sprint(routeForAgencyEndPoint, id), "RoutesForAgency", nil)
if err != nil {
return nil, err
}
agencies := data.References.Agencies.toAgencies()
routes := data.List.toRoutes(agencies)
return routes, nil
}
// RoutesForLocation - search for routes near a location, optionally by route name
// http://developer.onebusaway.org/modules/onebusaway-application-modules/current/api/where/methods/routes-for-location.html
//
// Method: routes-for-location
// Search for routes near a specific location, optionally by name
//
// Sample Request
// http://api.pugetsound.onebusaway.org/api/where/routes-for-location.xml?key=TEST&lat=47.653435&lon=-122.305641
//
// Sample Response
// <response>
// <version>2</version>
// <code>200</code>
// <text>OK</text>
// <currentTime>1270614730908</currentTime>
// <data class="listWithReferences">
// <references>...</references>
// <list>
// <route>...</route>
// <!-- More routes -->
// </list>
// <limitExceeded>true</limitExceeded>
// </data>
// </response>
//
// Request Parameters
// lat - The latitude coordinate of the search center
// lon - The longitude coordinate of the search center
// radius - The search radius in meters (optional)
// latSpan/lonSpan - An alternative to radius to set the search bounding
// box (optional)
// query - A specific route short name to search for (optional)
// If you just specify a lat,lon search location, the routes-for-location method
// will just return nearby routes. If you specify an optional query parameter,
// we’ll search for nearby routes with the specified route short name. This is
// the primary method from going from a user-facing route name like “44” to the
// actual underlying route id unique to a route for a particular transit agency.
//
// Response
// The routes-for-location method returns a list result, so see additional
// documentation on controlling the number of elements returned and interpreting
// the results. The list contents are <route/> elements.
//
func (c DefaultClient) RoutesForLocation(params map[string]string) ([]Route, error) {
data, err := c.getData(routeForLocationEndPoint, "Routes for Location", params)
if err != nil {
return nil, err
}
agencies := data.References.Agencies.toAgencies()
routes := data.References.Routes.toRoutes(agencies)
return routes, nil
}
// ScheduleForStop - get the full schedule for a stop on a particular day
// http://developer.onebusaway.org/modules/onebusaway-application-modules/current/api/where/methods/schedule-for-stop.html
//
// Method: schedule-for-stop
// Retrieve the full schedule for a stop on a particular day
//
// Sample Request
// http://api.pugetsound.onebusaway.org/api/where/schedule-for-stop/1_75403.xml?key=TEST
//
// Sample Response
// <response>
// <version>2</version>
// <code>200</code>
// <text>OK</text>
// <currentTime>1270614730908</currentTime>
// <data class="entryWithReferences">
// <references>...</references>
// <entry class="stopSchedule">
// <date>1270623339481</date>
// <stopId>1_75403</stopId>
// <stopRouteSchedules>
// <stopRouteSchedule>
// <routeId>1_31</routeId>
// <stopRouteDirectionSchedules>
// <stopRouteDirectionSchedule>
// <tripHeadsign>Central Magnolia</tripHeadsign>
// <scheduleStopTimes>
// <scheduleStopTime>
// <arrivalTime>1270559769000</arrivalTime>
// <departureTime>1270559769000</departureTime>
// <serviceId>1_114-WEEK</serviceId>
// <tripId>1_11893408</tripId>
// </scheduleStopTime>
// <!-- More schduleStopTime entries... -->
// </scheduleStopTimes>
// </stopRouteDirectionSchedule>
// </stopRouteDirectionSchedules>
// <!-- More stopRouteDirectionSchedule entries -->
// </stopRouteSchedule>
// <!-- More stopRouteSchedule entries -->
// </stopRouteSchedules>
// <timeZone>America/Los_Angeles</timeZone>
// <stopCalendarDays>
// <stopCalendarDay>
// <date>1276239600000</date>
// <group>1</group>
// </stopCalendarDay>
// <!-- More stopCalendarDay entries -->
// </stopCalendarDays>
// </entry>
// </data>
// </response>
//
// Request Parameters
// id - the stop id to request the schedule for, encoded directly in the URL:
// http://api.pugetsound.onebusaway.org/api/where/schedule-for-stop/[ID GOES HERE].xml
// date - The date for which you want to request a schedule of the format YYYY-MM-DD (optional, defaults to current date)
//
// Response
// The response is pretty complex, so we’ll describe the details at a high-level
// along with references to the various elements in the response.
// The response can be considered in two parts. The first part lists specific
// arrivals and departures at a stop on a given date (<stopRouteSchedules/>
// section) while the second part lists which days the stop currently has
// service defined (the <stopCalendarDays/> section). By convention, we refer
// to the arrival and departure time details for a particular trip at a stop as
// a stop time.
//
// We break up the stop time listings in a couple of ways. First, we split the
// stop times by route (corresponds to each <stopRouteSchedule/> element). We
// next split the stop times for each route by direction of travel along the
// route (corresponds to each <stopRouteDirectionSchedule/> element). Most stops
// will serve just one direction of a particular route, but some stops will
// serve both directions, and it may be useful to present those listings
// separately. Each <stopRouteDirectionSchedule/> element has a tripHeadsign
// property that indicates the direction of travel.
//
// Finally we get down to the unit of a stop time, as represented by the
// <scheduleStopTime/> element. Each element has the following set of properties:
// arrivalTime - time in milliseconds since the Unix epoch that the transit
// vehicle will arrive
// departureTime - time in milliseconds since the Unix epoch that the transit
// vehicle will depart
// tripId - the id for the trip of the scheduled transit vehicle
// serviceId - the serviceId for the schedule trip (see the GTFS spec for
// more details
// In addition to all the <scheduleStopTime/> elements, the response also
// contains <stopCalendarDay/> elements which list out all the days that a
// particular stop has service. This element has the following properties:
// date - the date of service in milliseconds since the Unix epoch
// group - we provide a group id that groups <stopCalendarDay/> into
// collections of days with similar service. For example,
// Monday-Friday might all have the same schedule and the same group
// id as result, while Saturday and Sunday have a different weekend
// schedule, so they’d get their own group id.
// In addition to all the <scheduleStopTime/> elements, the main entry also has
// the following properties:
// date - the active date for the returned calendar
// stopId - the stop id for the requested stop, which can be used to access
// the <stop/> element in the <references/> section
// timeZone - the time-zone the stop is located in
//
func (c DefaultClient) ScheduleForStop(id string) (*StopSchedule, error) {
data, err := c.getData(fmt.Sprint(scheduleForStopEndPoint, id), "Schedule for Stop", nil)
if err != nil {
return nil, err
}
agencies := data.References.Agencies.toAgencies()
routes := data.References.Routes.toRoutes(agencies)
stops := data.References.Stops.toStops(routes)
ss := data.Entry.ToStopSchedule(stops)
ss.StopRouteSchedules = data.Entry.StopRouteSchedules.toStopRouteSchedules(routes)
return ss, nil
}
// Shape - get details for a specific shape (polyline drawn on a map)
// http://developer.onebusaway.org/modules/onebusaway-application-modules/current/api/where/methods/shape.html
//
// Method: shape
// Retrieve a shape (the path traveled by a transit vehicle) by id
//
// Sample Request
// http://api.pugetsound.onebusaway.org/api/where/shape/1_40046045.xml?key=TEST
//
// Sample Response
// <response>
// <version>2</version>
// <code>200</code>
// <text>OK</text>
// <currentTime>1270614730908</currentTime>
// <data class="entryWithReferences">
// <references/>
// <entry class="encodedPolyline">
// <points>ky`bHvwajVtDJ??|DL??fDH|@BnALVH??n@HhA\NF??DBZHzBhA??|@d@??nAl@fDdB??rBfAf@V??pCrA??
// hEvBf@N??p@Lp@F??j@DfA?xA???|A?pB@lCDtDElB???`@MVUTe@??FSFQNm@BG??
// DKHIRIfDgAbFwA|@_@x@q@b@a@j@}@??JQr@_B|AsDbA_CJWTs@??DQRgA????Ly@J_ABs@@u@?i@?YOwD??
// g@mJG_@Kc@??IUmAeCgAwBGs@???iI??CmO???M?aO???sF???cI???q@???g@?kF???cE???oA???sG???gH???cG@_@?aF?M??
// @{N???U???O??AeF@yH???oL???eN??rC???pC@??pC???D???jC???D???bC???`C???pC???pC???pCB??pCE??bCA??TFRR??
// nBkB??rCmC??bA_A??xCsC??rAuA??bD_D??nDiD??nDiD??PO^]??zCyC???sE???kG???_B???wB???qE???G?mE???sE??@aD???
// q@???sE???eFJm@??f@]fBcB??dAiA??x@y@??j@s@\a@??_@u@KUGQ??AeD???mACe@G_@Ka@??_@{@??a@}@cAcC??
// eA{B??{@eBEKEI??kBaE??oCI??AQGe@UwBSuB??E]?wD??BwF???oF??@mF???oF??DuF??DoF??@mF??@mF??@oF???gF??
// @uE???aC??@}A??@aF???qABuA?mA??AmC??^?pCDT????I?M?S?U@aA??@aF???YCi@Eg@CeA?a@??
// PgAPs@BMH_@VaA`@y@Zs@Ra@XmABQ??Fm@@}@@I?Q?_@B}FMW??@mC???q@@a@@c@D]Fi@Ne@??HUpAwC??Y_@??
// YS????WGkKQ??}B???m@A??{BC??eHC??iHG</points>
// <length>351</length>
// </entry>
// </data>
// </response>
//
// Request Parameters
// id - the shape id, encoded directly in the URL:
// http://api.pugetsound.onebusaway.org/api/where/shape/[ID GOES HERE].xml
//
// Response
// The path is returned as a <shape/> element with a points in the encoded
// polyline format defined for Google Maps.
//
func (c DefaultClient) Shape(id string) (*Shape, error) {
entry, err := c.getEntry(fmt.Sprint(shapeEndPoint, id), "Shape", nil)
if err != nil {
return nil, err
}
shape := entry.ToShape()
return shape, nil
}
// StipIDsForAgency - get a list of all stops for an agency
// http://developer.onebusaway.org/modules/onebusaway-application-modules/current/api/where/methods/stop-ids-for-agency.html
//
// Method: stops-ids-for-agency
// Retrieve the list of all stops for a particular agency by id
//
// Sample Request
// http://api.pugetsound.onebusaway.org/api/where/stop-ids-for-agency/40.xml?key=TEST
//
// Sample Response
// <response>
// <version>2</version>
// <code>200</code>
// <text>OK</text>
// <currentTime>1270614730908</currentTime>
// <data class="listWithReferences">
// <references/>
// <list>
// <string>40_C_1303</string>
// <string>40_C_1305</string>
// <string>40_C_1366</string>
// <string>...</string>
// </list>
// <limitExceeded>false</limitExceeded>
// </data>
// </response>
//
// Request Parameters
// id - the id of the agency, encoded directly in the URL:
// http://api.pugetsound.onebusaway.org/api/where/stop-ids-for-agency/[ID GOES HERE].xml
//
// Response
// Returns a list of all stop ids for stops served by the specified agency.
// Note that <stop/> elements for the referenced stops will NOT be included in
// the <references/> section, since there are potentially a large number of
// stops for an agency.
//
func (c DefaultClient) StopIDsForAgency(id string) ([]string, error) {
u := c.buildRequestURL(fmt.Sprint(stopIDsForAgencyEndPoint, id), nil)
response, err := requestAndHandleAlt(u, "Failed to get Stop IDs for Agency: ")
if err != nil {
return nil, err
}
ss := response.Data.List
return ss, nil
}
// Stop - get details for a specific stop
// http://developer.onebusaway.org/modules/onebusaway-application-modules/current/api/where/methods/stop.html
//
// Method: stop
// Retrieve info for a specific stop by id
//
// Sample Request
// http://api.pugetsound.onebusaway.org/api/where/stop/1_75403.xml?key=TEST
//
// Sample Response
// <response>
// <version>2</version>