github.com/grokify/go-ringcentral-client@v0.3.31/engagedigital/v1/examples/content_all/main.go (about) 1 package main 2 3 import ( 4 "context" 5 "fmt" 6 "log" 7 8 "github.com/antihax/optional" 9 "github.com/jessevdk/go-flags" 10 11 engagedigital "github.com/grokify/go-ringcentral-client/engagedigital/v1/client" 12 ex "github.com/grokify/go-ringcentral-client/engagedigital/v1/examples" 13 utils "github.com/grokify/go-ringcentral-client/engagedigital/v1/util" 14 ) 15 16 type options struct { 17 Site string `short:"s" long:"site" description:"A site" required:"true"` 18 Token string `short:"t" long:"token" description:"A token" required:"true"` 19 Action string `short:"a" long:"action" description:"Action" required:"true"` 20 Update []bool `short:"u" long:"update" description:"Update team"` 21 Id string `short:"i" long:"id" description:"An object id" required:"false"` 22 SourceId string `long:"id2" description:"A source object id" required:"false"` 23 Object string `short:"o" long:"object" description:"An object" required:"false"` 24 } 25 26 func main() { 27 opts := options{} 28 _, err := flags.Parse(&opts) 29 if err != nil { 30 log.Fatal(err) 31 } 32 33 client := utils.NewApiClient(opts.Site, opts.Token) 34 35 switch opts.Action { 36 case "create": 37 if len(opts.SourceId) == 0 { 38 log.Fatal("E_CREATE_NO_SOURCE_ID") 39 } 40 apiOpts := &engagedigital.CreateContentOpts{ 41 SourceId: optional.NewString(opts.SourceId)} 42 apiOpts.To = optional.NewInterface([]string{"demo@example.com"}) 43 apiOpts.Title = optional.NewString("Demo Email") 44 body := "Test Content Body" 45 ex.HandleApiResponse(client.ContentsApi.CreateContent( 46 context.Background(), body, apiOpts)) 47 case "read": 48 if len(opts.Id) > 0 { 49 ex.HandleApiResponse(client.ContentsApi.GetContent(context.Background(), opts.Id)) 50 } else { 51 ex.HandleApiResponse(client.ContentsApi.GetAllContents(context.Background(), nil)) 52 } 53 case "categorizecontent": 54 if len(opts.Id) > 0 { 55 ex.HandleApiResponse(client.ContentsApi.CategorizeContent( 56 context.Background(), opts.Id, []string{"5c8bf22b14bf8a84c44c774c"})) 57 } else { 58 log.Fatal("E_IGNORE_NO_ID") 59 } 60 case "ignore": 61 if len(opts.Id) > 0 { 62 ex.HandleApiResponse(client.ContentsApi.IgnoreContent(context.Background(), opts.Id)) 63 } else { 64 log.Fatal("E_IGNORE_NO_ID") 65 } 66 } 67 68 fmt.Println("DONE") 69 }