-
Notifications
You must be signed in to change notification settings - Fork 1
/
animation.go
71 lines (60 loc) · 1.39 KB
/
animation.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
package govoom
import (
"encoding/base64"
"encoding/json"
"fmt"
)
func (c *Client) ResetSendingAnimationPicId() error {
cmd := "Draw/ResetHttpGifId"
data := map[string]interface{}{
"Command": cmd,
}
resp, err := c.do(data)
if err != nil {
return err
}
defer resp.Body.Close()
return c.validateNoError(resp)
}
type getSendingAnimationPicIDResult struct {
errorCodeResult
PicId int `json:"PicId"`
}
func (c *Client) GetSendingAnimationPicID() (int, error) {
cmd := "Draw/GetHttpGifId"
data := map[string]interface{}{
"Command": cmd,
}
resp, err := c.do(data)
if err != nil {
return -1, err
}
defer resp.Body.Close()
var ret getSendingAnimationPicIDResult
err = json.NewDecoder(resp.Body).Decode(&ret)
if err != nil {
return -1, err
}
if ret.ErrorCode != 0 {
return -1, fmt.Errorf("GetSendingAnimationPicID failed: %d", ret.ErrorCode)
}
return ret.PicId, nil
}
func (c *Client) SendAnimation(animationId int, numPictures int, pictureIndex int, width int, speed int, picData []byte) error {
cmd := "Draw/SendHttpGif"
data := map[string]interface{}{
"Command": cmd,
"PicNum": numPictures,
"PicWidth": width,
"PicOffset": pictureIndex,
"PicID": animationId,
"PicSpeed": speed,
"PicData": base64.StdEncoding.EncodeToString(picData),
}
resp, err := c.do(data)
if err != nil {
return err
}
defer resp.Body.Close()
return c.validateNoError(resp)
}