From bcd00e802e6ef8243a2d622c31355e359d45f8ba Mon Sep 17 00:00:00 2001 From: Jordan Orelli Date: Thu, 10 Sep 2015 17:33:42 -0400 Subject: [PATCH] add api-interfaces command --- cmd/steam/api.go | 61 +++++++++++++++++++++++++++++++++++++++++++ cmd/steam/commands.go | 10 +------ 2 files changed, 62 insertions(+), 9 deletions(-) create mode 100644 cmd/steam/api.go diff --git a/cmd/steam/api.go b/cmd/steam/api.go new file mode 100644 index 0000000..0ce1dcb --- /dev/null +++ b/cmd/steam/api.go @@ -0,0 +1,61 @@ +package main + +import ( + "encoding/json" + "fmt" + "github.com/jordanorelli/steam" +) + +type ApiList struct { + Interfaces []Interface `json:"interfaces"` +} + +type Interface struct { + Name string `json:"name"` + Methods []Method `json:"methods"` +} + +type Method struct { + Name string `json:"name"` + Version int `json:"version"` + HttpMethod string `json:"httpmethod"` + Params []Param `json:"parameters"` +} + +type Param struct { + Name string `json:"name"` + Type string `json:"type"` + Optional bool `json:"optional"` + Description string `json:"description"` +} + +var cmd_api_list = command{ + help: ` +retrieves the list of currently supported api endpoints from steam and dumps +out the raw json +`, + handler: func(c *steam.Client, args ...string) { + dump(c.Get("ISteamWebAPIUtil", "GetSupportedAPIList", "v0001")) + }, +} + +var cmd_api_interfaces = command{ + help: ` +retrieves the list of currently supported api interfaces from steam +`, + handler: func(c *steam.Client, args ...string) { + res, err := c.Get("ISteamWebAPIUtil", "GetSupportedAPIList", "v0001") + if err != nil { + bail(1, "error: %s", err) + } + var response struct { + ApiList ApiList `json:"apilist"` + } + if err := json.NewDecoder(res.Body).Decode(&response); err != nil { + bail(1, "error parsing response: %s", err) + } + for _, i := range response.ApiList.Interfaces { + fmt.Println(i.Name) + } + }, +} diff --git a/cmd/steam/commands.go b/cmd/steam/commands.go index 2268641..663557f 100644 --- a/cmd/steam/commands.go +++ b/cmd/steam/commands.go @@ -16,6 +16,7 @@ var commands map[string]command func init() { commands = map[string]command{ "api-list": cmd_api_list, + "api-interfaces": cmd_api_interfaces, "user-friends": cmd_user_friends, "user-id": cmd_user_id, "user-details": cmd_user_details, @@ -57,15 +58,6 @@ retrieves info about a specific command } } -var cmd_api_list = command{ - help: ` -retrieves the list of currently supported api endpoints from steam -`, - handler: func(c *steam.Client, args ...string) { - dump(c.Get("ISteamWebAPIUtil", "GetSupportedAPIList", "v0001")) - }, -} - var cmd_user_friends = command{ help: ` retrieves the provided user's list of friends