forked from aliforever/gista
-
Notifications
You must be signed in to change notification settings - Fork 0
/
discover.go
70 lines (62 loc) · 1.65 KB
/
discover.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
package gista
import (
"encoding/json"
"fmt"
"time"
"github.com/aliforever/gista/errs"
"github.com/aliforever/gista/constants"
"github.com/aliforever/gista/responses"
)
type discover struct {
ig *Instagram
}
func newDiscover(i *Instagram) *discover {
return &discover{ig: i}
}
func (d *discover) GetExploreFeed(maxId *string, prefetch bool) (res *responses.Explore, err error) {
res = &responses.Explore{}
p := "false"
if prefetch {
p = "true"
}
_, offset := time.Now().Zone()
j, _ := json.Marshal(constants.SupportedCapabilities)
request := d.ig.client.Request(constants.Explore).
AddParam("is_prefetch", p).
AddParam("is_from_promote", "false").
AddParam("timezone_offset", fmt.Sprintf("%d", offset)).
AddParam("session_id", d.ig.sessionId).
AddParam("supported_capabilities_new", string(j))
if !prefetch {
if maxId == nil {
z := "0"
maxId = &z
}
request.AddParam("max_id", *maxId)
request.AddParam("module", "explore_popular")
}
err = request.GetResponse(res)
return
}
func (d *discover) GetRecentSearches() (res *responses.RecentSearches, err error) {
res = &responses.RecentSearches{}
err = d.ig.client.Request(constants.RecentSearches).GetResponse(res)
return
}
func (d *discover) GetSuggestedSearches(searchType string) (res *responses.SuggestedSearches, err error) {
found := false
for _, t := range []string{"blended", "users", "hashtags", "places"} {
if t == searchType {
found = true
}
}
if !found {
err = errs.UnknownSearchType(searchType)
return
}
res = &responses.SuggestedSearches{}
err = d.ig.client.Request(constants.SuggestedSearches).
AddParam("type", searchType).
GetResponse(res)
return
}