-
Notifications
You must be signed in to change notification settings - Fork 0
/
blocks.1.1.get_blocks.go
55 lines (46 loc) · 1.24 KB
/
blocks.1.1.get_blocks.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
package blocks
import (
"encoding/json"
"io"
"net/http"
"strconv"
"github.com/snowpal/pitch-content-management-sdk/lib"
helpers2 "github.com/snowpal/pitch-content-management-sdk/lib/helpers"
"github.com/snowpal/pitch-content-management-sdk/lib/structs/request"
"github.com/snowpal/pitch-content-management-sdk/lib/structs/response"
)
func GetBlocks(jwtToken string, blockParam request.GetBlocksParam) ([]response.Block, error) {
resBlocks := response.Blocks{}
route, err := helpers2.GetRoute(
lib.RouteBlocksGetBlocks,
blockParam.KeyId,
blockParam.Filter,
strconv.Itoa(blockParam.BatchIndex),
strconv.FormatBool(blockParam.WriteOrHigherAcl),
)
if err != nil {
return resBlocks.Blocks, err
}
var req *http.Request
req, err = http.NewRequest(http.MethodGet, route, nil)
if err != nil {
return resBlocks.Blocks, err
}
helpers2.AddUserHeaders(jwtToken, req)
var res *http.Response
res, err = helpers2.MakeRequest(req)
if err != nil {
return resBlocks.Blocks, err
}
defer helpers2.CloseBody(res.Body)
var body []byte
body, err = io.ReadAll(res.Body)
if err != nil {
return resBlocks.Blocks, err
}
err = json.Unmarshal(body, &resBlocks)
if err != nil {
return resBlocks.Blocks, err
}
return resBlocks.Blocks, nil
}