forked from nicklaw5/helix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbits.go
51 lines (43 loc) · 1.44 KB
/
bits.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
package helix
import "time"
// UserBitTotal ...
type UserBitTotal struct {
UserID string `json:"user_id"`
UserName string `json:"user_name"`
Rank int `json:"rank"`
Score int `json:"score"`
}
// ManyUserBitTotals ...
type ManyUserBitTotals struct {
Total int `json:"total"`
DateRange DateRange `json:"date_range"`
UserBitTotals []UserBitTotal `json:"data"`
}
// BitsLeaderboardResponse ...
type BitsLeaderboardResponse struct {
ResponseCommon
Data ManyUserBitTotals
}
// BitsLeaderboardParams ...
type BitsLeaderboardParams struct {
Count int `query:"count,10"` // Maximum 100
Period string `query:"period,all"` // "all" (default), "day", "week", "month" and "year"
StartedAt time.Time `query:"started_at"`
UserID string `query:"user_id"`
}
// GetBitsLeaderboard gets a ranked list of Bits leaderboard
// information for an authorized broadcaster.
//
// Required Scope: bits:read
func (c *Client) GetBitsLeaderboard(params *BitsLeaderboardParams) (*BitsLeaderboardResponse, error) {
resp, err := c.get("/bits/leaderboard", &ManyUserBitTotals{}, params)
if err != nil {
return nil, err
}
bits := &BitsLeaderboardResponse{}
resp.HydrateResponseCommon(&bits.ResponseCommon)
bits.Data.Total = resp.Data.(*ManyUserBitTotals).Total
bits.Data.DateRange = resp.Data.(*ManyUserBitTotals).DateRange
bits.Data.UserBitTotals = resp.Data.(*ManyUserBitTotals).UserBitTotals
return bits, nil
}