forked from nicklaw5/helix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
entitlement_codes.go
69 lines (57 loc) · 2.34 KB
/
entitlement_codes.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
package helix
type EntitlementCodeStatus string
const (
SUCCESSFULLY_REDEEMED EntitlementCodeStatus = "SUCCESSFULLY_REDEEMED"
ALREADY_CLAIMED = "ALREADY_CLAIMED"
EXPIRED = "EXPIRED"
USER_NOT_ELIGIBLE = "USER_NOT_ELIGIBLE"
NOT_FOUND = "NOT_FOUND"
INACTIVE = "INACTIVE"
UNUSED = "UNUSED"
INCORRECT_FORMAT = "INCORRECT_FORMAT"
INTERNAL_ERROR = "INTERNAL_ERROR"
)
type CodesParams struct {
// One of the below
UserID string `query:"user_id"`
Codes []string `query:"code"` // Limit 20
}
type CodeStatus struct {
Code string `json:"code"`
Status EntitlementCodeStatus `json:"status"`
}
type ManyCodes struct {
Codes []CodeStatus `json:"data"`
}
type CodeResponse struct {
ResponseCommon
Data ManyCodes
}
// GetEntitlementCodeStatus
// Per https://dev.twitch.tv/docs/api/reference#get-code-status
// Access is controlled via an app access token on the calling service. The client ID associated with the app access token must be approved by Twitch as part of a contracted arrangement.
// Callers with an app access token are authorized to redeem codes on behalf of any Twitch user account.
func (c *Client) GetEntitlementCodeStatus(params *CodesParams) (*CodeResponse, error) {
resp, err := c.get("/entitlements/codes", &ManyCodes{}, params)
if err != nil {
return nil, err
}
codes := &CodeResponse{}
resp.HydrateResponseCommon(&codes.ResponseCommon)
codes.Data.Codes = resp.Data.(*ManyCodes).Codes
return codes, nil
}
// RedeemEntitlementCode
// Per https://dev.twitch.tv/docs/api/reference/#redeem-code
// Access is controlled via an app access token on the calling service. The client ID associated with the app access token must be approved by Twitch.
// Callers with an app access token are authorized to redeem codes on behalf of any Twitch user account.
func (c *Client) RedeemEntitlementCode(params *CodesParams) (*CodeResponse, error) {
resp, err := c.post("/entitlements/code", &ManyCodes{}, params)
if err != nil {
return nil, err
}
codes := &CodeResponse{}
resp.HydrateResponseCommon(&codes.ResponseCommon)
codes.Data.Codes = resp.Data.(*ManyCodes).Codes
return codes, nil
}