30 lines
949 B
Go
30 lines
949 B
Go
package connectwise
|
|
|
|
import (
|
|
"encoding/base64"
|
|
"fmt"
|
|
)
|
|
|
|
//Site is a stuct containing the URL of the site and the API authorization token in the format that CW expects it.
|
|
type Site struct {
|
|
Site string
|
|
Auth string
|
|
}
|
|
|
|
//Count is a struct used for unmarshalling JSON data when using the Count endpoints in Connectwise (eg: counting number of companies)
|
|
type Count struct {
|
|
Count int `json:"count"`
|
|
}
|
|
|
|
//NewSite returns a pointer to a ConnectwiseSite struct with the site and auth string available for use in API requests
|
|
func NewSite(site string, publicKey string, privateKey string, company string) *Site {
|
|
//The auth string must be formatted in this way when used in requests to the API
|
|
authString := fmt.Sprintf("%s+%s:%s", company, publicKey, privateKey)
|
|
authString = base64.StdEncoding.EncodeToString([]byte(authString))
|
|
authString = fmt.Sprintf("Basic %s", authString)
|
|
|
|
cwSite := Site{Site: site, Auth: authString}
|
|
|
|
return &cwSite
|
|
}
|