/
season_stats.go
117 lines (100 loc) · 3.15 KB
/
season_stats.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package pubg
import (
"encoding/json"
"errors"
"fmt"
"strings"
)
// Notes:
//
// - Use the platform shard when making requests for PC and PS4 players' season stats for seasons after
// division.bro.official.2018-09, and for Xbox season stats for seasons after division.bro.official.2018-08.
// Use the platform-region shard for making any other requests for players' season stats.
//
// - The list of seasons can be queried using both the plaform shard and the platform-region shard.
// Seasons structure.
type Seasons struct {
Data []struct {
// Identifier for this object type ("season")
Type string `json:"type"`
// Season ID. Used to lookup a player's stats for this season on the /players endpoint
ID string `json:"id"`
Attributes struct {
// Indicates if the season is active
IsCurrentSeason bool `json:"isCurrentSeason"`
// Indicates if the season is not active
IsOffseason bool `json:"isOffseason"`
} `json:"attributes"`
} `json:"data"`
Links links `json:"links"`
}
// RankedStatsPlayer structure.
type RankedStatsPlayer struct {
Data rankedStatistics `json:"data"`
Links links `json:"links"`
}
// SeasonStatsPlayer structure.
type SeasonStatsPlayer struct {
Data statistics `json:"data"`
Links links `json:"links"`
}
// SeasonStatsPlayers structure.
type SeasonStatsPlayers struct {
Data []statistics `json:"data"`
Links links `json:"links"`
}
// Seasons returns the list of available seasons.
func (c Client) Seasons(platform Platform) (seasons *Seasons, err error) {
var b []byte
if b, _, err = c.requestGET(platform, "/seasons"); err != nil {
return
}
seasons = &Seasons{}
err = json.Unmarshal(b, seasons)
return
}
// RankedStats returns ranked stats for a single player.
func (c Client) RankedStatsPlayer(platform Platform, seasonID, accountID string) (stats *RankedStatsPlayer, err error) {
var b []byte
b, _, err = c.requestGET(platform, fmt.Sprintf("/players/%s/seasons/%s/ranked", accountID, seasonID))
if err != nil {
return
}
stats = &RankedStatsPlayer{}
err = json.Unmarshal(b, stats)
return
}
// SeasonStatsPlayer returns a season information for a single player.
func (c Client) SeasonStatsPlayer(platform Platform, seasonID, accountID string) (stats *SeasonStatsPlayer, err error) {
var b []byte
b, _, err = c.requestGET(platform, fmt.Sprintf("/players/%s/seasons/%s", accountID, seasonID))
if err != nil {
return
}
stats = &SeasonStatsPlayer{}
err = json.Unmarshal(b, stats)
return
}
// SeasonStatsPlayers returns a season information for up to 10 players.
func (c Client) SeasonStatsPlayers(platform Platform, seasonID string, gameMode GameMode, accountID ...string) (stats *SeasonStatsPlayers, err error) {
var b []byte
if !gameMode.IsValid() {
err = errors.New("Unknown game mode. ")
return
}
if len(accountID) == 0 || len(accountID) > 10 {
err = errors.New("You must specify 1 to 10 players. ")
return
}
b, _, err = c.requestGET(platform,
fmt.Sprintf("/seasons/%s/gameMode/%s/players?filter[playerIds]=%s",
seasonID, gameMode, strings.Join(accountID, ","),
),
)
if err != nil {
return
}
stats = &SeasonStatsPlayers{}
err = json.Unmarshal(b, stats)
return
}