forked from programmingthomas/instago
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlocation.go
49 lines (44 loc) · 1.57 KB
/
location.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
package instago
import "fmt"
//Gets basic information such as name and coordinates for a location
//
//locationId: The id of a location to lookup
func (api InstagramAPI) Location(locationId string) Location {
params := getEmptyMap()
response := api.DoRequest("locations/"+locationId, params)
return LocationFromAPI(response.Object("data"))
}
//Gets media posted from that location
//
//locationId: The id of the location
//
//beforePost: (optional = "") posts before this ID
//
//afterPost: (optional = "") posts after this ID
func (api InstagramAPI) LocationPosts(locationId, beforePost, afterPost string) ([]Media, Pagination, error) {
return api.GenericMediaListRequest("locations/"+locationId+"/media/recent", beforePost, afterPost, 0)
}
//Gets a list of locations near a give latitude/longitude within a certain distance
//
//lat: The latitude to search near
//
//long: The longitude to search near
//
//distance: (optional = 0) The number of meters to search within
func (api InstagramAPI) LocationsNear(lat, long, distance float64) ([]Location, Pagination, error) {
params := getEmptyMap()
if distance > 0 {
params["distance"] = fmt.Sprintf("%f", distance)
}
params["lat"] = fmt.Sprintf("%f", lat)
params["lng"] = fmt.Sprintf("%f", long)
results := api.DoRequest("locations/search", params)
data := results.ObjectArray("data")
locations := make([]Location, 0)
for _, loc := range data {
locations = append(locations, LocationFromAPI(loc))
}
pagination := PaginationFromAPI(results.Object("pagination"))
err := api.ErrorFromAPI(results)
return locations, pagination, err
}