Rename connectwise.ConnectwiseSite to connectwise.Site
This commit is contained in:
parent
d87b8ff4ba
commit
8c79fef71a
@ -158,7 +158,7 @@ func (co *Company) Unmarshal(data *[]byte) error {
|
|||||||
|
|
||||||
//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 *ConnectwiseSite) GetCompanyByName(companyName string) (*[]Company, error) {
|
func (cw *Site) GetCompanyByName(companyName string) (*[]Company, error) {
|
||||||
restAction := "/company/companies"
|
restAction := "/company/companies"
|
||||||
cwurl, err := cw.BuildURL(restAction)
|
cwurl, err := cw.BuildURL(restAction)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -184,7 +184,7 @@ func (cw *ConnectwiseSite) GetCompanyByName(companyName string) (*[]Company, err
|
|||||||
|
|
||||||
//GetCompanyByID expects the Connectwise Company ID and returns a pointer to a Company
|
//GetCompanyByID expects the Connectwise Company ID and returns a pointer to a Company
|
||||||
//Does not return a slice like GetCompanyByName as the ID will only ever have one match
|
//Does not return a slice like GetCompanyByName as the ID will only ever have one match
|
||||||
func (cw *ConnectwiseSite) GetCompanyByID(companyID int) (*Company, error) {
|
func (cw *Site) GetCompanyByID(companyID int) (*Company, error) {
|
||||||
req := NewRequest(cw, fmt.Sprintf("/company/companies/%d", companyID), "GET", nil)
|
req := NewRequest(cw, fmt.Sprintf("/company/companies/%d", companyID), "GET", nil)
|
||||||
err := req.Do()
|
err := req.Do()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -5,20 +5,20 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
//ConnectwiseSite is a stuct containing the URL of the site and the API authorization token in the format that CW expects it.
|
//Site is a stuct containing the URL of the site and the API authorization token in the format that CW expects it.
|
||||||
type ConnectwiseSite struct {
|
type Site struct {
|
||||||
Site string
|
Site string
|
||||||
Auth string
|
Auth string
|
||||||
}
|
}
|
||||||
|
|
||||||
//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) *ConnectwiseSite {
|
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
|
||||||
authString := fmt.Sprintf("%s+%s:%s", company, publicKey, privateKey)
|
authString := fmt.Sprintf("%s+%s:%s", company, publicKey, privateKey)
|
||||||
authString = base64.StdEncoding.EncodeToString([]byte(authString))
|
authString = base64.StdEncoding.EncodeToString([]byte(authString))
|
||||||
authString = fmt.Sprintf("Basic %s", authString)
|
authString = fmt.Sprintf("Basic %s", authString)
|
||||||
|
|
||||||
cwSite := ConnectwiseSite{Site: site, Auth: authString}
|
cwSite := Site{Site: site, Auth: authString}
|
||||||
|
|
||||||
return &cwSite
|
return &cwSite
|
||||||
}
|
}
|
||||||
|
@ -117,7 +117,7 @@ type Agreement struct {
|
|||||||
|
|
||||||
//GetAgreements returns a list of agreements, not paginated and currently not that useful
|
//GetAgreements returns a list of agreements, not paginated and currently not that useful
|
||||||
//TBD: Pagination and filtering options still need to be considered
|
//TBD: Pagination and filtering options still need to be considered
|
||||||
func (cw *ConnectwiseSite) GetAgreements() (*[]Agreement, error) {
|
func (cw *Site) GetAgreements() (*[]Agreement, error) {
|
||||||
restAction := "/finance/agreements"
|
restAction := "/finance/agreements"
|
||||||
cwurl, err := cw.BuildURL(restAction)
|
cwurl, err := cw.BuildURL(restAction)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -140,7 +140,7 @@ func (cw *ConnectwiseSite) GetAgreements() (*[]Agreement, error) {
|
|||||||
|
|
||||||
//GetAgreementsByCompanyName returns a list of agreements that belong to an exact matching company name
|
//GetAgreementsByCompanyName returns a list of agreements that belong to an exact matching company name
|
||||||
//TBD: Pagination and filtering options still need to be considered
|
//TBD: Pagination and filtering options still need to be considered
|
||||||
func (cw *ConnectwiseSite) GetAgreementsByCompanyName(companyName string) (*[]Agreement, error) {
|
func (cw *Site) GetAgreementsByCompanyName(companyName string) (*[]Agreement, error) {
|
||||||
restAction := "/finance/agreements"
|
restAction := "/finance/agreements"
|
||||||
cwurl, err := cw.BuildURL(restAction)
|
cwurl, err := cw.BuildURL(restAction)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -167,7 +167,7 @@ func (cw *ConnectwiseSite) GetAgreementsByCompanyName(companyName string) (*[]Ag
|
|||||||
//GetBillingCycles is not complete
|
//GetBillingCycles is not complete
|
||||||
//TBD: Finish this.
|
//TBD: Finish this.
|
||||||
/*
|
/*
|
||||||
func (cw *ConnectwiseSite) GetBillingCycles() {
|
func (cw *Site) GetBillingCycles() {
|
||||||
restAction := "/finance/billingCycles"
|
restAction := "/finance/billingCycles"
|
||||||
cwurl, err := cw.BuildURL(restAction)
|
cwurl, err := cw.BuildURL(restAction)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -11,7 +11,7 @@ import (
|
|||||||
|
|
||||||
//Request is a struct which holds all information that is collected in order to make a request
|
//Request is a struct which holds all information that is collected in order to make a request
|
||||||
type Request struct {
|
type Request struct {
|
||||||
CW *ConnectwiseSite
|
CW *Site
|
||||||
RestAction string
|
RestAction string
|
||||||
Parameters map[string]string
|
Parameters map[string]string
|
||||||
Method string //GET, POST, DELETE, etc
|
Method string //GET, POST, DELETE, etc
|
||||||
@ -19,7 +19,7 @@ type Request struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//NewRequest is a function which takes the mandatory fields to perform a request to the CW API and returns a pointer to a Request struct
|
//NewRequest is a function which takes the mandatory fields to perform a request to the CW API and returns a pointer to a Request struct
|
||||||
func NewRequest(cw *ConnectwiseSite, restAction, method string, body []byte) *Request {
|
func NewRequest(cw *Site, restAction, method string, body []byte) *Request {
|
||||||
req := Request{CW: cw, RestAction: restAction, Method: method, Body: body}
|
req := Request{CW: cw, RestAction: restAction, Method: method, Body: body}
|
||||||
return &req
|
return &req
|
||||||
}
|
}
|
||||||
@ -60,7 +60,7 @@ func (req *Request) Do() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//BuildURL will take a REST action such as "/companies/company/5" and then append the CW site to it and return a pointer to a url.URL
|
//BuildURL will take a REST action such as "/companies/company/5" and then append the CW site to it and return a pointer to a url.URL
|
||||||
func (cw *ConnectwiseSite) BuildURL(restAction string) (*url.URL, error) {
|
func (cw *Site) BuildURL(restAction string) (*url.URL, error) {
|
||||||
var cwurl *url.URL
|
var cwurl *url.URL
|
||||||
cwurl, err := url.Parse(cw.Site)
|
cwurl, err := url.Parse(cw.Site)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -86,8 +86,8 @@ func getHTTPResponseBody(resp *http.Response) ([]byte, error) {
|
|||||||
return body, nil
|
return body, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
//GetRequest takes a ConnectwiseSite and request URL, and returns the body of the response
|
//GetRequest takes a Site and request URL, and returns the body of the response
|
||||||
func (cw *ConnectwiseSite) GetRequest(cwurl *url.URL) ([]byte, error) {
|
func (cw *Site) GetRequest(cwurl *url.URL) ([]byte, error) {
|
||||||
client := &http.Client{}
|
client := &http.Client{}
|
||||||
req, err := http.NewRequest("GET", cwurl.String(), nil)
|
req, err := http.NewRequest("GET", cwurl.String(), nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -108,8 +108,8 @@ func (cw *ConnectwiseSite) GetRequest(cwurl *url.URL) ([]byte, error) {
|
|||||||
return body, nil
|
return body, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
//PostRequest takes a ConnectwiseSite and request URL, and returns the body of the response
|
//PostRequest takes a Site and request URL, and returns the body of the response
|
||||||
func (cw *ConnectwiseSite) PostRequest(cwurl *url.URL, reqBody io.Reader) ([]byte, error) {
|
func (cw *Site) PostRequest(cwurl *url.URL, reqBody io.Reader) ([]byte, error) {
|
||||||
client := &http.Client{}
|
client := &http.Client{}
|
||||||
req, err := http.NewRequest("POST", cwurl.String(), reqBody)
|
req, err := http.NewRequest("POST", cwurl.String(), reqBody)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -130,8 +130,8 @@ func (cw *ConnectwiseSite) PostRequest(cwurl *url.URL, reqBody io.Reader) ([]byt
|
|||||||
return body, nil
|
return body, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
//DeleteRequest takes a ConnectwiseSite and request URL, and returns the body of the response
|
//DeleteRequest takes a Site and request URL, and returns the body of the response
|
||||||
func (cw *ConnectwiseSite) DeleteRequest(cwurl *url.URL) ([]byte, error) {
|
func (cw *Site) DeleteRequest(cwurl *url.URL) ([]byte, error) {
|
||||||
client := &http.Client{}
|
client := &http.Client{}
|
||||||
req, err := http.NewRequest("DELETE", cwurl.String(), nil)
|
req, err := http.NewRequest("DELETE", cwurl.String(), nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -194,7 +194,7 @@ type ConfigurationReference struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//GetTicketByID expects a ticket ID and returns a pointer to a Ticket struct
|
//GetTicketByID expects a ticket ID and returns a pointer to a Ticket struct
|
||||||
func (cw *ConnectwiseSite) GetTicketByID(ticketID int) (*Ticket, error) {
|
func (cw *Site) GetTicketByID(ticketID int) (*Ticket, error) {
|
||||||
restAction := fmt.Sprintf("/service/tickets/%d", ticketID)
|
restAction := fmt.Sprintf("/service/tickets/%d", ticketID)
|
||||||
cwurl, err := cw.BuildURL(restAction)
|
cwurl, err := cw.BuildURL(restAction)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -215,7 +215,7 @@ func (cw *ConnectwiseSite) GetTicketByID(ticketID int) (*Ticket, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//GetTicketTimeEntriesByID expects a ticket ID and returns a pointer a to a slice of TimeEntryReference's, all the time entries attached to that ticket
|
//GetTicketTimeEntriesByID expects a ticket ID and returns a pointer a to a slice of TimeEntryReference's, all the time entries attached to that ticket
|
||||||
func (cw *ConnectwiseSite) GetTicketTimeEntriesByID(ticketID int) (*[]TimeEntryReference, error) {
|
func (cw *Site) GetTicketTimeEntriesByID(ticketID int) (*[]TimeEntryReference, error) {
|
||||||
restAction := fmt.Sprintf("/service/tickets/%d/timeentries", ticketID)
|
restAction := fmt.Sprintf("/service/tickets/%d/timeentries", ticketID)
|
||||||
cwurl, err := cw.BuildURL(restAction)
|
cwurl, err := cw.BuildURL(restAction)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -236,7 +236,7 @@ func (cw *ConnectwiseSite) GetTicketTimeEntriesByID(ticketID int) (*[]TimeEntryR
|
|||||||
}
|
}
|
||||||
|
|
||||||
//GetTicketConfigurationsByID expects a ticket ID and returns a pointer to a slice of the configurations attached to the ticket
|
//GetTicketConfigurationsByID expects a ticket ID and returns a pointer to a slice of the configurations attached to the ticket
|
||||||
func (cw *ConnectwiseSite) GetTicketConfigurationsByID(ticketID int) (*[]ConfigurationReference, error) {
|
func (cw *Site) GetTicketConfigurationsByID(ticketID int) (*[]ConfigurationReference, error) {
|
||||||
restAction := fmt.Sprintf("/service/tickets/%d/configurations", ticketID)
|
restAction := fmt.Sprintf("/service/tickets/%d/configurations", ticketID)
|
||||||
cwurl, err := cw.BuildURL(restAction)
|
cwurl, err := cw.BuildURL(restAction)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -20,7 +20,7 @@ type Callback struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//GetCallbacks returns a slice of Callback structs containing all the callbacks currently registered with ConnectWise
|
//GetCallbacks returns a slice of Callback structs containing all the callbacks currently registered with ConnectWise
|
||||||
func (cw *ConnectwiseSite) GetCallbacks() (*[]Callback, error) {
|
func (cw *Site) GetCallbacks() (*[]Callback, error) {
|
||||||
restAction := "/system/callbacks"
|
restAction := "/system/callbacks"
|
||||||
cwurl, err := cw.BuildURL(restAction)
|
cwurl, err := cw.BuildURL(restAction)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -43,7 +43,7 @@ func (cw *ConnectwiseSite) GetCallbacks() (*[]Callback, error) {
|
|||||||
|
|
||||||
//NewCallback expects a Callback struct and will register a new callback with Connectwise
|
//NewCallback expects a Callback struct and will register a new callback with Connectwise
|
||||||
//TBD: This should return something useful, response body??
|
//TBD: This should return something useful, response body??
|
||||||
func (cw *ConnectwiseSite) NewCallback(callback Callback) error {
|
func (cw *Site) NewCallback(callback Callback) error {
|
||||||
restAction := "/system/callbacks"
|
restAction := "/system/callbacks"
|
||||||
cwurl, err := cw.BuildURL(restAction)
|
cwurl, err := cw.BuildURL(restAction)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -67,7 +67,7 @@ func (cw *ConnectwiseSite) NewCallback(callback Callback) error {
|
|||||||
|
|
||||||
//DeleteCallback expects the ID of an existing callback and will unregister it with ConnectWise
|
//DeleteCallback expects the ID of an existing callback and will unregister it with ConnectWise
|
||||||
//TBD: This should return something useful, response body??
|
//TBD: This should return something useful, response body??
|
||||||
func (cw *ConnectwiseSite) DeleteCallback(callback int) error {
|
func (cw *Site) DeleteCallback(callback int) error {
|
||||||
restAction := fmt.Sprintf("/system/callbacks/%d", callback)
|
restAction := fmt.Sprintf("/system/callbacks/%d", callback)
|
||||||
cwurl, err := cw.BuildURL(restAction)
|
cwurl, err := cw.BuildURL(restAction)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -85,7 +85,7 @@ type TimeEntry struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//GetTimeEntryByID expects a time entry ID and will return a pointer to a TimeEntry struct
|
//GetTimeEntryByID expects a time entry ID and will return a pointer to a TimeEntry struct
|
||||||
func (cw *ConnectwiseSite) GetTimeEntryByID(timeEntryID int) (*TimeEntry, error) {
|
func (cw *Site) GetTimeEntryByID(timeEntryID int) (*TimeEntry, error) {
|
||||||
restAction := fmt.Sprintf("/time/entries/%d", timeEntryID)
|
restAction := fmt.Sprintf("/time/entries/%d", timeEntryID)
|
||||||
cwurl, err := cw.BuildURL(restAction)
|
cwurl, err := cw.BuildURL(restAction)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user