-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfriendships.go
85 lines (73 loc) · 2.42 KB
/
friendships.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
package instabot
import (
"context"
"fmt"
"github.com/winterssy/sreq"
)
const (
apiGetUserFriendship = apiV1 + "friendships/show/%s/"
apiGetUserFollowings = apiV1 + "friendships/%s/following/?max_id=%s"
apiGetUserFollowers = apiV1 + "friendships/%s/followers/?max_id=%s"
apiFollowUser = apiV1 + "friendships/create/%s/"
apiUnfollowUser = apiV1 + "friendships/destroy/%s/"
apiBlockUser = apiV1 + "friendships/block/%s/"
apiUnblockUser = apiV1 + "friendships/unblock/%s/"
)
func (bot *Bot) GetUserFriendship(ctx context.Context, userId string) (sreq.H, error) {
req, _ := sreq.NewRequest(sreq.MethodGet, fmt.Sprintf(apiGetUserFriendship, userId),
sreq.WithContext(ctx),
)
return bot.sendRequest(req)
}
func (bot *Bot) GetUserFollowings(ctx context.Context, userId string, maxId string) (sreq.H, error) {
req, _ := sreq.NewRequest(sreq.MethodGet, fmt.Sprintf(apiGetUserFollowings, userId, maxId),
sreq.WithContext(ctx),
)
return bot.sendRequest(req)
}
func (bot *Bot) GetUserFollowers(ctx context.Context, userId string, maxId string) (sreq.H, error) {
req, _ := sreq.NewRequest(sreq.MethodGet, fmt.Sprintf(apiGetUserFollowers, userId, maxId),
sreq.WithContext(ctx),
)
return bot.sendRequest(req)
}
func (bot *Bot) GetSelfFollowings(ctx context.Context, maxId string) (sreq.H, error) {
return bot.GetUserFollowings(ctx, bot.GetUserId(), maxId)
}
func (bot *Bot) GetSelfFollowers(ctx context.Context, maxId string) (sreq.H, error) {
return bot.GetUserFollowers(ctx, bot.GetUserId(), maxId)
}
func (bot *Bot) FollowUser(ctx context.Context, userId string, undo bool) (sreq.H, error) {
form := sreq.Form{
"_csrftoken": bot.GetCSRFToken(),
"user_id": userId,
"_uid": bot.GetUserId(),
"_uuid": bot.uuid,
}
url := apiFollowUser
if undo {
url = apiUnfollowUser
}
req, _ := sreq.NewRequest(sreq.MethodPost, fmt.Sprintf(url, userId),
sreq.WithForm(GenerateSignedForm(form)),
sreq.WithContext(ctx),
)
return bot.sendRequest(req)
}
func (bot *Bot) BlockUser(ctx context.Context, userId string, undo bool) (sreq.H, error) {
form := sreq.Form{
"_csrftoken": bot.GetCSRFToken(),
"user_id": userId,
"_uid": bot.GetUserId(),
"_uuid": bot.uuid,
}
url := apiBlockUser
if undo {
url = apiUnblockUser
}
req, _ := sreq.NewRequest(sreq.MethodPost, fmt.Sprintf(url, userId),
sreq.WithForm(GenerateSignedForm(form)),
sreq.WithContext(ctx),
)
return bot.sendRequest(req)
}