-
Notifications
You must be signed in to change notification settings - Fork 9
/
venues_general.go
281 lines (238 loc) · 9.54 KB
/
venues_general.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
package foursquarego
import (
"encoding/json"
"net/http"
)
type categoriesResp struct {
Categories []Category `json:"categories"`
}
// Categories returns a hierarchical list of categories applied to venues.
// https://developer.foursquare.com/docs/api/venues/categories
func (s *VenueService) Categories() ([]Category, *http.Response, error) {
cats := new(categoriesResp)
response := new(Response)
resp, err := s.sling.New().Get("categories").Receive(response, response)
if err == nil {
json.Unmarshal(response.Response, cats)
}
return cats.Categories, resp, relevantError(err, *response)
}
// SearchIntent are the intent options on VenueService.Search
type SearchIntent string
// Options for SearchIntent
const (
IntentCheckin SearchIntent = "checkin"
IntentBrowse SearchIntent = "browse"
IntentGlobal SearchIntent = "global"
IntentMatch SearchIntent = "match"
)
// VenueSearchParams are the parameters for the VenueService.Search
type VenueSearchParams struct {
LatLong string `url:"ll,omitempty"`
Near string `url:"near,omitempty"`
LatLongAccuracy int `url:"llAcc,omitempty"`
Altitude int `url:"alt,omitempty"`
AltitudeAccuracy int `url:"altAcc,omitempty"`
Query string `url:"query,omitempty"`
Limit int `url:"limit,omitempty"`
Intent SearchIntent `url:"intent,omitempty"`
Radius int `url:"radius,omitempty"`
Sw string `url:"sw,omitempty"`
Ne string `url:"ne,omitempty"`
CategoryID []string `url:"categoryId,omitempty"`
URL string `url:"url,omitempty"`
ProviderID string `url:"providerId,omitempty"`
LinkedID int `url:"linkedId,omitempty"`
}
type venueSearchResp struct {
Venues []Venue `json:"venues"`
}
// Search returns a list of venues near the current location, optionally matching a search term.
// https://developer.foursquare.com/docs/api/venues/search
func (s *VenueService) Search(params *VenueSearchParams) ([]Venue, *http.Response, error) {
venues := new(venueSearchResp)
response := new(Response)
resp, err := s.sling.New().Get("search").QueryStruct(params).Receive(response, response)
if err == nil {
json.Unmarshal(response.Response, venues)
}
return venues.Venues, resp, relevantError(err, *response)
}
// VenueSuggestParams are the parementers for the VenueService.SuggestCompletion
type VenueSuggestParams struct {
LatLong string `url:"ll,omitempty"`
Near string `url:"near,omitempty"`
LatLongAccuracy int `url:"llAcc,omitempty"`
Altitude int `url:"alt,omitempty"`
AltitudeAccuracy int `url:"altAcc,omitempty"`
Query string `url:"query,omitempty"`
Limit int `url:"limit,omitempty"`
Radius int `url:"radius,omitempty"`
Sw string `url:"sw,omitempty"`
Ne string `url:"ne,omitempty"`
}
// MiniVenue is a compact Venue
// https://developer.foursquare.com/docs/api/venues/suggestcompletion
type MiniVenue struct {
ID string `json:"id"`
Name string `json:"name"`
Location Location `json:"location"`
Category []Category `json:"categories"`
HasPerk bool `json:"hasPerk"`
}
type venueSuggestResp struct {
MiniVenues []MiniVenue `json:"minivenues"`
}
// SuggestCompletion returns a list of mini-venues partially matching the search term, near the location.
// https://developer.foursquare.com/docs/api/venues/suggestcompletion
func (s *VenueService) SuggestCompletion(params *VenueSuggestParams) ([]MiniVenue, *http.Response, error) {
venues := new(venueSuggestResp)
response := new(Response)
resp, err := s.sling.New().Get("suggestCompletion").QueryStruct(params).Receive(response, response)
if err == nil {
json.Unmarshal(response.Response, venues)
}
return venues.MiniVenues, resp, relevantError(err, *response)
}
// VenueTrendingParams are the parameters for VenueService.Trending
type VenueTrendingParams struct {
LatLong string `url:"ll,omitempty"`
Limit int `url:"limit,omitempty"`
Radius int `url:"radius,omitempty"`
}
type venueTrendingResp struct {
Venues []Venue `json:"venues"`
}
// Trending returns a list of venues near the current location with the most people currently checked in.
// https://developer.foursquare.com/docs/api/venues/trending
func (s *VenueService) Trending(params *VenueTrendingParams) ([]Venue, *http.Response, error) {
venues := new(venueTrendingResp)
response := new(Response)
resp, err := s.sling.New().Get("trending").QueryStruct(params).Receive(response, response)
if err == nil {
json.Unmarshal(response.Response, venues)
}
return venues.Venues, resp, relevantError(err, *response)
}
// ExploreSection are the section options on VenueService.Explore
type ExploreSection string
// Options for ExploreSection
const (
SectionFood ExploreSection = "food"
SectionDrink ExploreSection = "drink"
SectionCoffee ExploreSection = "coffee"
SectionShops ExploreSection = "shops"
SectionArts ExploreSection = "arts"
SectionOutdoors ExploreSection = "outdoors"
SectionSights ExploreSection = "sights"
SectionTrending ExploreSection = "trending"
SectionSpecials ExploreSection = "specials"
SectionNextVenues ExploreSection = "nextVenues"
SectionTopPicks ExploreSection = "topPicks"
)
// Novelty are the novelty options on VenueService.Explore
type Novelty string
// Options for Novelty
const (
NoveltyNew Novelty = "new"
NoveltyOld Novelty = "old"
)
// FriendVisit are the friendVisit options on VenueService.Explore
type FriendVisit string
// Options for FriendVisit
const (
FriendVisited FriendVisit = "visited"
FriendNotVisited FriendVisit = "notvisited"
)
// ExploreTime are the time options on VenueService.Explore
type ExploreTime string
// Options for ExploreTime
const (
TimeAny ExploreTime = "any"
)
// VenueExploreParams are the parameters for VenueService.Explore
type VenueExploreParams struct {
LatLong string `url:"ll,omitempty"`
Near string `url:"near,omitempty"`
LatLongAccuracy int `url:"llAcc,omitempty"`
Altitude int `url:"alt,omitempty"`
AltitudeAccuracy int `url:"altAcc,omitempty"`
Radius int `url:"radius,omitempty"`
Section ExploreSection `url:"section,omitempty"`
Query string `url:"query,omitempty"`
CategoryID []string `url:"categoryId,omitempty"`
Limit int `url:"limit,omitempty"`
Offset int `url:"offset,omitempty"`
Novelty Novelty `url:"novelty,omitempty"`
FriendVisits FriendVisit `url:"friendVists,omitempty"`
Time ExploreTime `url:"time,omitempty"`
Day ExploreTime `url:"day,omitempty"`
VenuePhotos BoolAsAnInt `url:"venuePhotos,omitempty"`
LastVenue string `url:"lastVenue,omitempty"`
OpenNow BoolAsAnInt `url:"openNow,omitempty"`
SortByDistance BoolAsAnInt `url:"sortByDistance,omitempty"`
Price []int `url:"price,omitempty"`
Saved BoolAsAnInt `url:"saved,omitempty"`
Specials BoolAsAnInt `url:"specials,omitempty"`
}
// VenueExploreResp is the response for VenueService.Explore
// https://developer.foursquare.com/docs/api/venues/explore
type VenueExploreResp struct {
SuggestedFilters SuggestedFilters `json:"suggestedFilters"`
Warning Warning `json:"warning"`
SuggestedRadius int `json:"suggestedRadius"`
HeaderLocation string `json:"headerLocation"`
HeaderFullLocation string `json:"headerFullLocation"`
HeaderLocationGranularity string `json:"headerLocationGranularity"`
TotalResults int `json:"totalResults"`
SuggestedBounds SuggestedBounds `json:"suggestedBounds"`
Groups []Recommendation `json:"groups"`
}
// SuggestedFilters are filters to show the user
type SuggestedFilters struct {
Header string `json:"header"`
Filters []Filter `json:"filters"`
}
// Filter is a Filter in SuggestedFilters
type Filter struct {
Name string `json:"name"`
Key string `json:"key"`
}
// Warning is a text field that contains a warning message
type Warning struct {
Text string `json:"text"`
}
// SuggestedBounds are the bounds that were used in the search
type SuggestedBounds struct {
Ne LatLong `json:"ne"`
Sw LatLong `json:"sw"`
}
// LatLong simple lat/long fields for SuggestedBounds
type LatLong struct {
Lat float64 `json:"lat"`
Lng float64 `json:"lng"`
}
// Recommendation the groups field in VenueExploreResp
type Recommendation struct {
Type string `json:"type"`
Name string `json:"name"`
Items []Recommend `json:"items"`
}
// Recommend is a recommendation with a Venue for VenueService.Explore
type Recommend struct {
Reasons Reasons `json:"reasons"`
Venue Venue `json:"venue"`
Tips []Tip `json:"tips"`
ReferralID string `json:"referralId"`
}
// Explore returns a list of recommended venues near the current location.
// https://developer.foursquare.com/docs/api/venues/explore
func (s *VenueService) Explore(params *VenueExploreParams) (*VenueExploreResp, *http.Response, error) {
exploreResponse := new(VenueExploreResp)
response := new(Response)
resp, err := s.sling.New().Get("explore").QueryStruct(params).Receive(response, response)
if err == nil {
json.Unmarshal(response.Response, exploreResponse)
}
return exploreResponse, resp, relevantError(err, *response)
}