-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcollections.go
63 lines (56 loc) · 1.69 KB
/
collections.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
package instabot
import (
"context"
"fmt"
"github.com/winterssy/sreq"
)
const (
apiGetCollections = apiV1 + "collections/list/"
apiCreateCollection = apiV1 + "collections/create/"
apiEditCollection = apiV1 + "collections/%s/edit/"
apiDeleteCollection = apiV1 + "collections/%s/delete/"
)
func (bot *Bot) GetCollections(ctx context.Context) (sreq.H, error) {
req, _ := sreq.NewRequest(sreq.MethodGet, apiGetCollections,
sreq.WithContext(ctx),
)
return bot.sendRequest(req)
}
func (bot *Bot) CreateCollection(ctx context.Context, name string) (sreq.H, error) {
form := sreq.Form{
"name": name,
"_csrftoken": bot.GetCSRFToken(),
"_uid": bot.GetUserId(),
"_uuid": bot.uuid,
}
req, _ := sreq.NewRequest(sreq.MethodPost, apiCreateCollection,
sreq.WithForm(GenerateSignedForm(form)),
sreq.WithContext(ctx),
)
return bot.sendRequest(req)
}
func (bot *Bot) EditCollection(ctx context.Context, collectionId string, name string) (sreq.H, error) {
form := sreq.Form{
"name": name,
"_csrftoken": bot.GetCSRFToken(),
"_uid": bot.GetUserId(),
"_uuid": bot.uuid,
}
req, _ := sreq.NewRequest(sreq.MethodPost, fmt.Sprintf(apiEditCollection, collectionId),
sreq.WithForm(GenerateSignedForm(form)),
sreq.WithContext(ctx),
)
return bot.sendRequest(req)
}
func (bot *Bot) DeleteCollection(ctx context.Context, collectionId string) (sreq.H, error) {
form := sreq.Form{
"_csrftoken": bot.GetCSRFToken(),
"_uid": bot.GetUserId(),
"_uuid": bot.uuid,
}
req, _ := sreq.NewRequest(sreq.MethodPost, fmt.Sprintf(apiDeleteCollection, collectionId),
sreq.WithForm(GenerateSignedForm(form)),
sreq.WithContext(ctx),
)
return bot.sendRequest(req)
}