Skip to content

Commit

Permalink
Add SC2 ladder game data API (#22)
Browse files Browse the repository at this point in the history
* Add SC2 ladder game data API

* Change TestSC2LadderData test data to US region
  • Loading branch information
w1ck3dg0ph3r authored Jan 26, 2021
1 parent 5ebc834 commit e9ce9fb
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 0 deletions.
23 changes: 23 additions & 0 deletions v2/sc2gd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
45 changes: 45 additions & 0 deletions v2/sc2gd/ladder.go
Original file line number Diff line number Diff line change
@@ -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"`
}
12 changes: 12 additions & 0 deletions v2/sc2gd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

0 comments on commit e9ce9fb

Please sign in to comment.