-
Notifications
You must be signed in to change notification settings - Fork 57
/
Copy pathlocation.go
87 lines (78 loc) · 2.1 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
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
package goinsta
import (
"encoding/json"
"fmt"
)
type LocationInstance struct {
insta *Instagram
}
func newLocation(insta *Instagram) *LocationInstance {
return &LocationInstance{insta: insta}
}
type LayoutSection struct {
LayoutType string `json:"layout_type"`
LayoutContent struct {
Medias []struct {
Media Item `json:"media"`
} `json:"medias"`
} `json:"layout_content"`
FeedType string `json:"feed_type"`
ExploreItemInfo struct {
NumColumns int `json:"num_columns"`
TotalNumColumns int `json:"total_num_columns"`
AspectRatio float64 `json:"aspect_ratio"`
Autoplay bool `json:"autoplay"`
} `json:"explore_item_info"`
}
type Section struct {
Sections []LayoutSection `json:"sections"`
MoreAvailable bool `json:"more_available"`
NextPage int `json:"next_page"`
NextMediaIds []int64 `json:"next_media_ids"`
NextID string `json:"next_max_id"`
Status string `json:"status"`
}
func (l *LocationInstance) Feeds(locationID int64) (*Section, error) {
// TODO: use pagination for location feeds.
insta := l.insta
body, _, err := insta.sendRequest(
&reqOptions{
Endpoint: fmt.Sprintf(urlFeedLocations, locationID),
IsPost: true,
Query: map[string]string{
"rank_token": insta.rankToken,
"ranked_content": "true",
"_uid": toString(insta.Account.ID),
"_uuid": insta.uuid,
},
},
)
if err != nil {
return nil, err
}
section := &Section{}
err = json.Unmarshal(body, section)
return section, err
}
func (l *Location) Feed() (*Section, error) {
// TODO: use pagination for location feeds.
insta := l.insta
body, _, err := insta.sendRequest(
&reqOptions{
Endpoint: fmt.Sprintf(urlFeedLocations, l.ID),
IsPost: true,
Query: map[string]string{
"rank_token": insta.rankToken,
"ranked_content": "true",
"_uid": toString(insta.Account.ID),
"_uuid": insta.uuid,
},
},
)
if err != nil {
return nil, err
}
section := &Section{}
err = json.Unmarshal(body, section)
return section, err
}