Browse Source

Add UserLookup()

main
Sam 5 years ago
parent
commit
c2f6e6954d
  1. 21
      keybase.go
  2. 59
      types.go

21
keybase.go

@ -2,7 +2,9 @@ package keybase @@ -2,7 +2,9 @@ package keybase
import (
"encoding/json"
"fmt"
"os/exec"
"strings"
)
// Possible MemberTypes
@ -115,3 +117,22 @@ func (k *Keybase) version() string { @@ -115,3 +117,22 @@ func (k *Keybase) version() string {
return string(cmdOut)
}
// UserLookup pulls information about users.
// The following fields are currently returned: basics, profile, proofs_summary
// See https://keybase.io/docs/api/1.0/call/user/lookup for more info
func (k *Keybase) UserLookup(users ...string) (UserAPI, error) {
var fields = []string{"basics", "profile", "proofs_summary"}
cmdOut, err := k.Exec("apicall", "--arg", fmt.Sprintf("usernames=%s", strings.Join(users, ",")), "--arg", fmt.Sprintf("fields=%s", strings.Join(fields, ",")), "user/lookup")
if err != nil {
return UserAPI{}, err
}
var r UserAPI
if err := json.Unmarshal(cmdOut, &r); err != nil {
return UserAPI{}, err
}
return r, nil
}

59
types.go

@ -597,6 +597,64 @@ type tResult struct { @@ -597,6 +597,64 @@ type tResult struct {
Showcase showcase `json:"showcase"`
}
// UserAPI holds information received to the userlookup api
type UserAPI struct {
Status uStatus `json:"status"`
Them []them `json:"them"`
}
type uStatus struct {
Code int `json:"code"`
Name string `json:"name"`
}
type basics struct {
Ctime int `json:"ctime"`
EldestSeqno int `json:"eldest_seqno"`
IDVersion int `json:"id_version"`
LastIDChange int `json:"last_id_change"`
Mtime int `json:"mtime"`
PassphraseGeneration int `json:"passphrase_generation"`
RandomPw bool `json:"random_pw"`
Salt string `json:"salt"`
Status int `json:"status"`
TrackVersion int `json:"track_version"`
Username string `json:"username"`
UsernameCased string `json:"username_cased"`
}
type profile struct {
Bio string `json:"bio"`
FullName string `json:"full_name"`
Location string `json:"location"`
Mtime int `json:"mtime"`
}
type proof struct {
HumanURL string `json:"human_url"`
Nametag string `json:"nametag"`
PresentationGroup string `json:"presentation_group"`
PresentationTag string `json:"presentation_tag"`
ProofID string `json:"proof_id"`
ProofType string `json:"proof_type"`
ProofURL string `json:"proof_url"`
ServiceURL string `json:"service_url"`
SigID string `json:"sig_id"`
State int `json:"state"`
}
type proofsSummary struct {
All []proof `json:"all"`
HasWeb bool `json:"has_web"`
}
type them struct {
Basics basics `json:"basics,omitempty"`
ID string `json:"id"`
Profile profile `json:"profile,omitempty"`
ProofsSummary proofsSummary `json:"proofs_summary"`
}
// Keybase holds basic information about the local Keybase executable
type Keybase struct {
Path string
@ -673,6 +731,7 @@ type keybase interface { @@ -673,6 +731,7 @@ type keybase interface {
Run(handler func(ChatAPI), options ...RunOptions)
status() status
version() string
UserLookup(users ...string) (UserAPI, error)
}
type status struct {

Loading…
Cancel
Save