-
Notifications
You must be signed in to change notification settings - Fork 3
/
crd_ice_breakers.go
87 lines (69 loc) · 2.18 KB
/
crd_ice_breakers.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
86
87
package instabot
import (
"bytes"
"context"
"encoding/json"
"io"
"net/url"
)
func encodeSetIceBreakersJSON(w io.Writer, iceBreakers []*IceBreaker) error {
enc := json.NewEncoder(w)
return enc.Encode(&struct {
Platform string `json:"platform"`
IceBreakers []*IceBreaker `json:"ice_breakers"`
}{
Platform: Platform,
IceBreakers: iceBreakers,
})
}
// SetIceBreakers sets a instagram account ice breakers.
// https://developers.facebook.com/docs/messenger-platform/instagram/features/ice-breakers#setting-ice-breakers
func (c *Client) SetIceBreakers(ctx context.Context, iceBreakers []*IceBreaker) (*SetIceBreakersResponse, error) {
var buf bytes.Buffer
if err := encodeSetIceBreakersJSON(&buf, iceBreakers); err != nil {
return nil, err
}
res, err := c.post(ctx, APIEndpointMessengerProfile, &buf)
if err != nil {
return nil, err
}
defer res.Body.Close()
return decodeToSetIceBreakersResponse(res)
}
// GetIceBreakers fetches ice breakers.
// https://developers.facebook.com/docs/messenger-platform/instagram/features/ice-breakers#getting-ice-breakers
func (c *Client) GetIceBreakers(ctx context.Context) (*GetIceBreakersResponse, error) {
query := url.Values{}
query.Add("fields", "ice_breakers")
query.Add("platform", Platform)
res, err := c.get(ctx, APIEndpointMessengerProfile, query)
if err != nil {
return nil, err
}
defer res.Body.Close()
return decodeToGetIceBreakersResponse(res)
}
func encodeDeletetIceBreakersJSON(w io.Writer) error {
enc := json.NewEncoder(w)
return enc.Encode(&struct {
Fields []string `json:"fields"`
}{
Fields: []string{"ice_breakers"},
})
}
// DeleteIceBreakers deletes ice breakers.
// https://developers.facebook.com/docs/messenger-platform/instagram/features/ice-breakers#deleting-icebreakers
func (c *Client) DeleteIceBreakers(ctx context.Context) (*DeleteIceBreakersResponse, error) {
var buf bytes.Buffer
if err := encodeDeletetIceBreakersJSON(&buf); err != nil {
return nil, err
}
query := url.Values{}
query.Add("platform", Platform)
res, err := c.delete(ctx, APIEndpointMessengerProfile, &buf, query)
if err != nil {
return nil, err
}
defer res.Body.Close()
return decodeToDeleteIceBreakersResponse(res)
}