github.com/keybase/client/go@v0.0.0-20240309051027-028f7c731f8b/engine/team_blocks_get.go (about)

     1  package engine
     2  
     3  import (
     4  	"github.com/keybase/client/go/libkb"
     5  	keybase1 "github.com/keybase/client/go/protocol/keybase1"
     6  )
     7  
     8  type TeamBlocksGet struct {
     9  	libkb.Contextified
    10  
    11  	blocks []keybase1.TeamBlock
    12  }
    13  
    14  func NewTeamBlocksGet(g *libkb.GlobalContext) *TeamBlocksGet {
    15  	return &TeamBlocksGet{
    16  		Contextified: libkb.NewContextified(g),
    17  	}
    18  }
    19  
    20  // Name is the unique engine name.
    21  func (e *TeamBlocksGet) Name() string {
    22  	return "TeamBlocksGet"
    23  }
    24  
    25  // GetPrereqs returns the engine prereqs.
    26  func (e *TeamBlocksGet) Prereqs() Prereqs {
    27  	return Prereqs{}
    28  }
    29  
    30  // RequiredUIs returns the required UIs.
    31  func (e *TeamBlocksGet) RequiredUIs() []libkb.UIKind {
    32  	return []libkb.UIKind{}
    33  }
    34  
    35  // SubConsumers returns the other UI consumers for this engine.
    36  func (e *TeamBlocksGet) SubConsumers() []libkb.UIConsumer {
    37  	return nil
    38  }
    39  
    40  // Run starts the engine.
    41  func (e *TeamBlocksGet) Run(mctx libkb.MetaContext) (err error) {
    42  	defer mctx.Trace("TeamBlocksGet#Run", &err)()
    43  	apiArg := libkb.APIArg{
    44  		Endpoint:    "team/blocks",
    45  		SessionType: libkb.APISessionTypeREQUIRED,
    46  	}
    47  
    48  	type getBlockResult struct {
    49  		libkb.AppStatusEmbed
    50  		TeamBlocks []keybase1.TeamBlock `json:"team_blocks"`
    51  	}
    52  
    53  	var apiRes getBlockResult
    54  	err = mctx.G().API.GetDecode(mctx, apiArg, &apiRes)
    55  	if err != nil {
    56  		return err
    57  	}
    58  
    59  	e.blocks = apiRes.TeamBlocks
    60  
    61  	return nil
    62  }
    63  
    64  func (e *TeamBlocksGet) Blocks() []keybase1.TeamBlock {
    65  	return e.blocks
    66  }