2018-06-20 16:55:53 +00:00
|
|
|
package connectwise
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/base64"
|
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
2018-06-29 01:35:34 +00:00
|
|
|
//ConnectwiseSite is a stuct containing the URL of the site and the API authorization token in the format that CW expects it.
|
2018-06-20 16:55:53 +00:00
|
|
|
type ConnectwiseSite struct {
|
|
|
|
Site string
|
|
|
|
Auth string
|
|
|
|
}
|
|
|
|
|
2018-06-29 01:35:34 +00:00
|
|
|
//NewSite returns a pointer to a ConnectwiseSite struct with the site and auth string available for use in API requests
|
2018-06-20 16:55:53 +00:00
|
|
|
func NewSite(site string, publicKey string, privateKey string, company string) *ConnectwiseSite {
|
2018-06-23 00:47:39 +00:00
|
|
|
//The auth string must be formatted in this way when used in requests to the API
|
2018-06-20 16:55:53 +00:00
|
|
|
authString := fmt.Sprintf("%s+%s:%s", company, publicKey, privateKey)
|
|
|
|
authString = base64.StdEncoding.EncodeToString([]byte(authString))
|
|
|
|
authString = fmt.Sprintf("Basic %s", authString)
|
|
|
|
|
|
|
|
cwSite := ConnectwiseSite{Site: site, Auth: authString}
|
|
|
|
|
|
|
|
return &cwSite
|
|
|
|
}
|