forked from ahmdrz/goinsta
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfeeds.go
86 lines (78 loc) · 2.24 KB
/
feeds.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
package goinsta
import (
"encoding/json"
"fmt"
)
// Feed is the object for all feed endpoints.
type Feed struct {
inst *Instagram
}
// newFeed creates new Feed structure
func newFeed(inst *Instagram) *Feed {
return &Feed{
inst: inst,
}
}
// Feed search by locationID
func (feed *Feed) LocationID(locationID int64) (*FeedLocation, error) {
insta := feed.inst
body, err := insta.sendRequest(
&reqOptions{
Endpoint: fmt.Sprintf(urlFeedLocationID, locationID),
Query: map[string]string{
"rank_token": insta.rankToken,
"ranked_content": "true",
},
},
)
if err != nil {
return nil, err
}
res := &FeedLocation{}
err = json.Unmarshal(body, res)
return res, err
}
// FeedLocation is the struct that fits the structure returned by instagram on LocationID search.
type FeedLocation struct {
RankedItems []Item `json:"ranked_items"`
Items []Item `json:"items"`
NumResults int `json:"num_results"`
NextID string `json:"next_max_id"`
MoreAvailable bool `json:"more_available"`
AutoLoadMoreEnabled bool `json:"auto_load_more_enabled"`
MediaCount int `json:"media_count"`
Location Location `json:"location"`
Status string `json:"status"`
}
// Tags search by Tag in user Feed
//
// (sorry for returning FeedTag. See #FeedTag)
func (feed *Feed) Tags(tag string) (*FeedTag, error) {
insta := feed.inst
body, err := insta.sendRequest(
&reqOptions{
Endpoint: fmt.Sprintf(urlFeedTag, tag),
Query: map[string]string{
"rank_token": insta.rankToken,
"ranked_content": "true",
},
},
)
if err != nil {
return nil, err
}
res := &FeedTag{}
err = json.Unmarshal(body, res)
return res, err
}
// FeedTag is the struct that fits the structure returned by instagram on TagSearch.
type FeedTag struct {
RankedItems []Item `json:"ranked_items"`
Images []Item `json:"items"`
NumResults int `json:"num_results"`
NextID string `json:"next_max_id"`
MoreAvailable bool `json:"more_available"`
AutoLoadMoreEnabled bool `json:"auto_load_more_enabled"`
Story StoryMedia `json:"story"`
Status string `json:"status"`
}