First pass at adding Team API stuff
This commit is contained in:
@ -41,6 +41,14 @@ func (k *Keybase) NewChat(channel Channel) Chat {
|
||||
}
|
||||
}
|
||||
|
||||
// NewTeam returns a new Team instance
|
||||
func (k *Keybase) NewTeam(name string) Team {
|
||||
return Team{
|
||||
keybase: k,
|
||||
Name: name,
|
||||
}
|
||||
}
|
||||
|
||||
// username returns the username of the currently logged-in Keybase user.
|
||||
func (k *Keybase) username() string {
|
||||
cmd := exec.Command(k.Path, "status", "-j")
|
||||
|
||||
35
team.go
Normal file
35
team.go
Normal file
@ -0,0 +1,35 @@
|
||||
package keybase
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os/exec"
|
||||
)
|
||||
|
||||
// teamAPIOut sends JSON requests to the team API and returns its response.
|
||||
func teamAPIOut(keybasePath string, w TeamAPI) (TeamAPI, error) {
|
||||
jsonBytes, _ := json.Marshal(w)
|
||||
|
||||
cmd := exec.Command(keybasePath, "team", "api", "-m", string(jsonBytes))
|
||||
cmdOut, err := cmd.Output()
|
||||
if err != nil {
|
||||
return TeamAPI{}, err
|
||||
}
|
||||
|
||||
var r TeamAPI
|
||||
json.Unmarshal(cmdOut, &r)
|
||||
|
||||
return r, nil
|
||||
}
|
||||
|
||||
// CreateSubteam creates a subteam
|
||||
func (t Team) CreateSubteam(name string) (TeamAPI, error) {
|
||||
m := TeamAPI{
|
||||
Params: &tParams{},
|
||||
}
|
||||
m.Method = "create-team"
|
||||
m.Params.Options.Team = fmt.Sprintf("%s.%s", t.Name, name)
|
||||
|
||||
r, err := teamAPIOut(t.keybase.Path, m)
|
||||
return r, err
|
||||
}
|
||||
56
types.go
56
types.go
@ -240,20 +240,6 @@ type SendPayment struct {
|
||||
PaymentID string `json:"paymentID"`
|
||||
}
|
||||
|
||||
// Keybase holds basic information about the local Keybase executable
|
||||
type Keybase struct {
|
||||
Path string
|
||||
Username string
|
||||
LoggedIn bool
|
||||
Version string
|
||||
}
|
||||
|
||||
// Chat holds basic information about a specific conversation
|
||||
type Chat struct {
|
||||
keybase *Keybase
|
||||
Channel Channel
|
||||
}
|
||||
|
||||
// WalletAPI holds data for sending to API
|
||||
type WalletAPI struct {
|
||||
Method string `json:"method,omitempty"`
|
||||
@ -322,6 +308,37 @@ type wResult struct {
|
||||
Unread bool `json:"unread"`
|
||||
}
|
||||
|
||||
// TeamAPI holds information sent and received to/from the team api
|
||||
type TeamAPI struct {
|
||||
Method string `json:"method"`
|
||||
Params *tParams `json:"params"`
|
||||
Result *tResult `json:"result"`
|
||||
}
|
||||
type tOptions struct {
|
||||
Team string `json:"team"`
|
||||
}
|
||||
type tParams struct {
|
||||
Options tOptions `json:"options"`
|
||||
}
|
||||
type tResult struct {
|
||||
ChatSent bool `json:"chatSent"`
|
||||
CreatorAdded bool `json:"creatorAdded"`
|
||||
}
|
||||
|
||||
// Keybase holds basic information about the local Keybase executable
|
||||
type Keybase struct {
|
||||
Path string
|
||||
Username string
|
||||
LoggedIn bool
|
||||
Version string
|
||||
}
|
||||
|
||||
// Chat holds basic information about a specific conversation
|
||||
type Chat struct {
|
||||
keybase *Keybase
|
||||
Channel Channel
|
||||
}
|
||||
|
||||
type chat interface {
|
||||
Send(message ...string) (ChatAPI, error)
|
||||
Edit(messageID int, message ...string) (ChatAPI, error)
|
||||
@ -334,7 +351,18 @@ type chatAPI interface {
|
||||
Previous(count ...int) (*ChatAPI, error)
|
||||
}
|
||||
|
||||
// Team holds basic information about a team
|
||||
type Team struct {
|
||||
keybase *Keybase
|
||||
Name string
|
||||
}
|
||||
|
||||
type team interface {
|
||||
CreateSubteam(name string) (TeamAPI, error)
|
||||
}
|
||||
|
||||
type keybase interface {
|
||||
NewTeam(name string) Team
|
||||
NewChat(channel Channel) Chat
|
||||
Run(handler func(ChatAPI), options ...RunOptions)
|
||||
ChatList() ([]conversation, error)
|
||||
|
||||
Reference in New Issue
Block a user