github.com/grokify/go-ringcentral-client@v0.3.31/engagedigital/v1/examples/intervention_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 "cancel": 35 if len(opts.Id) > 0 { 36 ex.HandleApiResponse(client.InterventionsApi.CancelIntervention( 37 context.Background(), opts.Id)) 38 } else { 39 log.Fatal("E_CANCEL_NO_ID") 40 } 41 case "categorize": 42 if len(opts.Id) > 0 && len(opts.Id2) > 0 { 43 ex.HandleApiResponse(client.InterventionsApi.CategorizeIntervention( 44 context.Background(), opts.Id, []string{opts.Id2})) 45 } else { 46 log.Fatal("E_CREATE_NO_INTERVENTION_ID_OR_NO_CONTENT_ID") 47 } 48 case "create": 49 if len(opts.Id) == 0 { 50 log.Fatal("E_CREATE_NO_CONTENT_ID") 51 } 52 ex.HandleApiResponse(client.InterventionsApi.CreateIntervention( 53 context.Background(), opts.Id)) 54 case "close": 55 if len(opts.Id) > 0 { 56 ex.HandleApiResponse(client.InterventionsApi.CloseIntervention( 57 context.Background(), opts.Id)) 58 } else { 59 log.Fatal("E_CREATE_NO_CONTENT_ID") 60 } 61 case "read": 62 if len(opts.Id) > 0 { 63 ex.HandleApiResponse(client.InterventionsApi.GetIntervention(context.Background(), opts.Id)) 64 } else { 65 ex.HandleApiResponse(client.InterventionsApi.GetAllInterventions(context.Background(), nil)) 66 } 67 case "reassign": 68 if len(opts.Id) > 0 && len(opts.Id2) > 0 { 69 ex.HandleApiResponse(client.InterventionsApi.ReassignIntervention( 70 context.Background(), opts.Id, opts.Id2)) 71 } else { 72 log.Fatal("E_REASSIGN_REQUIRE_INTERVENTION_AND_USER_ID") 73 } 74 } 75 76 fmt.Println("DONE") 77 }