added slapapi
This commit is contained in:
49
pkg/slapshotapi/slapid.go
Normal file
49
pkg/slapshotapi/slapid.go
Normal file
@@ -0,0 +1,49 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user