Skip to content

Commit

Permalink
Adds call to fetch player_name from API
Browse files Browse the repository at this point in the history
  • Loading branch information
kinduff committed Jul 1, 2021
1 parent 4a5e68c commit e071f35
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 1 deletion.
6 changes: 5 additions & 1 deletion internal/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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":
Expand Down
4 changes: 4 additions & 0 deletions internal/collector/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
15 changes: 15 additions & 0 deletions internal/collector/steam_name.go
Original file line number Diff line number Diff line change
@@ -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
}
9 changes: 9 additions & 0 deletions internal/model/player_summaries.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package model

type PlayerSummaries struct {
Response struct {
Players []struct {
PersonaName string `json:"personaname"`
} `json:"players"`
} `json:"response"`
}

0 comments on commit e071f35

Please sign in to comment.