master
Jordan Orelli 10 years ago
commit 4f42e1e21e

@ -0,0 +1,20 @@
package steam
import (
"fmt"
"net/http"
)
// a steam API client, not tied to any particular game
type Client struct {
key string
}
func NewClient(key string) *Client {
return &Client{key: key}
}
func (c *Client) Get(iface, method, version string) (*http.Response, error) {
url := fmt.Sprintf("https://api.steampowered.com/%s/%s/%s/?key=%s", iface, method, version, c.key)
return http.Get(url)
}

@ -0,0 +1,27 @@
package main
import (
"github.com/jordanorelli/steam"
"io"
"net/http"
"os"
)
var commands = map[string]command{
"api-list": command{
handler: func(c *steam.Client) {
dump(c.Get("ISteamWebAPIUtil", "GetSupportedAPIList", "v0001"))
},
},
}
type command struct {
handler func(*steam.Client)
}
func dump(r *http.Response, e error) {
if e != nil {
bail(1, e.Error())
}
io.Copy(os.Stdout, r.Body)
}

@ -0,0 +1,36 @@
package main
import (
"fmt"
"github.com/jordanorelli/steam"
"io"
"os"
)
func bail(code int, t string, args ...interface{}) {
var out io.Writer
if code == 0 {
out = os.Stdout
} else {
out = os.Stderr
}
fmt.Fprintf(out, t+"\n", args...)
os.Exit(code)
}
func main() {
key := os.Getenv("STEAM_KEY")
if key == "" {
bail(1, "no steam key provided. use the environment variable STEAM_KEY to provide an api key")
}
client := steam.NewClient(key)
if len(os.Args) < 2 {
bail(1, "supply a subcommand pl0x")
}
cmd, ok := commands[os.Args[1]]
if !ok {
bail(1, "no such subcommand %s", os.Args[1])
}
cmd.handler(client)
}
Loading…
Cancel
Save