github.com/grokify/go-ringcentral-client@v0.3.31/office/v1/examples/message_store/read_all/main.go (about) 1 package main 2 3 import ( 4 "context" 5 "fmt" 6 "log" 7 "os" 8 "time" 9 10 "github.com/antihax/optional" 11 "github.com/grokify/goauth" 12 "github.com/grokify/goauth/authutil" 13 "github.com/grokify/mogo/config" 14 "github.com/grokify/mogo/fmt/fmtutil" 15 16 rc "github.com/grokify/go-ringcentral-client/office/v1/client" 17 ru "github.com/grokify/go-ringcentral-client/office/v1/util" 18 ) 19 20 func getClient() (*rc.APIClient, error) { 21 _, err := config.LoadDotEnv([]string{os.Getenv("ENV_PATH"), "./.env"}, 1) 22 if err != nil { 23 return nil, err 24 } 25 26 return ru.NewApiClientPassword( 27 goauth.CredentialsOAuth2{ 28 ServerURL: os.Getenv("RINGCENTRAL_SERVER_URL"), 29 ClientID: os.Getenv("RINGCENTRAL_CLIENT_ID"), 30 ClientSecret: os.Getenv("RINGCENTRAL_CLIENT_SECRET"), 31 GrantType: authutil.GrantTypePassword, 32 Username: os.Getenv("RINGCENTRAL_USERNAME"), 33 Password: os.Getenv("RINGCENTRAL_PASSWORD")}) 34 } 35 36 func main() { 37 apiClient, err := getClient() 38 if err != nil { 39 panic(err) 40 } 41 42 dt, err := time.Parse(time.RFC3339, "2016-01-01T00:00:00Z") 43 if err != nil { 44 log.Fatal(err) 45 } 46 47 opts := &rc.ListMessagesOpts{ 48 DateFrom: optional.NewTime(dt)} 49 50 info, resp, err := apiClient.MessagesApi.ListMessages( 51 context.Background(), "~", "~", opts) 52 if err != nil { 53 panic(err) 54 } else if resp.StatusCode >= 300 { 55 panic(fmt.Errorf("API Status %v", resp.StatusCode)) 56 } 57 fmtutil.PrintJSON(info) 58 59 fmt.Println("DONE") 60 }