-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathprofile_move.go
More file actions
64 lines (49 loc) · 1.11 KB
/
Copy pathprofile_move.go
File metadata and controls
64 lines (49 loc) · 1.11 KB
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
package adspower
import (
"bytes"
"context"
"fmt"
"net/http"
json "github.com/goccy/go-json"
)
type moveProfileRequest struct {
UserIds []string `json:"user_ids"`
GroupId string `json:"group_id"`
}
func (a *AdsPower) MoveProfiles(ctx context.Context, ids []string, groupId string) error {
payload := &moveProfileRequest{
UserIds: ids,
GroupId: groupId,
}
b, err := json.Marshal(payload)
if err != nil {
panic(err)
}
fmt.Println(string(b))
buf := bytes.NewBuffer(b)
url := UserApi + "/regroup"
req, err := http.NewRequestWithContext(ctx, http.MethodPost, url, buf)
if err != nil {
panic(err)
}
defer req.Body.Close()
req.Header.Set("Content-Type", "application/json")
a.rl.Take()
resp, err := a.HTTPClient.Do(req)
if err != nil {
return err
}
defer resp.Body.Close()
decodedBody, err := decodeResponseBody[response](resp)
if err != nil {
return err
}
err = handleResponseError(decodedBody)
if err != nil {
return err
}
return nil
}
func (a *AdsPower) MoveProfile(ctx context.Context, id, targetGroupId string) error {
return a.MoveProfiles(ctx, []string{id}, targetGroupId)
}