-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathneighbourhood.go
197 lines (160 loc) · 6.06 KB
/
neighbourhood.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
package ukpolice
import (
"context"
"fmt"
)
// NeighbourhoodService handles communication with the neighbourhood related
// method of the data.police.uk API.
type NeighbourhoodService service
// Neighbourhood holds details of neighbourhoods.
type Neighbourhood struct {
ForceURL string `json:"url_force,omitempty"`
ContactDetails map[string]string `json:"contact_details,omitempty"`
Name string `json:"name,omitempty"`
Links []map[string]string `json:"links,omitempty"`
Centre Location `json:"centre,omitempty"`
Locations []Location `json:"locations,omitempty"`
Description string `json:"description,omitempty"`
ID string `json:"id,omitempty"`
Population string `json:"population,omitempty"`
// Used by LocateNeighbourhood
Force string `json:"force,omitempty"`
Neighbourhood string `json:"neighbourhood,omitempty"`
}
func (n Neighbourhood) String() string {
return Stringify(n)
}
// NeighbourhoodTeam holds details of neighbourhood teams.
type NeighbourhoodTeam struct {
Bio string `json:"bio,omitempty"`
ContactDetails map[string]string `json:"contact_details,omitempty"`
Name string `json:"name,omitempty"`
Rank string `json:"rank,omitempty"`
}
func (n NeighbourhoodTeam) String() string {
return Stringify(n)
}
// NeighbourhoodEvent holds details of neighbourhood events.
type NeighbourhoodEvent struct {
ContactDetails map[string]string `json:"contact_details,omitempty"`
Description string `json:"description,omitempty"`
Title string `json:"title,omitempty"`
Address string `json:"address,omitempty"`
Type string `json:"type,omitempty"`
StartDate string `json:"start_date,omitempty"`
EndDate string `json:"end_date,omitempty"`
}
func (n NeighbourhoodEvent) String() string {
return Stringify(n)
}
// NeighbourhoodPriorities holds details of neighbourhood priorities.
type NeighbourhoodPriorities struct {
Action string `json:"action,omitempty"`
Issue string `json:"issue,omitempty"`
IssueDate string `json:"issue-date,omitempty"`
ActionDate string `json:"action-date,omitempty"`
}
func (n NeighbourhoodPriorities) String() string {
return Stringify(n)
}
// GetNeighbourhoods returns a the neighbourhood details for a given police force.
func (n *NeighbourhoodService) GetNeighbourhoods(ctx context.Context, force string) ([]Neighbourhood, *Response, error) {
u := fmt.Sprintf("%s/neighbourhoods", force)
req, err := n.api.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
var neighbourhoods []Neighbourhood
resp, err := n.api.Do(ctx, req, &neighbourhoods)
if err != nil {
return nil, nil, err
}
return neighbourhoods, resp, nil
}
// GetSpecificNeighbourhood returns the details of a specific neighbourhood given
// a police force and neighbourhood ID
func (n *NeighbourhoodService) GetSpecificNeighbourhood(ctx context.Context, force, ID string) (*Neighbourhood, *Response, error) {
u := fmt.Sprintf("%s/%s", force, ID)
req, err := n.api.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
var neighbourhood *Neighbourhood
resp, err := n.api.Do(ctx, req, &neighbourhood)
if err != nil {
return nil, nil, err
}
return neighbourhood, resp, nil
}
// GetNeighbourhoodBoundary returns a list of latitude/longitude pairs that make
// up the boundary of a neighbourhood.
func (n *NeighbourhoodService) GetNeighbourhoodBoundary(ctx context.Context, force, NeighbourhoodID string) ([]Location, *Response, error) {
u := fmt.Sprintf("%s/%s/boundary", force, NeighbourhoodID)
req, err := n.api.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
var boundary []Location
resp, err := n.api.Do(ctx, req, &boundary)
if err != nil {
return nil, nil, err
}
return boundary, resp, nil
}
// GetNeighbourhoodTeam returns a list of team information for a given force and neighbourhood.
func (n *NeighbourhoodService) GetNeighbourhoodTeam(ctx context.Context, force, NeighbourhoodID string) ([]NeighbourhoodTeam, *Response, error) {
u := fmt.Sprintf("%s/%s/people", force, NeighbourhoodID)
req, err := n.api.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
var team []NeighbourhoodTeam
resp, err := n.api.Do(ctx, req, &team)
if err != nil {
return nil, nil, err
}
return team, resp, nil
}
// GetNeighbourhoodEvents returns a list of events information for a given force and neighbourhood.
func (n *NeighbourhoodService) GetNeighbourhoodEvents(ctx context.Context, force, NeighbourhoodID string) ([]NeighbourhoodEvent, *Response, error) {
u := fmt.Sprintf("%s/%s/events", force, NeighbourhoodID)
req, err := n.api.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
var events []NeighbourhoodEvent
resp, err := n.api.Do(ctx, req, &events)
if err != nil {
return nil, nil, err
}
return events, resp, nil
}
// GetNeighbourhoodPriorities returns a list of priorities for a given force and neighbourhood
func (n *NeighbourhoodService) GetNeighbourhoodPriorities(ctx context.Context, force, NeighbourhoodID string) ([]NeighbourhoodPriorities, *Response, error) {
u := fmt.Sprintf("%s/%s/priorities", force, NeighbourhoodID)
req, err := n.api.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
var priorities []NeighbourhoodPriorities
resp, err := n.api.Do(ctx, req, &priorities)
if err != nil {
return nil, nil, err
}
return priorities, resp, nil
}
// LocateNeighbourhood returns the neighbourhood policing team responsible for a given
// latitude and longitude
func (n *NeighbourhoodService) LocateNeighbourhood(ctx context.Context, lat, long string) (*Neighbourhood, *Response, error) {
u := fmt.Sprintf("locate-neighbourhood?q=%s,%s", lat, long)
req, err := n.api.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
var neighbourhood *Neighbourhood
resp, err := n.api.Do(ctx, req, &neighbourhood)
if err != nil {
return nil, nil, err
}
return neighbourhood, resp, nil
}