Browse Source

Update comments for documentation

main
Sam 6 years ago
parent
commit
c182fe7e44
  1. 6
      chatIn.go
  2. 20
      chatOut.go
  3. 10
      keybase.go
  4. 14
      wallet.go

6
chatIn.go

@ -7,6 +7,7 @@ import (
"time" "time"
) )
// ChatIn holds information about a message received by the `keybase chat api-listen` command
type ChatIn struct { type ChatIn struct {
Type string `json:"type"` Type string `json:"type"`
Source string `json:"source"` Source string `json:"source"`
@ -147,7 +148,7 @@ func createFiltersString(channels []Channel) string {
return string(jsonBytes) return string(jsonBytes)
} }
// Get new messages coming into keybase and send them into the channel // Run `keybase chat api-listen` to get new messages coming into keybase and send them into the channel
func getNewMessages(k Keybase, c chan<- ChatIn, execOptions []string) { func getNewMessages(k Keybase, c chan<- ChatIn, execOptions []string) {
execString := []string{"chat", "api-listen"} execString := []string{"chat", "api-listen"}
if len(execOptions) > 0 { if len(execOptions) > 0 {
@ -169,7 +170,7 @@ func getNewMessages(k Keybase, c chan<- ChatIn, execOptions []string) {
} }
} }
// Run() runs keybase chat api-listen, and passes incoming messages to the message handler func // Run runs `keybase chat api-listen`, and passes incoming messages to the message handler func
func (k Keybase) Run(handler func(ChatIn), options ...RunOptions) { func (k Keybase) Run(handler func(ChatIn), options ...RunOptions) {
var heartbeatFreq int64 var heartbeatFreq int64
runOptions := make([]string, 0) runOptions := make([]string, 0)
@ -206,6 +207,7 @@ func (k Keybase) Run(handler func(ChatIn), options ...RunOptions) {
} }
} }
// heartbeat sends a message through the channel with a message type of `heartbeat`
func heartbeat(c chan<- ChatIn, freq time.Duration) { func heartbeat(c chan<- ChatIn, freq time.Duration) {
m := ChatIn{ m := ChatIn{
Type: "heartbeat", Type: "heartbeat",

20
chatOut.go

@ -6,7 +6,7 @@ import (
"strings" "strings"
) )
// ---- Struct for sending to API // chatOut holds data to be sent to the Chat API
type chatOut struct { type chatOut struct {
Method string `json:"method"` Method string `json:"method"`
Params chatOutParams `json:"params"` Params chatOutParams `json:"params"`
@ -30,9 +30,7 @@ type chatOutParams struct {
Options chatOutOptions `json:"options"` Options chatOutOptions `json:"options"`
} }
// ---- // chatOutResult holds data received after sending to API
// ---- Struct for data received after sending to API
type chatOutResult struct { type chatOutResult struct {
Result ChatOut `json:"result"` Result ChatOut `json:"result"`
} }
@ -58,9 +56,7 @@ type ChatOut struct {
Offline bool `json:"offline,omitempty"` Offline bool `json:"offline,omitempty"`
} }
// ---- // chatAPIOut sends JSON requests to the chat API and returns its response.
// chatAPIOut() sends JSON requests to the chat API and returns its response.
func chatAPIOut(keybasePath string, c chatOut) (chatOutResult, error) { func chatAPIOut(keybasePath string, c chatOut) (chatOutResult, error) {
jsonBytes, _ := json.Marshal(c) jsonBytes, _ := json.Marshal(c)
@ -76,7 +72,7 @@ func chatAPIOut(keybasePath string, c chatOut) (chatOutResult, error) {
return r, nil return r, nil
} }
// Send() sends a chat message // Send sends a chat message
func (c Chat) Send(message ...string) (ChatOut, error) { func (c Chat) Send(message ...string) (ChatOut, error) {
m := chatOut{} m := chatOut{}
m.Method = "send" m.Method = "send"
@ -90,7 +86,7 @@ func (c Chat) Send(message ...string) (ChatOut, error) {
return r.Result, nil return r.Result, nil
} }
// Edit() edits a previously sent chat message // Edit edits a previously sent chat message
func (c Chat) Edit(messageId int, message ...string) (ChatOut, error) { func (c Chat) Edit(messageId int, message ...string) (ChatOut, error) {
m := chatOut{} m := chatOut{}
m.Method = "edit" m.Method = "edit"
@ -105,7 +101,7 @@ func (c Chat) Edit(messageId int, message ...string) (ChatOut, error) {
return r.Result, nil return r.Result, nil
} }
// React() sends a reaction to a message. // React sends a reaction to a message.
func (c Chat) React(messageId int, reaction string) (ChatOut, error) { func (c Chat) React(messageId int, reaction string) (ChatOut, error) {
m := chatOut{} m := chatOut{}
m.Method = "reaction" m.Method = "reaction"
@ -120,7 +116,7 @@ func (c Chat) React(messageId int, reaction string) (ChatOut, error) {
return r.Result, nil return r.Result, nil
} }
// Delete() deletes a chat message // Delete deletes a chat message
func (c Chat) Delete(messageId int) (ChatOut, error) { func (c Chat) Delete(messageId int) (ChatOut, error) {
m := chatOut{} m := chatOut{}
m.Method = "delete" m.Method = "delete"
@ -134,7 +130,7 @@ func (c Chat) Delete(messageId int) (ChatOut, error) {
return r.Result, nil return r.Result, nil
} }
// ChatList() returns a list of all conversations. // ChatList returns a list of all conversations.
func (k Keybase) ChatList() ([]conversation, error) { func (k Keybase) ChatList() ([]conversation, error) {
m := chatOut{} m := chatOut{}
m.Method = "list" m.Method = "list"

10
keybase.go

@ -52,7 +52,7 @@ type status struct {
LoggedIn bool `json:"LoggedIn"` LoggedIn bool `json:"LoggedIn"`
} }
// New() returns a new instance of Keybase object. Optionally, you can pass a string containing the path to the Keybase executable as the first argument. // NewKeybase returns a new Keybase. Optionally, you can pass a string containing the path to the Keybase executable as the first argument.
func NewKeybase(path ...string) Keybase { func NewKeybase(path ...string) Keybase {
k := Keybase{} k := Keybase{}
if len(path) < 1 { if len(path) < 1 {
@ -68,7 +68,7 @@ func NewKeybase(path ...string) Keybase {
return k return k
} }
// Return a new Chat instance // NewChat returns a new Chat instance
func (k Keybase) NewChat(channel Channel) Chat { func (k Keybase) NewChat(channel Channel) Chat {
return Chat{ return Chat{
keybase: k, keybase: k,
@ -76,7 +76,7 @@ func (k Keybase) NewChat(channel Channel) Chat {
} }
} }
// 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")
cmdOut, err := cmd.Output() cmdOut, err := cmd.Output()
@ -90,7 +90,7 @@ func (k Keybase) username() string {
return s.Username return s.Username
} }
// loggedIn() returns true if Keybase is currently logged in, otherwise returns false. // loggedIn returns true if Keybase is currently logged in, otherwise returns false.
func (k Keybase) loggedIn() bool { func (k Keybase) loggedIn() bool {
cmd := exec.Command(k.Path, "status", "-j") cmd := exec.Command(k.Path, "status", "-j")
cmdOut, err := cmd.Output() cmdOut, err := cmd.Output()
@ -104,7 +104,7 @@ func (k Keybase) loggedIn() bool {
return s.LoggedIn return s.LoggedIn
} }
// version() returns the version string of the client. // version returns the version string of the client.
func (k Keybase) version() string { func (k Keybase) version() string {
cmd := exec.Command(k.Path, "version", "-S", "-f", "s") cmd := exec.Command(k.Path, "version", "-S", "-f", "s")
cmdOut, err := cmd.Output() cmdOut, err := cmd.Output()

14
wallet.go

@ -5,7 +5,7 @@ import (
"os/exec" "os/exec"
) )
// ---- Struct for sending to API //walletOut holds data for sending to API
type walletOut struct { type walletOut struct {
Method string `json:"method"` Method string `json:"method"`
Params walletOutParams `json:"params"` Params walletOutParams `json:"params"`
@ -18,9 +18,7 @@ type walletOutParams struct {
Options walletOutOptions `json:"options"` Options walletOutOptions `json:"options"`
} }
// ---- // walletOutResult holds data data received after sending to API
// ---- Struct for data received after sending to API
type walletOutResult struct { type walletOutResult struct {
Result WalletResult `json:"result"` Result WalletResult `json:"result"`
} }
@ -78,9 +76,7 @@ type WalletResult struct {
Unread bool `json:"unread"` Unread bool `json:"unread"`
} }
// ---- // walletAPIOut sends JSON requests to the wallet API and returns its response.
// walletAPIOut() sends JSON requests to the wallet API and returns its response.
func walletAPIOut(keybasePath string, w walletOut) (walletOutResult, error) { func walletAPIOut(keybasePath string, w walletOut) (walletOutResult, error) {
jsonBytes, _ := json.Marshal(w) jsonBytes, _ := json.Marshal(w)
@ -96,7 +92,7 @@ func walletAPIOut(keybasePath string, w walletOut) (walletOutResult, error) {
return r, nil return r, nil
} }
// TxDetail() returns details of a stellar transaction // TxDetail returns details of a stellar transaction
func (k Keybase) TxDetail(txid string) (WalletResult, error) { func (k Keybase) TxDetail(txid string) (WalletResult, error) {
m := walletOut{} m := walletOut{}
m.Method = "details" m.Method = "details"
@ -106,7 +102,7 @@ func (k Keybase) TxDetail(txid string) (WalletResult, error) {
return r.Result, err return r.Result, err
} }
// StellarAddress() returns the primary stellar address of a given user // StellarAddress returns the primary stellar address of a given user
func (k Keybase) StellarAddress(user string) (string, error) { func (k Keybase) StellarAddress(user string) (string, error) {
m := walletOut{} m := walletOut{}
m.Method = "lookup" m.Method = "lookup"

Loading…
Cancel
Save