2018-06-20 16:55:53 +00:00
|
|
|
package connectwise
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/base64"
|
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
2018-07-07 00:29:53 +00:00
|
|
|
//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 {
|
2018-06-20 16:55:53 +00:00
|
|
|
Site string
|
|
|
|
Auth string
|
|
|
|
}
|
|
|
|
|
2018-07-08 17:21:07 +00:00
|
|
|
//Count is a struct used for unmarshalling JSON data when using the Count endpoints in Connectwise (eg: counting number of companies)
|
2018-07-08 06:59:32 +00:00
|
|
|
type Count struct {
|
|
|
|
Count int `json:"count"`
|
|
|
|
}
|
|
|
|
|
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-07-07 00:29:53 +00:00
|
|
|
func NewSite(site string, publicKey string, privateKey string, company string) *Site {
|
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)
|
|
|
|
|
2018-07-07 00:29:53 +00:00
|
|
|
cwSite := Site{Site: site, Auth: authString}
|
2018-06-20 16:55:53 +00:00
|
|
|
|
|
|
|
return &cwSite
|
|
|
|
}
|