Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@ An unofficial, simple, lighweight API wrapper for chess.com written in go
}
```

Complete Documentation can be found at https://pkg.go.dev/github.com/ATTron/chessdotcom-go
Endpoints used as defined at https://www.chess.com/news/view/published-data-api

Complete documentation can be found at https://pkg.go.dev/github.com/ATTron/chessdotcom-go
14 changes: 7 additions & 7 deletions chessdotcom.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@ import (
"github.com/ATTron/chessdotcom-go/util"
)

func processRespJSON(resp *http.Response) (string, error) {
func processRespJSON(resp *http.Response) (map[string]interface{}, error) {
if resp.StatusCode == 200 {
b, _ := ioutil.ReadAll(resp.Body)
var jsonResp map[string]interface{}
err := json.Unmarshal(b, &jsonResp)
util.Check(err)
returnResp, err := json.MarshalIndent(&jsonResp, "", " ")
err := json.Unmarshal([]byte(b), &jsonResp)
util.Check(err)
return string(returnResp), nil
// returnResp, err := json.MarshalIndent(&jsonResp, "", " ")
// util.Check(err)
return jsonResp, nil
} else if resp.StatusCode == 404 {
log.Println("Unable to find the request you are looking for")
return "", util.ErrNotFound
return nil, util.ErrNotFound
} else {
log.Fatal("Could not return valid response from server . . .")
return "", util.ErrBadType
return nil, util.ErrBadType
}
}

Expand Down
6 changes: 3 additions & 3 deletions clubs.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

// GetClub - Returns details about a club
func GetClub(clubID string) string {
func GetClub(clubID string) map[string]interface{} {
reqURL := util.Join(util.CLUB_URL, clubID)
resp, err := http.Get(reqURL)
util.Check(err)
Expand All @@ -19,7 +19,7 @@ func GetClub(clubID string) string {
}

// GetClubMembers - Returns details a specific club members
func GetClubMembers(clubID string) string {
func GetClubMembers(clubID string) map[string]interface{} {
reqURL := util.Join(util.CLUB_URL, clubID, "/members")
resp, err := http.Get(reqURL)
util.Check(err)
Expand All @@ -31,7 +31,7 @@ func GetClubMembers(clubID string) string {
}

// GetClubMatches - Returns club match details
func GetClubMatches(clubID string) string {
func GetClubMatches(clubID string) map[string]interface{} {
reqURL := util.Join(util.CLUB_URL, clubID, "/matches")
resp, err := http.Get(reqURL)
util.Check(err)
Expand Down
6 changes: 3 additions & 3 deletions countries.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

// GetCountry - Returns details about specific country
func GetCountry(countryISO int) string {
func GetCountry(countryISO int) map[string]interface{} {
reqURL := util.Join(util.COUNTRY_URL, strconv.Itoa(countryISO))
resp, err := http.Get(reqURL)
util.Check(err)
Expand All @@ -20,7 +20,7 @@ func GetCountry(countryISO int) string {
}

// GetCountryPlayers - Returns details about specific country's players
func GetCountryPlayers(countryISO int) string {
func GetCountryPlayers(countryISO int) map[string]interface{} {
reqURL := util.Join(util.COUNTRY_URL, strconv.Itoa(countryISO), "/players")
resp, err := http.Get(reqURL)
util.Check(err)
Expand All @@ -32,7 +32,7 @@ func GetCountryPlayers(countryISO int) string {
}

// GetCountryClubs - Returns details about specific country's clubs
func GetCountryClubs(countryISO int) string {
func GetCountryClubs(countryISO int) map[string]interface{} {
reqURL := util.Join(util.COUNTRY_URL, strconv.Itoa(countryISO), "/clubs")
resp, err := http.Get(reqURL)
util.Check(err)
Expand Down
8 changes: 4 additions & 4 deletions matches.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

// GetDailyTeamMatch - Returns daily team match details
func GetDailyTeamMatch(matchID int) string {
func GetDailyTeamMatch(matchID int) map[string]interface{} {
reqURL := util.Join(util.MATCH_URL, strconv.Itoa(matchID))
resp, err := http.Get(reqURL)
util.Check(err)
Expand All @@ -20,7 +20,7 @@ func GetDailyTeamMatch(matchID int) string {
}

// GetDailyTeamMatchBoard - Returns daily team match board details
func GetDailyTeamMatchBoard(matchID int, board int) string {
func GetDailyTeamMatchBoard(matchID int, board int) map[string]interface{} {
reqURL := util.Join(util.MATCH_URL, strconv.Itoa(matchID), "/", strconv.Itoa(board))
resp, err := http.Get(reqURL)
util.Check(err)
Expand All @@ -32,7 +32,7 @@ func GetDailyTeamMatchBoard(matchID int, board int) string {
}

// GetLiveTeamMatch - Returns live team match details
func GetLiveTeamMatch(matchID int) string {
func GetLiveTeamMatch(matchID int) map[string]interface{} {
reqURL := util.Join(util.MATCH_URL, "/live/", strconv.Itoa(matchID))
resp, err := http.Get(reqURL)
util.Check(err)
Expand All @@ -44,7 +44,7 @@ func GetLiveTeamMatch(matchID int) string {
}

// GetLiveTeamMatchBoard - Returns live team match board details
func GetLiveTeamMatchBoard(matchID int, board int) string {
func GetLiveTeamMatchBoard(matchID int, board int) map[string]interface{} {
reqURL := util.Join(util.MATCH_URL, "/live", strconv.Itoa(matchID), "/", strconv.Itoa(board))
resp, err := http.Get(reqURL)
util.Check(err)
Expand Down
4 changes: 2 additions & 2 deletions misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

// GetStreamers - Returns details about chess.com streamers
func GetStreamers() string {
func GetStreamers() map[string]interface{} {
reqURL := util.Join(util.STREAMER_URL)
resp, err := http.Get(reqURL)
util.Check(err)
Expand All @@ -19,7 +19,7 @@ func GetStreamers() string {
}

// GetLeaderboard - Returns details about the chess.com leaderboard
func GetLeaderboard() string {
func GetLeaderboard() map[string]interface{} {
reqURL := util.Join(util.LEADERBOARD_URL)
resp, err := http.Get(reqURL)
util.Check(err)
Expand Down
4 changes: 2 additions & 2 deletions puzzles.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

// GetDailyPuzzle - Returns details about the daily puzzle
func GetDailyPuzzle() string {
func GetDailyPuzzle() map[string]interface{} {
reqURL := util.Join(util.PUZZLE_URL)
resp, err := http.Get(reqURL)
util.Check(err)
Expand All @@ -19,7 +19,7 @@ func GetDailyPuzzle() string {
}

// GetRandomPuzzle - Returns details about a random puzzle
func GetRandomPuzzle() string {
func GetRandomPuzzle() map[string]interface{} {
reqURL := util.Join(util.PUZZLE_URL, "/random")
resp, err := http.Get(reqURL)
util.Check(err)
Expand Down
6 changes: 3 additions & 3 deletions tournaments.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

// GetTournament - Returns tournament details
func GetTournament(tournamentID string) string {
func GetTournament(tournamentID string) map[string]interface{} {
reqURL := util.Join(util.TOURNAMENT_URL, tournamentID)
resp, err := http.Get(reqURL)
util.Check(err)
Expand All @@ -20,7 +20,7 @@ func GetTournament(tournamentID string) string {
}

// GetTournamentRound - Returns tournament round details
func GetTournamentRound(tournamentID string, round int) string {
func GetTournamentRound(tournamentID string, round int) map[string]interface{} {
reqURL := util.Join(util.TOURNAMENT_URL, tournamentID, strconv.Itoa(round))
resp, err := http.Get(reqURL)
util.Check(err)
Expand All @@ -32,7 +32,7 @@ func GetTournamentRound(tournamentID string, round int) string {
}

// GetTournamentRoundGroup - Returns tournament round group details
func GetTournamentRoundGroup(tournamentID string, round int, group int) string {
func GetTournamentRoundGroup(tournamentID string, round int, group int) map[string]interface{} {
reqURL := util.Join(util.TOURNAMENT_URL, tournamentID, strconv.Itoa(round), "/", strconv.Itoa(group))
resp, err := http.Get(reqURL)
util.Check(err)
Expand Down
28 changes: 14 additions & 14 deletions users.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type UserInfo struct {
}

// GetTitledPlayers - Returns an array of all titled players of specific type (i.e. GM, WGM, IM, etc)
func GetTitledPlayers(title string) string {
func GetTitledPlayers(title string) map[string]interface{} {
reqURL := util.Join(util.BASE_URL, "/titled/", title)
resp, err := http.Get(reqURL)
util.Check(err)
Expand All @@ -26,7 +26,7 @@ func GetTitledPlayers(title string) string {
}

// GetUser - Returns basic info about a specific user
func GetUser(username string) string {
func GetUser(username string) map[string]interface{} {
reqURL := util.Join(util.PLAYER_URL, username)
resp, err := http.Get(reqURL)
util.Check(err)
Expand All @@ -38,7 +38,7 @@ func GetUser(username string) string {
}

// GetUserStats - Returns statistics about a specific user
func GetUserStats(username string) string {
func GetUserStats(username string) map[string]interface{} {
reqURL := util.Join(util.PLAYER_URL, username, "/stats")
resp, err := http.Get(reqURL)
util.Check(err)
Expand All @@ -50,7 +50,7 @@ func GetUserStats(username string) string {
}

// GetPlayerStatus (Currently Broken) - Returns T/F of players online status
func GetPlayerStatus(username string) string {
func GetPlayerStatus(username string) map[string]interface{} {
reqURL := util.Join(util.PLAYER_URL, username, "/is-online")
resp, err := http.Get(reqURL)
util.Check(err)
Expand All @@ -61,19 +61,19 @@ func GetPlayerStatus(username string) string {
return returnResp
}

// GetAllData - Return all user info in one object
// GetAllData (Currently not working)- Return all user info in one object
func GetAllData(username string) UserInfo {
UI := UserInfo{}
UI.BasicInfo = GetUser(username)
UI.Stats = GetUserStats(username)
// UI.BasicInfo = GetUser(username)
// UI.Stats = GetUserStats(username)
// currently online status is not working so omitting it here
// UI.OnlineStats = GetPlayerStatus(username)

return UI
}

// GetPlayerGames - Return current user games
func GetPlayerGames(username string) string {
func GetPlayerGames(username string) map[string]interface{} {
reqURL := util.Join(util.PLAYER_URL, username, "/games")
resp, err := http.Get(reqURL)
util.Check(err)
Expand All @@ -85,7 +85,7 @@ func GetPlayerGames(username string) string {
}

// GetPlayerGamesToMove - Return player who has to move
func GetPlayerGamesToMove(username string) string {
func GetPlayerGamesToMove(username string) map[string]interface{} {
reqURL := util.Join(util.PLAYER_URL, username, "/games/to-move")
resp, err := http.Get(reqURL)
util.Check(err)
Expand All @@ -97,7 +97,7 @@ func GetPlayerGamesToMove(username string) string {
}

// GetPlayerGamesMonthly - Return games the player has played in the past month
func GetPlayerGamesMonthly(username string) string {
func GetPlayerGamesMonthly(username string) map[string]interface{} {
reqURL := util.Join(util.PLAYER_URL, username, "/games/archives")
resp, err := http.Get(reqURL)
util.Check(err)
Expand All @@ -109,7 +109,7 @@ func GetPlayerGamesMonthly(username string) string {
}

// GetPlayerArchive - Return games the player has played in a specific month
func GetPlayerGamesArchive(username string, year int, month int) string {
func GetPlayerGamesArchive(username string, year int, month int) map[string]interface{} {
reqURL := util.Join(util.PLAYER_URL, username, "/games/", strconv.Itoa(year), "/", strconv.Itoa(month))
resp, err := http.Get(reqURL)
util.Check(err)
Expand All @@ -121,7 +121,7 @@ func GetPlayerGamesArchive(username string, year int, month int) string {
}

// GetPlayerGamesArchivePGN (Currently broken) - Return games the player has played in a specific month
func GetPlayerGamesArchivePGN(username string, year int, month int) string {
func GetPlayerGamesArchivePGN(username string, year int, month int) map[string]interface{} {
reqURL := util.Join(util.PLAYER_URL, username, "/games/", strconv.Itoa(year), "/", strconv.Itoa(month), "/pgn")
resp, err := http.Get(reqURL)
util.Check(err)
Expand All @@ -133,7 +133,7 @@ func GetPlayerGamesArchivePGN(username string, year int, month int) string {
}

// GetPlayerMatches - Returns list of team matches the player is currently registered in
func GetPlayerMatches(username string) string {
func GetPlayerMatches(username string) map[string]interface{} {
reqURL := util.Join(util.PLAYER_URL, username, "/matches")
resp, err := http.Get(reqURL)
util.Check(err)
Expand All @@ -145,7 +145,7 @@ func GetPlayerMatches(username string) string {
}

// GetPlayerTournaments
func GetPlayerTournaments(username string) string {
func GetPlayerTournaments(username string) map[string]interface{} {
reqURL := util.Join(util.PLAYER_URL, username, "/tournaments")
resp, err := http.Get(reqURL)
util.Check(err)
Expand Down