Files
oslstats/pkg/slapshotapi/slapid.go
2026-02-17 08:12:07 +11:00

50 lines
902 B
Go

package slapshotapi
import (
"context"
"encoding/json"
"fmt"
"github.com/pkg/errors"
)
type endpointSteamID struct {
steamID string
}
func getEndpointSteamID(steamID string) *endpointSteamID {
return &endpointSteamID{
steamID: steamID,
}
}
func (ep *endpointSteamID) path() string {
return fmt.Sprintf("/api/public/players/steam/%s", ep.steamID)
}
func (ep *endpointSteamID) method() string {
return "GET"
}
type idresp struct {
ID uint32 `json:"id"`
}
// GetSlapID returns the slapshot ID of the steam user
func (c *SlapAPI) GetSlapID(
ctx context.Context,
steamid string,
) (uint32, error) {
endpoint := getEndpointSteamID(steamid)
data, err := c.request(ctx, endpoint)
if err != nil {
return 0, errors.Wrap(err, "slapapiReq")
}
resp := idresp{}
err = json.Unmarshal(data, &resp)
if err != nil {
return 0, errors.Wrap(err, "json.Unmarshal")
}
return resp.ID, nil
}