forked from grokify/go-ringcentral-client
/
setup.go
39 lines (33 loc) · 1 KB
/
setup.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package examples
import (
"os"
"github.com/joho/godotenv"
rc "github.com/grokify/go-ringcentral/client"
ro "github.com/grokify/oauth2more/ringcentral"
)
func LoadEnv() error {
envPaths := []string{}
if len(os.Getenv("ENV_PATH")) > 0 {
envPaths = append(envPaths, os.Getenv("ENV_PATH"))
}
return godotenv.Load(envPaths...)
}
func NewApiClient() (*rc.APIClient, error) {
httpClient, err := ro.NewClientPassword(
ro.ApplicationCredentials{
ServerURL: os.Getenv("RINGCENTRAL_SERVER_URL"),
ClientID: os.Getenv("RINGCENTRAL_CLIENT_ID"),
ClientSecret: os.Getenv("RINGCENTRAL_CLIENT_SECRET")},
ro.PasswordCredentials{
Username: os.Getenv("RINGCENTRAL_USERNAME"),
Extension: os.Getenv("RINGCENTRAL_EXTENSION"),
Password: os.Getenv("RINGCENTRAL_PASSWORD")})
if err != nil {
return nil, err
}
apiConfig := rc.NewConfiguration()
apiConfig.BasePath = os.Getenv("RINGCENTRAL_SERVER_URL")
apiConfig.HTTPClient = httpClient
apiClient := rc.NewAPIClient(apiConfig)
return apiClient, nil
}