forked from nicklaw5/helix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextensions.go
99 lines (84 loc) · 3.46 KB
/
extensions.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
88
89
90
91
92
93
94
95
96
97
98
99
package helix
import "fmt"
type ExtensionTransaction struct {
ID string `json:"id"`
Timestamp Time `json:"timestamp"`
BroadcasterID string `json:"broadcaster_id"`
BroadcasterLogin string `json:"broadcaster_login"`
BroadcasterName string `json:"broadcaster_name"`
UserID string `json:"user_id"`
UserLogin string `json:"user_login"`
UserName string `json:"user_name"`
ProductType string `json:"product_type"`
ProductData struct {
Domain string `json:"domain"`
Broadcast bool `json:"broadcast"`
Expiration string `json:"expiration"`
SKU string `json:"sku"`
Cost struct {
Amount int `json:"amount"`
Type string `json:"type"`
} `json:"cost"`
DisplayName string `json:"displayName"`
InDevelopment bool `json:"inDevelopment"`
} `json:"product_data"`
}
type ManyExtensionTransactions struct {
ExtensionTransactions []ExtensionTransaction `json:"data"`
Pagination Pagination `json:"pagination"`
}
type ExtensionTransactionsResponse struct {
ResponseCommon
Data ManyExtensionTransactions
}
type ExtensionTransactionsParams struct {
ExtensionID string `query:"extension_id"` // Required
ID []string `query:"id"` // Optional, Limit 100
After string `query:"after"` // Optional
First int `query:"first,20"` // Optional, Limit 100
}
type ExtensionSendChatMessageParams struct {
BroadcasterID string `query:"broadcaster_id" json:"-"`
Text string `json:"text"` // Limit 280
ExtensionVersion string `json:"extension_version"`
ExtensionID string `json:"extension_id"`
}
type ExtensionSendChatMessageResponse struct {
ResponseCommon
}
// GetExtensionTransactions allows extension back end servers to fetch a list of transactions that
// have occurred for their extension across all of Twitch. A transaction is a record of a user
// exchanging Bits for an in-Extension digital good.
//
// See https://dev.twitch.tv/docs/api/reference/#get-extension-transactions
func (c *Client) GetExtensionTransactions(params *ExtensionTransactionsParams) (*ExtensionTransactionsResponse, error) {
resp, err := c.get("/extensions/transactions", &ManyExtensionTransactions{}, params)
if err != nil {
return nil, err
}
extTxnResp := &ExtensionTransactionsResponse{}
resp.HydrateResponseCommon(&extTxnResp.ResponseCommon)
extTxnResp.Data.ExtensionTransactions = resp.Data.(*ManyExtensionTransactions).ExtensionTransactions
extTxnResp.Data.Pagination = resp.Data.(*ManyExtensionTransactions).Pagination
return extTxnResp, nil
}
// SendExtensionChatMessage Sends a specified chat message to a specified channel.
// The message will appear in the channel’s chat as a normal message,
// The author of the message is the Extension name.
//
// see https://dev.twitch.tv/docs/api/reference#send-extension-chat-message
func (c *Client) SendExtensionChatMessage(params *ExtensionSendChatMessageParams) (*ExtensionSendChatMessageResponse, error) {
if len(params.Text) > 280 {
return nil, fmt.Errorf("error: chat message length exceeds 280 characters")
}
if params.BroadcasterID == "" {
return nil, fmt.Errorf("error: broadcaster ID must be specified")
}
resp, err := c.postAsJSON("/extensions/chat", &ExtensionSendChatMessageResponse{}, params)
if err != nil {
return nil, err
}
sndExtMsgResp := &ExtensionSendChatMessageResponse{}
resp.HydrateResponseCommon(&sndExtMsgResp.ResponseCommon)
return sndExtMsgResp, nil
}