github.com/grokify/go-ringcentral-client@v0.3.31/office/v1/examples/glip/glip_recent_groups/main.go (about) 1 package main 2 3 import ( 4 "context" 5 "fmt" 6 "log" 7 "os" 8 9 "github.com/caarlos0/env/v11" 10 "github.com/grokify/goauth/authutil" 11 "github.com/grokify/mogo/config" 12 "github.com/grokify/mogo/fmt/fmtutil" 13 "github.com/jessevdk/go-flags" 14 15 rc "github.com/grokify/go-ringcentral-client/office/v1/client" 16 ru "github.com/grokify/go-ringcentral-client/office/v1/util" 17 ) 18 19 type Options struct { 20 SubscriptionId string `short:"s" long:"subscriptionId" description:"SubscriptionId to delete" required:"true"` 21 } 22 23 type RingCentralConfig struct { 24 TokenJSON string `env:"RINGCENTRAL_TOKEN_JSON"` 25 ServerURL string `env:"RINGCENTRAL_SERVER_URL"` 26 WebhookURL string `env:"RINGCENTRAL_WEBHOOK_URL"` 27 } 28 29 // This code takes a bot token and creates a permanent webhook. 30 func main() { 31 opts := &Options{} 32 _, err := flags.Parse(opts) 33 if err != nil { 34 panic(err) 35 } 36 37 _, err = config.LoadDotEnv([]string{os.Getenv("ENV_PATH"), "./.env"}, 1) 38 if err != nil { 39 log.Fatal(err) 40 } 41 42 appCfg := RingCentralConfig{} 43 err = env.Parse(&appCfg) 44 if err != nil { 45 log.Fatal(err) 46 } 47 48 httpClient, err := authutil.NewClientTokenJSON( 49 context.Background(), []byte(appCfg.TokenJSON)) 50 if err != nil { 51 log.Fatal(err) 52 } 53 54 apiClient, err := ru.NewApiClientHttpClientBaseURL( 55 httpClient, appCfg.ServerURL) 56 if err != nil { 57 log.Fatal(err) 58 } 59 60 //msi := map[string]interface{}{} 61 groups, resp, err := apiClient.GlipApi.LoadGroupList(context.Background(), 62 &rc.LoadGroupListOpts{}) 63 if err != nil { 64 log.Fatal(err) 65 } else if resp.StatusCode >= 300 { 66 log.Fatal(fmt.Sprintf("API Status %v", resp.StatusCode)) 67 } 68 69 fmt.Printf("Status: %v\n", resp.StatusCode) 70 71 fmtutil.PrintJSON(groups) 72 73 fmt.Println("DONE") 74 }