github.com/grokify/go-ringcentral-client@v0.3.31/engagevoice/v1/util/lite/client.go (about) 1 package lite 2 3 import ( 4 "errors" 5 "net/http" 6 "strings" 7 8 "github.com/grokify/mogo/net/urlutil" 9 ) 10 11 type ClientLite struct { 12 ServerURL string 13 Token string 14 AccountID string 15 HTTPClient *http.Client 16 } 17 18 func NewClientLite(serverURL, accountID, token string) ClientLite { 19 client := ClientLite{ 20 ServerURL: strings.TrimSpace(serverURL), 21 AccountID: strings.TrimSpace(accountID), 22 Token: strings.TrimSpace(token)} 23 client.LoadHTTPClient(client.Token) 24 return client 25 } 26 27 func (lite *ClientLite) LoadHTTPClient(token string) { 28 if len(strings.TrimSpace(token)) == 0 { 29 token = lite.Token 30 } 31 lite.HTTPClient = NewClientToken(token) 32 } 33 34 func (lite *ClientLite) Tokens() ([]string, error) { 35 return ListTokens(lite.ServerURL, lite.Token) 36 } 37 38 /* 39 func NewHTTPClient(token string) *http.Client { 40 return goauth.NewClientHeaderQuery( 41 http.Header{HeaderEngageVoiceToken: []string{token}}, 42 url.Values{}, 43 false) 44 } 45 */ 46 47 func APIInfo(serverURL, urlPath, authOrApiToken string) (http.Header, string, error) { 48 authOrApiToken = strings.TrimSpace(authOrApiToken) 49 if len(authOrApiToken) == 0 { 50 return http.Header{}, "", errors.New("E_NO_TOKEN") 51 } 52 serverURL = strings.TrimSpace(serverURL) 53 if len(serverURL) == 0 { 54 serverURL = EngageVoiceServerURL 55 } 56 apiURL := urlutil.JoinAbsolute(serverURL, urlPath) 57 58 return http.Header(map[string][]string{ 59 HeaderEngageVoiceToken: {authOrApiToken}, 60 }), apiURL, nil 61 }