github.com/grokify/go-ringcentral-client@v0.3.31/engagedigital/v1/examples/intervention-comment_all/main.go (about)

     1  package main
     2  
     3  import (
     4  	"context"
     5  	"fmt"
     6  	"log"
     7  
     8  	"github.com/jessevdk/go-flags"
     9  
    10  	ex "github.com/grokify/go-ringcentral-client/engagedigital/v1/examples"
    11  	utils "github.com/grokify/go-ringcentral-client/engagedigital/v1/util"
    12  )
    13  
    14  type options struct {
    15  	Site   string `short:"s" long:"site" description:"A site" required:"true"`
    16  	Token  string `short:"t" long:"token" description:"A token" required:"true"`
    17  	Action string `short:"a" long:"action" description:"Action" required:"true"`
    18  	Update []bool `short:"u" long:"update" description:"Update team"`
    19  	Id     string `short:"i" long:"id" description:"An object id" required:"false"`
    20  	Id2    string `long:"id2" description:"A source object id" required:"false"`
    21  	Object string `short:"o" long:"object" description:"An object" required:"false"`
    22  }
    23  
    24  func main() {
    25  	opts := options{}
    26  	_, err := flags.Parse(&opts)
    27  	if err != nil {
    28  		log.Fatal(err)
    29  	}
    30  
    31  	client := utils.NewApiClient(opts.Site, opts.Token)
    32  
    33  	switch opts.Action {
    34  	case "create":
    35  		if len(opts.Id) > 0 && len(opts.Id2) > 0 {
    36  			body := "Let's intervene here!"
    37  			ex.HandleApiResponse(client.InterventionCommentsApi.CreateInterventionComment(
    38  				context.Background(), body, opts.Id, opts.Id2))
    39  		} else {
    40  			log.Fatal("E_CREATE_INTERVENTION_ID_USER_ID")
    41  		}
    42  	case "delete":
    43  		if len(opts.Id) > 0 {
    44  			ex.HandleApiResponse(client.InterventionCommentsApi.DeleteInterventionComment(
    45  				context.Background(), opts.Id))
    46  		} else {
    47  			log.Fatal("E_CREATE_NO_INTERVENTION_COMMENT_ID")
    48  		}
    49  	case "read":
    50  		if len(opts.Id) > 0 {
    51  			ex.HandleApiResponse(client.InterventionCommentsApi.GetInterventionComment(context.Background(), opts.Id))
    52  		} else {
    53  			ex.HandleApiResponse(client.InterventionCommentsApi.GetAllInterventionComments(context.Background(), nil))
    54  		}
    55  	}
    56  
    57  	fmt.Println("DONE")
    58  }