diff --git a/README.md b/README.md index 24ce974..5c8b225 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/chessdotcom.go b/chessdotcom.go index 41a3eee..bf30a71 100644 --- a/chessdotcom.go +++ b/chessdotcom.go @@ -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 } } diff --git a/clubs.go b/clubs.go index 6d54bb1..13c9b65 100644 --- a/clubs.go +++ b/clubs.go @@ -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) @@ -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) @@ -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) diff --git a/countries.go b/countries.go index 4cd5835..dd8d843 100644 --- a/countries.go +++ b/countries.go @@ -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) @@ -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) @@ -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) diff --git a/matches.go b/matches.go index 35b0c0d..2bbd7c7 100644 --- a/matches.go +++ b/matches.go @@ -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) @@ -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) @@ -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) @@ -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) diff --git a/misc.go b/misc.go index 78712af..1ec6870 100644 --- a/misc.go +++ b/misc.go @@ -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) @@ -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) diff --git a/puzzles.go b/puzzles.go index 4dd1649..0f7df32 100644 --- a/puzzles.go +++ b/puzzles.go @@ -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) @@ -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) diff --git a/tournaments.go b/tournaments.go index b8d6f69..d257d7f 100644 --- a/tournaments.go +++ b/tournaments.go @@ -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) @@ -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) @@ -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) diff --git a/users.go b/users.go index 45c31ba..51a65e1 100644 --- a/users.go +++ b/users.go @@ -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) @@ -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) @@ -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) @@ -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) @@ -61,11 +61,11 @@ 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) @@ -73,7 +73,7 @@ func GetAllData(username string) UserInfo { } // 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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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)