github.com/grokify/go-ringcentral-client@v0.3.31/office/v1/examples/get_message_list/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 main() {
    21  	_, err := config.LoadDotEnv([]string{os.Getenv("ENV_PATH"), "./.env"}, 1)
    22  	if err != nil {
    23  		panic(err)
    24  	}
    25  
    26  	apiClient, err := 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  	if err != nil {
    35  		panic(err)
    36  	}
    37  
    38  	dt, err := time.Parse(time.RFC3339, "2018-01-01T00:00:00Z")
    39  	if err != nil {
    40  		log.Fatal(err)
    41  	}
    42  
    43  	opts := &rc.ListMessagesOpts{
    44  		DateFrom: optional.NewTime(dt)}
    45  
    46  	info, resp, err := apiClient.MessagesApi.ListMessages(
    47  		context.Background(), "~", "~", opts)
    48  	if err != nil {
    49  		panic(err)
    50  	} else if resp.StatusCode >= 300 {
    51  		panic(fmt.Errorf("API Status %v", resp.StatusCode))
    52  	}
    53  	fmtutil.PrintJSON(info)
    54  
    55  	fmt.Println("DONE")
    56  }