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.
|
// username returns the username of the currently logged-in Keybase user.
|
||||||
func (k *Keybase) username() string {
|
func (k *Keybase) username() string {
|
||||||
cmd := exec.Command(k.Path, "status", "-j")
|
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"`
|
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
|
// WalletAPI holds data for sending to API
|
||||||
type WalletAPI struct {
|
type WalletAPI struct {
|
||||||
Method string `json:"method,omitempty"`
|
Method string `json:"method,omitempty"`
|
||||||
@ -322,6 +308,37 @@ type wResult struct {
|
|||||||
Unread bool `json:"unread"`
|
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 {
|
type chat interface {
|
||||||
Send(message ...string) (ChatAPI, error)
|
Send(message ...string) (ChatAPI, error)
|
||||||
Edit(messageID int, message ...string) (ChatAPI, error)
|
Edit(messageID int, message ...string) (ChatAPI, error)
|
||||||
@ -334,7 +351,18 @@ type chatAPI interface {
|
|||||||
Previous(count ...int) (*ChatAPI, error)
|
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 {
|
type keybase interface {
|
||||||
|
NewTeam(name string) Team
|
||||||
NewChat(channel Channel) Chat
|
NewChat(channel Channel) Chat
|
||||||
Run(handler func(ChatAPI), options ...RunOptions)
|
Run(handler func(ChatAPI), options ...RunOptions)
|
||||||
ChatList() ([]conversation, error)
|
ChatList() ([]conversation, error)
|
||||||
|
|||||||
Reference in New Issue
Block a user