-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnps.go
2264 lines (2114 loc) · 79.8 KB
/
nps.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 nps
import (
"encoding/json"
"fmt"
"io"
"net/http"
"reflect"
"strings"
"time"
)
/*
Go client for the National Park Service API.
https://www.nps.gov/subjects/developer/api-documentation.htm
*/
type NpsApi interface {
GetActivities(id, q string, limit, start int, sort string) (*ActivityResponse, error)
GetActivityParks(id []string, q string, limit, start int, sort string) (*ActivityParkResponse, error)
GetAlerts(parkCode, stateCode []string, q string, limit, start int) (*AlertResponse, error)
GetAmenities(id []string, q string, limit, start int) (*AmenityResponse, error)
GetAmenitiesParksPlaces(parkCode, id []string, q string, limit, start int, sort string) (*AmenityParkPlaceResponse, error)
GetAmenitiesParksVisitorCenters(parkCode, id, q string, limit, start int, sort []string) (*AmenityParkVisitorCenterResponse, error)
GetArticles(parkCode, stateCode []string, q string, limit, start int) (*ArticleData, error)
GetCampgrounds(parkCode, stateCode []string, q string, limit, start int, sort []string) (*CampgroundData, error)
GetEvents(parkCode, stateCode, organization, subject, portal, tagsAll, tagsOne, tagsNone []string, dateStart, dateEnd string, eventType []string, id, q string, pageSize, pageNumber int, expandRecurring bool) (*EventResponse, error)
GetFeesPasses(parkCode, stateCode []string, q string, start, limit int, sort []string) (*FeePassResponse, error)
GetLessonPlans(parkCode, stateCode []string, q string, start, limit int, sort []string) (*LessonPlanResponse, error)
GetParkBoundaries(sitecode string) (*MapdataParkboundaryResponse, error)
GetMultimediaAudio(parkCode, stateCode []string, q string, start, limit int) (*MultimediaAudioResponse, error)
GetMultimediaGalleries(parkCode, stateCode []string, q string, start, limit int) (*MultimediaGalleriesResponse, error)
GetMultimediaGalleriesAssets(id, galleryId string, parkCode, stateCode []string, q string, start, limit int) (*MultimediaGalleriesAssetsResponse, error)
GetMultimediaVideos(parkCode, stateCode []string, q string, start, limit int) (*MultimediaVideosResponse, error)
GetNewsReleases(parkCode, stateCode []string, q string, limit, start int, sort []string) (*NewsReleaseResponse, error)
GetParkinglots(parkCode, stateCode []string, q string, start, limit int) (*ParkinglotResponse, error)
GetParks(parkCode, stateCode []string, start, limit int, q string, sort []string) (*ParkResponse, error)
GetPassportStampLocations(parkCode, stateCode []string, q string, limit, start int) (*PassportStampLocationResponse, error)
GetPeople(parkCode, stateCode []string, q string, limit, start int) (*PersonResponse, error)
GetPlaces(parkCode, stateCode []string, q string, limit, start int) (*PlaceResponse, error)
GetRoadEvents(parkCode, eventType string) (*RoadEventResponse, error)
GetThingsToDo(id, parkCode, stateCode, q string, limit, start int, sort []string) (*ThingsToDoResponse, error)
GetTopics(id, q string, limit, start int, sort string) (*TopicResponse, error)
GetTopicParks(id []string, q string, limit, start int, sort string) (*TopicParkResponse, error)
GetTours(id, parkCode, stateCode []string, q string, limit, start int, sort []string) (*TourResponse, error)
GetVisitorCenters(parkCode, stateCode []string, q string, limit, start int, sort []string) (*VisitorCenterResponse, error)
GetWebcams(id string, parkCode, stateCode []string, q string, limit, start int) (*WebcamResponse, error)
}
const (
BASE_URL = "https://developer.nps.gov/api/v1"
)
type npsApi struct {
BaseURL string
ApiKey string
Client *http.Client
}
func NewNpsApi(apiKey string) NpsApi {
return &npsApi{
ApiKey: apiKey,
BaseURL: BASE_URL,
Client: &http.Client{
Timeout: time.Second * 30,
},
}
}
func (api *npsApi) BuildRequestURL(endpoint string, params map[string]interface{}) string {
var sb strings.Builder
sb.WriteString(api.BaseURL)
sb.WriteString(endpoint)
first := true
for key, value := range params {
if (reflect.ValueOf(value).Kind() == reflect.String && value != "") ||
(reflect.ValueOf(value).Kind() == reflect.Int && value != 0) {
if first {
sb.WriteString("?")
first = false
} else {
sb.WriteString("&")
}
sb.WriteString(key)
sb.WriteString("=")
sb.WriteString(fmt.Sprintf("%v", value))
}
}
if api.ApiKey != "" {
if first {
sb.WriteString("?")
} else {
sb.WriteString("&")
}
sb.WriteString("api_key=")
sb.WriteString(api.ApiKey)
}
return sb.String()
}
// Activity represents an activity in the National Park Service.
type Activity struct {
ID string `json:"id"`
Name string `json:"name"`
}
// ActivityResponse represents the response from the /activities endpoint.
type ActivityResponse struct {
Total string `json:"total"`
Data []Activity `json:"data"`
Limit string `json:"limit"`
Start string `json:"start"`
}
// GetActivities makes a GET request to the /activities endpoint and returns the activities.
func (api *npsApi) GetActivities(id, q string, limit, start int, sort string) (*ActivityResponse, error) {
params := map[string]interface{}{
"id": id,
"q": q,
"sort": sort,
"limit": limit,
"start": start,
}
url := api.BuildRequestURL("/activities", params)
resp, err := api.Client.Get(url)
if err != nil {
return nil, err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
bodyBytes, err := io.ReadAll(resp.Body)
if err != nil {
return nil, fmt.Errorf("unexpected status code: %d. Error reading body: %v", resp.StatusCode, err)
}
return nil, fmt.Errorf("unexpected status code: %d. Response body: %s", resp.StatusCode, string(bodyBytes))
}
var activitiesResponse ActivityResponse
if err := json.NewDecoder(resp.Body).Decode(&activitiesResponse); err != nil {
return nil, err
}
return &activitiesResponse, nil
}
// ActivityPark represents a park related to an activity in the National Park Service.
type ActivityParkData struct {
ID string `json:"id"`
Name string `json:"name"`
Parks []struct {
States string `json:"states"`
FullName string `json:"fullName"`
URL string `json:"url"`
ParkCode string `json:"parkCode"`
Designation string `json:"designation"`
Name string `json:"name"`
} `json:"parks"`
}
// ActivityParkResponse represents the response from the /activities/parks endpoint.
type ActivityParkResponse struct {
Total string `json:"total"`
Data []ActivityParkData `json:"data"`
Limit string `json:"limit"`
Start string `json:"start"`
}
// GetActivityParks makes a GET request to the /activities/parks endpoint and returns the parks related to the activities.
func (api *npsApi) GetActivityParks(id []string, q string, limit, start int, sort string) (*ActivityParkResponse, error) {
params := map[string]interface{}{
"id": strings.Join(id, ","),
"q": q,
"sort": sort,
"limit": limit,
"start": start,
}
url := api.BuildRequestURL("/activities/parks", params)
resp, err := api.Client.Get(url)
if err != nil {
return nil, err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
bodyBytes, err := io.ReadAll(resp.Body)
if err != nil {
return nil, fmt.Errorf("unexpected status code: %d. Error reading body: %v", resp.StatusCode, err)
}
return nil, fmt.Errorf("unexpected status code: %d. Response body: %s", resp.StatusCode, string(bodyBytes))
}
var activityParkResponse ActivityParkResponse
if err := json.NewDecoder(resp.Body).Decode(&activityParkResponse); err != nil {
return nil, err
}
return &activityParkResponse, nil
}
// Alert represents an alert in the National Park Service.
type Alert struct {
Category string `json:"category"`
Description string `json:"description"`
ID string `json:"id"`
ParkCode string `json:"parkCode"`
Title string `json:"title"`
URL string `json:"url"`
LastIndexedDate string `json:"lastIndexedDate"`
RelatedRoadEvents []struct {
Title string `json:"title"`
ID string `json:"id"`
Type string `json:"type"`
URL string `json:"url"`
} `json:"relatedRoadEvents"`
}
// AlertResponse represents the response from the /alerts endpoint.
type AlertResponse struct {
Total string `json:"total"`
Data []Alert `json:"data"`
Limit string `json:"limit"`
Start string `json:"start"`
}
// GetAlerts makes a GET request to the /alerts endpoint and returns the alerts.
func (api *npsApi) GetAlerts(parkCode, stateCode []string, q string, limit, start int) (*AlertResponse, error) {
params := map[string]interface{}{
"parkCode": strings.Join(parkCode, ","),
"stateCode": strings.Join(stateCode, ","),
"q": q,
"limit": limit,
"start": start,
}
url := api.BuildRequestURL("/alerts", params)
resp, err := api.Client.Get(url)
if err != nil {
return nil, err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
bodyBytes, err := io.ReadAll(resp.Body)
if err != nil {
return nil, fmt.Errorf("unexpected status code: %d. Error reading body: %v", resp.StatusCode, err)
}
return nil, fmt.Errorf("unexpected status code: %d. Response body: %s", resp.StatusCode, string(bodyBytes))
}
var alertsResponse AlertResponse
if err := json.NewDecoder(resp.Body).Decode(&alertsResponse); err != nil {
return nil, err
}
return &alertsResponse, nil
}
// Amenity represents an amenity in the National Park Service.
type Amenity struct {
ID string `json:"id"`
Name string `json:"name"`
}
// AmenityResponse represents the response from the /amenities endpoint.
type AmenityResponse struct {
Total string `json:"total"`
Data []Amenity `json:"data"`
Limit string `json:"limit"`
Start string `json:"start"`
}
// GetAmenities makes a GET request to the /amenities endpoint and returns the amenities.
func (api *npsApi) GetAmenities(id []string, q string, limit, start int) (*AmenityResponse, error) {
params := map[string]interface{}{
"id": strings.Join(id, ","),
"q": q,
"limit": limit,
"start": start,
}
url := api.BuildRequestURL("/amenities", params)
resp, err := api.Client.Get(url)
if err != nil {
return nil, err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
bodyBytes, err := io.ReadAll(resp.Body)
if err != nil {
return nil, fmt.Errorf("unexpected status code: %d. Error reading body: %v", resp.StatusCode, err)
}
return nil, fmt.Errorf("unexpected status code: %d. Response body: %s", resp.StatusCode, string(bodyBytes))
}
var amenitiesResponse AmenityResponse
if err := json.NewDecoder(resp.Body).Decode(&amenitiesResponse); err != nil {
return nil, err
}
return &amenitiesResponse, nil
}
// Place represents a place in the National Park Service.
type AmenityParkPlace struct {
ID string `json:"id"`
Name string `json:"name"`
Parks []struct {
States string `json:"states"`
ParkCode string `json:"parkCode"`
Designation string `json:"designation"`
FullName string `json:"fullName"`
Places []struct {
IsManagedByNps string `json:"isManagedByNps"`
AudioDescription string `json:"audioDescription"`
Multimedia []struct {
Title string `json:"title"`
ID string `json:"id"`
Type string `json:"type"`
Url string `json:"url"`
} `json:"multimedia"`
Latitude string `json:"latitude"`
ManagedByOrg string `json:"managedByOrg"`
Url string `json:"url"`
Longitude string `json:"longitude"`
BodyText string `json:"bodyText"`
GeometryPoiId string `json:"geometryPoiId"`
NpmapId string `json:"npmapId"`
RelatedOrganizations []string `json:"relatedOrganizations"`
Amenities []string `json:"amenities"`
Title string `json:"title"`
Images []string `json:"images"`
ListingDescription string `json:"listingDescription"`
IsOpenToPublic string `json:"isOpenToPublic"`
Tags []string `json:"tags"`
ManagedByUrl string `json:"managedByUrl"`
QuickFacts []string `json:"quickFacts"`
LatLong string `json:"latLong"`
ID string `json:"id"`
RelatedParks []struct {
States string `json:"states"`
ParkCode string `json:"parkCode"`
Designation string `json:"designation"`
FullName string `json:"fullName"`
Url string `json:"url"`
Name string `json:"name"`
} `json:"relatedParks"`
} `json:"places"`
URL string `json:"url"`
Name string `json:"name"`
} `json:"parks"`
}
// AmenityParkPlaceResponse represents the response from the /amenities/parksplaces endpoint.
type AmenityParkPlaceResponse struct {
Total string `json:"total"`
Data [][]AmenityParkPlace `json:"data"`
Limit string `json:"limit"`
Start string `json:"start"`
}
// GetAmenitiesParksPlaces makes a GET request to the /amenities/parksplaces endpoint and returns the parks with places related to the amenities.
func (api *npsApi) GetAmenitiesParksPlaces(parkCode, id []string, q string, limit, start int, sort string) (*AmenityParkPlaceResponse, error) {
params := map[string]interface{}{
"parkCode": strings.Join(parkCode, ","),
"id": strings.Join(id, ","),
"q": q,
"sort": sort,
"limit": limit,
"start": start,
}
url := api.BuildRequestURL("/amenities/parksplaces", params)
resp, err := api.Client.Get(url)
if err != nil {
return nil, err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
bodyBytes, err := io.ReadAll(resp.Body)
if err != nil {
return nil, fmt.Errorf("unexpected status code: %d. Error reading body: %v", resp.StatusCode, err)
}
return nil, fmt.Errorf("unexpected status code: %d. Response body: %s", resp.StatusCode, string(bodyBytes))
}
var amenityParkPlaceResponse AmenityParkPlaceResponse
if err := json.NewDecoder(resp.Body).Decode(&amenityParkPlaceResponse); err != nil {
return nil, err
}
return &amenityParkPlaceResponse, nil
}
// VisitorCenter represents a visitor center in the National Park Service.
type AmenityParkVisitorCenterData struct {
ID string `json:"id"`
Name string `json:"name"`
Parks []struct {
States string `json:"states"`
ParkCode string `json:"parkCode"`
Designation string `json:"designation"`
VisitorCenters []struct {
URL string `json:"url"`
ID string `json:"id"`
Name string `json:"name"`
} `json:"visitorcenters"`
FullName string `json:"fullName"`
URL string `json:"url"`
Name string `json:"Name"`
} `json:"parks"`
}
// AmenityParkVisitorCenterResponse represents the response from the /amenities/parksvisitorcenters endpoint.
type AmenityParkVisitorCenterResponse struct {
Total string `json:"total"`
Data [][]AmenityParkVisitorCenterData `json:"data"`
Limit string `json:"limit"`
Start string `json:"start"`
}
// GetAmenitiesParksVisitorCenters makes a GET request to the /amenities/parksvisitorcenters endpoint and returns the parks with visitor centers related to the amenities.
func (api *npsApi) GetAmenitiesParksVisitorCenters(parkCode, id, q string, limit, start int, sort []string) (*AmenityParkVisitorCenterResponse, error) {
params := map[string]interface{}{
"parkCode": parkCode,
"id": id,
"q": q,
"sort": strings.Join(sort, ","),
"limit": limit,
"start": start,
}
url := api.BuildRequestURL("/amenities/parksvisitorcenters", params)
resp, err := api.Client.Get(url)
if err != nil {
return nil, err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
bodyBytes, err := io.ReadAll(resp.Body)
if err != nil {
return nil, fmt.Errorf("unexpected status code: %d. Error reading body: %v", resp.StatusCode, err)
}
return nil, fmt.Errorf("unexpected status code: %d. Response body: %s", resp.StatusCode, string(bodyBytes))
}
var amenityParkVisitorCenterResponse AmenityParkVisitorCenterResponse
if err := json.NewDecoder(resp.Body).Decode(&amenityParkVisitorCenterResponse); err != nil {
return nil, err
}
return &amenityParkVisitorCenterResponse, nil
}
// Article represents an article in the National Park Service.
type Article struct {
URL string `json:"url"`
Title string `json:"title"`
ID string `json:"id"`
GeometryPoiId string `json:"geometryPoiId"`
ListingDescription string `json:"listingDescription"`
ListingImage struct {
URL string `json:"url"`
Credit string `json:"credit"`
AltText string `json:"altText"`
Title string `json:"title"`
Description string `json:"description"`
Caption string `json:"caption"`
} `json:"listingImage"`
RelatedParks []struct {
States string `json:"states"`
ParkCode string `json:"parkCode"`
Designation string `json:"designation"`
FullName string `json:"fullName"`
URL string `json:"url"`
Name string `json:"name"`
} `json:"relatedParks"`
Latitude float64 `json:"latitude"`
Longitude float64 `json:"longitude"`
LatLong string `json:"latLong"`
}
// ArticleData represents the data in the response from the /articles endpoint.
type ArticleData struct {
Total string `json:"total"`
Data []Article `json:"data"`
Limit string `json:"limit"`
Start string `json:"start"`
}
// GetArticles makes a GET request to the /articles endpoint and returns the articles.
func (api *npsApi) GetArticles(parkCode, stateCode []string, q string, limit, start int) (*ArticleData, error) {
params := map[string]interface{}{
"parkCode": strings.Join(parkCode, ","),
"stateCode": strings.Join(stateCode, ","),
"q": q,
"limit": limit,
"start": start,
}
url := api.BuildRequestURL("/articles", params)
resp, err := api.Client.Get(url)
if err != nil {
return nil, err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
bodyBytes, err := io.ReadAll(resp.Body)
if err != nil {
return nil, fmt.Errorf("unexpected status code: %d. Error reading body: %v", resp.StatusCode, err)
}
return nil, fmt.Errorf("unexpected status code: %d. Response body: %s", resp.StatusCode, string(bodyBytes))
}
var articleData ArticleData
if err := json.NewDecoder(resp.Body).Decode(&articleData); err != nil {
return nil, err
}
return &articleData, nil
}
// Campground represents a campground in the National Park Service.
type Campground struct {
ID string `json:"id"`
URL string `json:"url"`
Name string `json:"name"`
ParkCode string `json:"parkCode"`
Description string `json:"description"`
Latitude string `json:"latitude"`
Longitude string `json:"longitude"`
LatLong string `json:"latLong"`
AudioDescription string `json:"audioDescription"`
IsPassportStampLocation string `json:"isPassportStampLocation"`
PassportStampLocationDescription string `json:"passportStampLocationDescription"`
PassportStampImages []interface{} `json:"passportStampImages"`
GeometryPoiId string `json:"geometryPoiId"`
ReservationInfo string `json:"reservationInfo"`
ReservationUrl string `json:"reservationUrl"`
Regulationsurl string `json:"regulationsurl"`
RegulationsOverview string `json:"regulationsOverview"`
Amenities struct {
TrashRecyclingCollection string `json:"trashRecyclingCollection"`
Toilets []string `json:"toilets"`
InternetConnectivity string `json:"internetConnectivity"`
Showers []string `json:"showers"`
CellPhoneReception string `json:"cellPhoneReception"`
Laundry string `json:"laundry"`
Amphitheater string `json:"amphitheater"`
DumpStation string `json:"dumpStation"`
CampStore string `json:"campStore"`
StaffOrVolunteerHostOnsite string `json:"staffOrVolunteerHostOnsite"`
PotableWater []string `json:"potableWater"`
IceAvailableForSale string `json:"iceAvailableForSale"`
FirewoodForSale string `json:"firewoodForSale"`
FoodStorageLockers string `json:"foodStorageLockers"`
} `json:"amenities"`
Contacts struct {
PhoneNumbers []interface{} `json:"phoneNumbers"`
EmailAddresses []struct {
Description string `json:"description"`
EmailAddress string `json:"emailAddress"`
} `json:"emailAddresses"`
} `json:"contacts"`
Fees []struct {
Cost string `json:"cost"`
Description string `json:"description"`
Title string `json:"title"`
} `json:"fees"`
DirectionsOverview string `json:"directionsOverview"`
DirectionsUrl string `json:"directionsUrl"`
OperatingHours []struct {
Exceptions []interface{} `json:"exceptions"`
Description string `json:"description"`
StandardHours struct {
Wednesday string `json:"wednesday"`
Monday string `json:"monday"`
Thursday string `json:"thursday"`
Sunday string `json:"sunday"`
Tuesday string `json:"tuesday"`
Friday string `json:"friday"`
Saturday string `json:"saturday"`
} `json:"standardHours"`
Name string `json:"name"`
} `json:"operatingHours"`
Addresses []interface{} `json:"addresses"`
Images []struct {
Credit string `json:"credit"`
Crops []interface{} `json:"crops"`
Title string `json:"title"`
AltText string `json:"altText"`
Caption string `json:"caption"`
URL string `json:"url"`
} `json:"images"`
WeatherOverview string `json:"weatherOverview"`
NumberOfSitesReservable string `json:"numberOfSitesReservable"`
NumberOfSitesFirstComeFirstServe string `json:"numberOfSitesFirstComeFirstServe"`
Campsites struct {
TotalSites string `json:"totalSites"`
Group string `json:"group"`
Horse string `json:"horse"`
TentOnly string `json:"tentOnly"`
ElectricalHookups string `json:"electricalHookups"`
RvOnly string `json:"rvOnly"`
WalkBoatTo string `json:"walkBoatTo"`
Other string `json:"other"`
} `json:"campsites"`
Accessibility struct {
WheelchairAccess string `json:"wheelchairAccess"`
InternetInfo string `json:"internetInfo"`
CellPhoneInfo string `json:"cellPhoneInfo"`
FireStovePolicy string `json:"fireStovePolicy"`
RvAllowed string `json:"rvAllowed"`
RvInfo string `json:"rvInfo"`
RvMaxLength string `json:"rvMaxLength"`
AdditionalInfo string `json:"additionalInfo"`
TrailerMaxLength string `json:"trailerMaxLength"`
AdaInfo string `json:"adaInfo"`
TrailerAllowed string `json:"trailerAllowed"`
AccessRoads []string `json:"accessRoads"`
Classifications []string `json:"classifications"`
} `json:"accessibility"`
Multimedia []interface{} `json:"multimedia"`
RelevanceScore float64 `json:"relevanceScore"`
LastIndexedDate string `json:"lastIndexedDate"`
}
// CampgroundData represents the data in the response from the /campgrounds endpoint.
type CampgroundData struct {
Total string `json:"total"`
Data []Campground `json:"data"`
Limit string `json:"limit"`
Start string `json:"start"`
}
// GetCampgrounds makes a GET request to the /campgrounds endpoint and returns the campgrounds.
func (api *npsApi) GetCampgrounds(parkCode, stateCode []string, q string, limit, start int, sort []string) (*CampgroundData, error) {
params := map[string]interface{}{
"parkCode": strings.Join(parkCode, ","),
"stateCode": strings.Join(stateCode, ","),
"q": q,
"sort": strings.Join(sort, ","),
"limit": limit,
"start": start,
}
url := api.BuildRequestURL("/campgrounds", params)
resp, err := api.Client.Get(url)
if err != nil {
return nil, err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
bodyBytes, err := io.ReadAll(resp.Body)
if err != nil {
return nil, fmt.Errorf("unexpected status code: %d. Error reading body: %v", resp.StatusCode, err)
}
return nil, fmt.Errorf("unexpected status code: %d. Response body: %s", resp.StatusCode, string(bodyBytes))
}
var campgroundData CampgroundData
if err := json.NewDecoder(resp.Body).Decode(&campgroundData); err != nil {
return nil, err
}
return &campgroundData, nil
}
// Event represents an event in the National Park Service.
type Event struct {
Category string `json:"category"`
CategoryID string `json:"categoryid"`
Date string `json:"date"`
DateEnd string `json:"dateend"`
Dates []string `json:"dates"`
DateStart string `json:"datestart"`
Description string `json:"description"`
EventID string `json:"eventid"`
ID string `json:"id"`
IsAllDay string `json:"isallday"`
IsFree string `json:"isfree"`
IsRecurring string `json:"isrecurring"`
Location string `json:"location"`
Title string `json:"title"`
}
// EventResponse represents the response from the /events endpoint.
type EventResponse struct {
Total string `json:"total"`
Errors []string `json:"errors"` // Assuming errors are strings.
Data []Event `json:"data"`
Dates string `json:"dates"`
PageNumber string `json:"pagenumber"`
PageSize string `json:"pagesize"`
}
// GetEvents makes a GET request to the /events endpoint and returns the events.
func (api *npsApi) GetEvents(parkCode, stateCode, organization, subject, portal, tagsAll, tagsOne, tagsNone []string, dateStart, dateEnd string, eventType []string, id, q string, pageSize, pageNumber int, expandRecurring bool) (*EventResponse, error) {
params := map[string]interface{}{
"parkCode": strings.Join(parkCode, ","),
"stateCode": strings.Join(stateCode, ","),
"organization": strings.Join(organization, ","),
"subject": strings.Join(subject, ","),
"portal": strings.Join(portal, ","),
"tagsAll": strings.Join(tagsAll, ","),
"tagsOne": strings.Join(tagsOne, ","),
"tagsNone": strings.Join(tagsNone, ","),
"dateStart": dateStart,
"dateEnd": dateEnd,
"eventType": strings.Join(eventType, ","),
"id": id,
"q": q,
"pageSize": pageSize,
"pageNumber": pageNumber,
"expandRecurring": expandRecurring,
}
url := api.BuildRequestURL("/events", params)
resp, err := api.Client.Get(url)
if err != nil {
return nil, err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
bodyBytes, err := io.ReadAll(resp.Body)
if err != nil {
return nil, fmt.Errorf("unexpected status code: %d. Error reading body: %v", resp.StatusCode, err)
}
return nil, fmt.Errorf("unexpected status code: %d. Response body: %s", resp.StatusCode, string(bodyBytes))
}
var eventsResponse EventResponse
if err := json.NewDecoder(resp.Body).Decode(&eventsResponse); err != nil {
return nil, err
}
return &eventsResponse, nil
}
// FeePass represents a fee or pass in the National Park Service.
type FeePass struct {
CustomFeeLinkUrl string `json:"customFeeLinkUrl"`
TimedEntryDescription string `json:"timedEntryDescription"`
ParkingDetailsUrl string `json:"parkingDetailsUrl"`
EntrancePassesDescription string `json:"entrancePassesDescription"`
TimedEntryHeading string `json:"timedEntryHeading"`
CustomFeeDescription string `json:"customFeeDescription"`
IsParkingFeePossible bool `json:"isParkingFeePossible"`
EntranceFeeDescription string `json:"entranceFeeDescription"`
Cashless string `json:"cashless"`
CustomFeeHeading string `json:"customFeeHeading"`
IsInteragencyPassAccepted bool `json:"isInteragencyPassAccepted"`
PaidParkingDescription string `json:"paidParkingDescription"`
IsFeeFreePark bool `json:"isFeeFreePark"`
PaidParkingHeading string `json:"paidParkingHeading"`
ParkCode string `json:"parkCode"`
ContentOrderOrdinals struct {
EntranceFee int `json:"entranceFee"`
TimedEntry int `json:"timedEntry"`
PaidParking int `json:"paidParking"`
CustomFee int `json:"customFee"`
} `json:"contentOrderOrdinals"`
IsParkingOrTransportationFeePossible bool `json:"isParkingOrTransportationFeePossible"`
CustomFeeLinkText string `json:"customFeeLinkText"`
FeesAtWorkUrl string `json:"feesAtWorkUrl"`
}
// FeePassResponse represents the response from the /feespasses endpoint.
type FeePassResponse struct {
Total string `json:"total"`
Data []FeePass `json:"data"`
Start string `json:"start"`
Limit string `json:"limit"`
}
// GetFeesPasses makes a GET request to the /feespasses endpoint and returns the fees and passes.
func (api *npsApi) GetFeesPasses(parkCode, stateCode []string, q string, start, limit int, sort []string) (*FeePassResponse, error) {
params := map[string]interface{}{
"parkCode": strings.Join(parkCode, ","),
"stateCode": strings.Join(stateCode, ","),
"start": start,
"limit": limit,
"q": q,
"sort": strings.Join(sort, ","),
}
url := api.BuildRequestURL("/feespasses", params)
resp, err := api.Client.Get(url)
if err != nil {
return nil, err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
bodyBytes, err := io.ReadAll(resp.Body)
if err != nil {
return nil, fmt.Errorf("unexpected status code: %d. Error reading body: %v", resp.StatusCode, err)
}
return nil, fmt.Errorf("unexpected status code: %d. Response body: %s", resp.StatusCode, string(bodyBytes))
}
var feesPassesResponse FeePassResponse
if err := json.NewDecoder(resp.Body).Decode(&feesPassesResponse); err != nil {
return nil, err
}
return &feesPassesResponse, nil
}
// LessonPlan represents a lesson plan in the National Park Service.
type LessonPlan struct {
Parks []string `json:"parks"`
Description string `json:"description"`
CommonCore struct {
StateStandards string `json:"statestandards"`
MathStandards []string `json:"mathstandards"`
AdditionalStandards string `json:"additionalstandards"`
ElaStandards []string `json:"elastandards"`
} `json:"commoncore"`
Subject []string `json:"subject"`
GradeLevel string `json:"gradelevel"`
Url string `json:"url"`
QuestionObjective string `json:"questionobjective"`
Duration string `json:"duration"`
Title string `json:"title"`
ID string `json:"id"`
}
// LessonPlanResponse represents the response from the /lessonplans endpoint.
type LessonPlanResponse struct {
Total string `json:"total"`
Data []LessonPlan `json:"data"`
Start string `json:"start"`
Limit string `json:"limit"`
}
// GetLessonPlans makes a GET request to the /lessonplans endpoint and returns the lesson plans.
func (api *npsApi) GetLessonPlans(parkCode, stateCode []string, q string, start, limit int, sort []string) (*LessonPlanResponse, error) {
params := map[string]interface{}{
"parkCode": strings.Join(parkCode, ","),
"stateCode": strings.Join(stateCode, ","),
"start": start,
"limit": limit,
"q": q,
"sort": strings.Join(sort, ","),
}
url := api.BuildRequestURL("/lessonplans", params)
resp, err := api.Client.Get(url)
if err != nil {
return nil, err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
bodyBytes, err := io.ReadAll(resp.Body)
if err != nil {
return nil, fmt.Errorf("unexpected status code: %d. Error reading body: %v", resp.StatusCode, err)
}
return nil, fmt.Errorf("unexpected status code: %d. Response body: %s", resp.StatusCode, string(bodyBytes))
}
var lessonPlansResponse LessonPlanResponse
if err := json.NewDecoder(resp.Body).Decode(&lessonPlansResponse); err != nil {
return nil, err
}
return &lessonPlansResponse, nil
}
// MapdataParkboundaryResponse represents the response from the /mapdata/parkboundaries/{sitecode} endpoint.
type MapdataParkboundaryResponse struct {
Type string `json:"type"`
ID string `json:"id"`
Properties struct {
TypeID string `json:"typeId"`
Type struct {
Name string `json:"name"`
ID string `json:"id"`
} `json:"type"`
Aliases []struct {
ParkID string `json:"parkId"`
Current bool `json:"current"`
Name string `json:"name"`
ID string `json:"id"`
} `json:"aliases"`
Name string `json:"name"`
} `json:"properties"`
Geometry struct {
Coordinates [][][][]float64 `json:"coordinates"`
Type string `json:"type"`
} `json:"geometry"`
}
// GetParkBoundaries makes a GET request to the /mapdata/parkboundaries/{sitecode} endpoint and returns the park boundaries.
func (api *npsApi) GetParkBoundaries(sitecode string) (*MapdataParkboundaryResponse, error) {
if sitecode == "" {
return nil, fmt.Errorf("sitecode cannot be empty")
}
url := api.BaseURL + "/mapdata/parkboundaries/" + sitecode + "?api_key=" + api.ApiKey
resp, err := api.Client.Get(url)
if err != nil {
return nil, err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
bodyBytes, err := io.ReadAll(resp.Body)
if err != nil {
return nil, fmt.Errorf("unexpected status code: %d. Error reading body: %v", resp.StatusCode, err)
}
return nil, fmt.Errorf("unexpected status code: %d. Response body: %s", resp.StatusCode, string(bodyBytes))
}
var parkBoundariesResponse MapdataParkboundaryResponse
if err := json.NewDecoder(resp.Body).Decode(&parkBoundariesResponse); err != nil {
return nil, err
}
return &parkBoundariesResponse, nil
}
// MultimediaAudio represents an audio file in the National Park Service.
type MultimediaAudio struct {
CallToActionUrl string `json:"callToActionUrl"`
PermalinkUrl string `json:"permalinkUrl"`
Latitude float64 `json:"latitude"`
CallToAction string `json:"callToAction"`
Longitude float64 `json:"longitude"`
GeometryPoiId string `json:"geometryPoiId"`
SplashImage struct {
Url string `json:"url"`
} `json:"splashImage"`
Transcript string `json:"transcript"`
Title string `json:"title"`
Tags []string `json:"tags"`
Credit string `json:"credit"`
DurationMs int64 `json:"durationMs"`
ID string `json:"id"`
Versions []struct {
FileSize float64 `json:"fileSize"`
FileType string `json:"fileType"`
Url string `json:"url"`
} `json:"versions"`
Description string `json:"description"`
RelatedParks []struct {
States string `json:"states"`
ParkCode string `json:"parkCode"`
Designation string `json:"designation"`
} `json:"relatedParks"`
}
// MultimediaAudioResponse represents the response from the /multimedia/audio endpoint.
type MultimediaAudioResponse struct {
Total string `json:"total"`
Data []MultimediaAudio `json:"data"`
Start string `json:"start"`
Limit string `json:"limit"`
}
// GetMultimediaAudio makes a GET request to the /multimedia/audio endpoint and returns the audio files.
func (api *npsApi) GetMultimediaAudio(parkCode, stateCode []string, q string, start, limit int) (*MultimediaAudioResponse, error) {
params := map[string]interface{}{
"parkCode": strings.Join(parkCode, ","),
"stateCode": strings.Join(stateCode, ","),
"start": start,
"limit": limit,
"q": q,
}
url := api.BuildRequestURL("/multimedia/audio", params)
resp, err := api.Client.Get(url)
if err != nil {
return nil, err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
bodyBytes, err := io.ReadAll(resp.Body)
if err != nil {
return nil, fmt.Errorf("unexpected status code: %d. Error reading body: %v", resp.StatusCode, err)
}
return nil, fmt.Errorf("unexpected status code: %d. Response body: %s", resp.StatusCode, string(bodyBytes))
}
var multimediaAudioResponse MultimediaAudioResponse
if err := json.NewDecoder(resp.Body).Decode(&multimediaAudioResponse); err != nil {
return nil, err
}
return &multimediaAudioResponse, nil
}
// MultimediaGalleries represents a gallery in the National Park Service.
type MultimediaGalleries struct {
ConstraintsInfo struct {
Constraint string `json:"constraint"`
GrantingRights string `json:"grantingRights"`
} `json:"constraintsInfo"`
Copyright string `json:"copyright"`
Url string `json:"url"`
Title string `json:"title"`
Images []struct {
Url string `json:"url"`
AltText string `json:"altText"`
Title string `json:"title"`
Description string `json:"description"`
} `json:"images"`
Tags []string `json:"tags"`
ID string `json:"id"`
Description string `json:"description"`
RelatedParks []struct {
States string `json:"states"`
ParkCode string `json:"parkCode"`
Designation string `json:"designation"`
FullName string `json:"fullName"`
Url string `json:"url"`