diff --git a/v2/sc2gd.go b/v2/sc2gd.go index b9a4582..32f5c74 100644 --- a/v2/sc2gd.go +++ b/v2/sc2gd.go @@ -28,3 +28,26 @@ func (c *Client) SC2LeagueData(ctx context.Context, seasonID int, queueID sc2gd. return &dat, b, nil } + +// SC2LadderData returns SC2 ladder for given division's ladderID. +// +// This API is undocumented by Blizzard, so may be unstable. +func (c *Client) SC2LadderData(ctx context.Context, ladderID int) (*sc2gd.Ladder, []byte, error) { + var ( + dat sc2gd.Ladder + b []byte + err error + ) + + b, err = c.getURLBody(ctx, c.apiURL+fmt.Sprintf("/data/sc2/ladder/%d?locale=%s", ladderID, c.locale), "") + if err != nil { + return &dat, b, err + } + + err = json.Unmarshal(b, &dat) + if err != nil { + return &dat, b, err + } + + return &dat, b, nil +} diff --git a/v2/sc2gd/ladder.go b/v2/sc2gd/ladder.go new file mode 100644 index 0000000..4fa660d --- /dev/null +++ b/v2/sc2gd/ladder.go @@ -0,0 +1,45 @@ +package sc2gd + +type Ladder struct { + Team []struct { + ID uint64 `json:"id"` + Rating int `json:"rating"` + Wins int `json:"wins"` + Losses int `json:"losses"` + Ties int `json:"ties"` + Points int `json:"points"` + LongestWinStreak int `json:"longest_win_streak"` + CurrentWinStreak int `json:"current_win_streak"` + CurrentRank int `json:"current_rank"` + HighestRank int `json:"highest_rank"` + PreviousRank int `json:"previous_rank"` + JoinTimeStamp int `json:"join_time_stamp"` + LastPlayedTimeStamp int `json:"last_played_time_stamp"` + Member []struct { + LegacyLink struct { + ID int `json:"id"` + Realm int `json:"realm"` + Name string `json:"name"` + Path string `json:"path"` + } `json:"legacy_link"` + PlayedRaceCount []struct { + Race string `json:"race"` + Count int `json:"count"` + } `json:"played_race_count"` + CharacterLink struct { + ID int `json:"id"` + BattleTag string `json:"battle_tag"` + Key struct { + Href string `json:"href"` + } `json:"key"` + } `json:"character_link"` + ClanLink struct { + ID int `json:"id"` + ClanTag string `json:"clan_tag"` + ClanName string `json:"clan_name"` + IconURL string `json:"icon_url"` + DecalURL string `json:"decal_url"` + } `json:"clan_link"` + } `json:"member"` + } `json:"team"` +} diff --git a/v2/sc2gd_test.go b/v2/sc2gd_test.go index 1b04050..a4bd211 100644 --- a/v2/sc2gd_test.go +++ b/v2/sc2gd_test.go @@ -19,3 +19,15 @@ func TestSC2LeagueData(t *testing.T) { fmt.Printf("%+v\n", dat) } } + +func TestSC2LadderData(t *testing.T) { + dat, _, err := c.SC2LadderData(context.Background(), 292787) + if err != nil { + fmt.Println(err) + t.Fail() + } + + if printOutput != "" { + fmt.Printf("%+v\n", dat) + } +}