-
Notifications
You must be signed in to change notification settings - Fork 88
/
analytics.go
85 lines (71 loc) · 2.52 KB
/
analytics.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
package helix
type ExtensionAnalytic struct {
ExtensionID string `json:"extension_id"`
URL string `json:"URL"`
Type string `json:"type"`
DateRange DateRange `json:"date_range"`
}
type ManyExtensionAnalytics struct {
ExtensionAnalytics []ExtensionAnalytic `json:"data"`
Pagination Pagination `json:"pagination"`
}
type ExtensionAnalyticsResponse struct {
ResponseCommon
Data ManyExtensionAnalytics
}
type ExtensionAnalyticsParams struct {
ExtensionID string `query:"extension_id"`
First int `query:"first,20"`
After string `query:"after"`
StartedAt Time `query:"started_at"`
EndedAt Time `query:"ended_at"`
Type string `query:"type"`
}
// GetExtensionAnalytics returns a URL to the downloadable CSV file
// containing analytics data. Valid for 5 minutes.
func (c *Client) GetExtensionAnalytics(params *ExtensionAnalyticsParams) (*ExtensionAnalyticsResponse, error) {
resp, err := c.get("/analytics/extensions", &ManyExtensionAnalytics{}, params)
if err != nil {
return nil, err
}
users := &ExtensionAnalyticsResponse{}
resp.HydrateResponseCommon(&users.ResponseCommon)
users.Data.ExtensionAnalytics = resp.Data.(*ManyExtensionAnalytics).ExtensionAnalytics
users.Data.Pagination = resp.Data.(*ManyExtensionAnalytics).Pagination
return users, nil
}
type GameAnalytic struct {
GameID string `json:"game_id"`
URL string `json:"URL"`
Type string `json:"type"`
DateRange DateRange `json:"date_range"`
}
type ManyGameAnalytics struct {
GameAnalytics []GameAnalytic `json:"data"`
Pagination Pagination `json:"pagination"`
}
type GameAnalyticsResponse struct {
ResponseCommon
Data ManyGameAnalytics
}
type GameAnalyticsParams struct {
GameID string `query:"game_id"`
First int `query:"first,20"`
After string `query:"after"`
StartedAt Time `query:"started_at"`
EndedAt Time `query:"ended_at"`
Type string `query:"type"`
}
// GetGameAnalytics returns a URL to the downloadable CSV file
// containing analytics data for the specified game. Valid for 5 minutes.
func (c *Client) GetGameAnalytics(params *GameAnalyticsParams) (*GameAnalyticsResponse, error) {
resp, err := c.get("/analytics/games", &ManyGameAnalytics{}, params)
if err != nil {
return nil, err
}
users := &GameAnalyticsResponse{}
resp.HydrateResponseCommon(&users.ResponseCommon)
users.Data.GameAnalytics = resp.Data.(*ManyGameAnalytics).GameAnalytics
users.Data.Pagination = resp.Data.(*ManyGameAnalytics).Pagination
return users, nil
}