Add CompanyCount method and Count struct to hold return data

This commit is contained in:
Steven Polley 2018-07-08 00:59:32 -06:00
parent d2ec87e7ca
commit 7e94afac9c
2 changed files with 21 additions and 0 deletions

View File

@ -145,6 +145,23 @@ type Company struct {
} `json:"customFields"` } `json:"customFields"`
} }
//CompanyCount returns the number of companies in ConnectWise
func (cw *Site) CompanyCount() (int, error) {
req := NewRequest(cw, "/company/companies/count", "GET", nil)
err := req.Do()
if err != nil {
return 0, fmt.Errorf("request failed for %s: %s", req.RestAction, err)
}
count := &Count{}
err = json.Unmarshal(req.Body, count)
if err != nil {
return 0, fmt.Errorf("failed to unmarshal body into struct: %s", err)
}
return count.Count, nil
}
//GetCompanyByName expects an exact match, perhaps an improvement could be made to support wildcard characters. //GetCompanyByName expects an exact match, perhaps an improvement could be made to support wildcard characters.
//Will return a pointer to a slice of Company's. //Will return a pointer to a slice of Company's.
func (cw *Site) GetCompanyByName(companyName string) (*[]Company, error) { func (cw *Site) GetCompanyByName(companyName string) (*[]Company, error) {

View File

@ -11,6 +11,10 @@ type Site struct {
Auth string Auth string
} }
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 //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 { 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 //The auth string must be formatted in this way when used in requests to the API