diff --git a/internal/client/client.go b/internal/client/client.go index fa52e3b..a005a76 100644 --- a/internal/client/client.go +++ b/internal/client/client.go @@ -67,10 +67,12 @@ func getAPIEndpoint(endpoint string) string { path = "/ISteamUserStats/GetUserStatsForGame/v0002" case "id": path = "/ISteamUser/ResolveVanityURL/v0001" + case "name": + path = "/ISteamUser/GetPlayerSummaries/v0002" case "news": path = "/ISteamNews/GetNewsForApp/v0002" case "gameInfo": - path = "/IPlayerService/GetOwnedGames/v1" + path = "/IPlayerService/GetOwnedGames/v0001" } return baseUrl + path @@ -89,6 +91,8 @@ func getAPIQueryParams(endpoint string, config *config.Config, req *http.Request q.Add("steamid", config.SteamID) case "id": q.Add("vanityurl", config.SteamName) + case "name": + q.Add("steamids", config.SteamID) case "news": q.Add("maxlength", "240") case "gameInfo": diff --git a/internal/collector/main.go b/internal/collector/main.go index 3ccb42e..1c8db24 100644 --- a/internal/collector/main.go +++ b/internal/collector/main.go @@ -36,6 +36,10 @@ func (collector *collector) Scrape() { collector.collectSteamID() } + if collector.config.SteamName == "" { + collector.collectSteamName() + } + collector.collectAll() for range time.Tick(collector.config.ScrapeInterval) { diff --git a/internal/collector/steam_name.go b/internal/collector/steam_name.go new file mode 100644 index 0000000..1d94985 --- /dev/null +++ b/internal/collector/steam_name.go @@ -0,0 +1,15 @@ +package collector + +import ( + "github.com/kinduff/csgo_exporter/internal/model" + + log "github.com/sirupsen/logrus" +) + +func (collector *collector) collectSteamName() { + PlayerSummaries := model.PlayerSummaries{} + if err := collector.client.DoAPIRequest("name", collector.config, &PlayerSummaries); err != nil { + log.Fatal(err) + } + collector.config.SteamName = PlayerSummaries.Response.Players[0].PersonaName +} diff --git a/internal/model/player_summaries.go b/internal/model/player_summaries.go new file mode 100644 index 0000000..7ab79a0 --- /dev/null +++ b/internal/model/player_summaries.go @@ -0,0 +1,9 @@ +package model + +type PlayerSummaries struct { + Response struct { + Players []struct { + PersonaName string `json:"personaname"` + } `json:"players"` + } `json:"response"` +}