-
Notifications
You must be signed in to change notification settings - Fork 0
/
map.go
101 lines (83 loc) · 2.52 KB
/
map.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
package epaecho
import (
"encoding/json"
)
// mapAPIURI is the unique URL path for a Get Map Data API request.
const mapAPIURI = "echo_rest_services.get_map"
// echoMapAPIOptions represents a human-readable map of map query options.
var echoMapAPIOptions = map[string]string{
"queryID": "QID",
"Latitude1": "C1Lat",
"Longitude1": "C1Long",
"Latitude2": "C2Lat",
"Longitude2": "C2Long",
}
type EchoMapAPI struct {
Config *EchoAPIConfig
response echoMapResponse
}
type echoMapResponse struct {
MapOutput struct {
QueryID string
IconBaseURL string
PopUpBaseURL string
CenterLatitude string
CenterLongitude string
MapData []EchoMapData
}
}
type EchoMapData struct {
Latitude string `json:"LAT"`
Longitude string `json:"LON"`
Icon string `json:"ICON,omitempty"`
Type string `json:"TYPE,omitempty"`
Name string `json:"NAME,omitempty"`
PUV string `json:"PUV,omitempty"`
SDWAStatus string `json:"SDWAstatus,omitempty"`
RCRAStatus string `json:"RCRAstatus,omitempty"`
CWAStatus string `json:"CWAstatus,omitempty"`
CAAStatus string `json:"CAAstatus,omitempty"`
LastInspection string `json:"LastInsp,omitempty"`
FormalInspectionCount string `json:"FormalCount,omitempty"`
InformalInspectionCount string `json:"InformalCount,omitempty"`
}
// NewMapAPI is a constructor function which returns a pointer
// to an EchoFacilitiesAPI struct.
// Any values defined in the defaultQueryParameters map will be set during
// construction.
func NewMapAPI(qid string) *EchoMapAPI {
mapAPI := &EchoMapAPI{
Config: newEchoAPIConfig(),
}
mapAPI.Config.endpointURI = mapAPIURI
mapAPI.SetParam("queryID", qid)
return mapAPI
}
func (api *EchoMapAPI) SetParam(key string, value string) error {
err := api.Config.addParam(key, value, echoMapAPIOptions)
if err != nil {
return err
}
return nil
}
// Maps returns the response from a Get Map Data API request.
func (api *EchoMapAPI) Maps() (echoMapResponse, error) {
err := api.Config.doRequest()
if err != nil {
return echoMapResponse{}, err
}
unmarshalErr := api.unmarshalResponse()
if unmarshalErr != nil {
return echoMapResponse{}, unmarshalErr
}
return api.response, nil
}
func (api *EchoMapAPI) unmarshalResponse() error {
response := echoMapResponse{}
err := json.Unmarshal(api.Config.rawResponse, &response)
if err != nil {
return err
}
api.response = response
return nil
}