Added GetOrganizationByName. Update README.MD with usage
This commit is contained in:
@ -3,6 +3,7 @@ package itglue
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
//OrganizationInternalData contains the schema of an Organization in IT Glue without the "data" wrapper.
|
||||
@ -39,13 +40,22 @@ type OrganizationList struct {
|
||||
//Returns a pointer to an Organization struct
|
||||
func (itg *ITGAPI) GetOrganizationByID(organizationID int) *Organization {
|
||||
itgurl := itg.BuildURL(fmt.Sprintf("/organizations/%d", organizationID))
|
||||
|
||||
body := itg.GetRequest(itgurl)
|
||||
|
||||
organization := &Organization{}
|
||||
err := json.Unmarshal(body, organization)
|
||||
check(err)
|
||||
|
||||
return organization
|
||||
|
||||
}
|
||||
|
||||
//GetOrganizationByName expects an exact matching organization name and returns an OrganizationList
|
||||
func (itg *ITGAPI) GetOrganizationByName(organizationName string) *OrganizationList {
|
||||
itgurl := itg.BuildURL("/organizations")
|
||||
params := url.Values{}
|
||||
params.Add("filter[name]", organizationName)
|
||||
itgurl.RawQuery = params.Encode()
|
||||
body := itg.GetRequest(itgurl)
|
||||
organization := &OrganizationList{}
|
||||
err := json.Unmarshal(body, organization)
|
||||
check(err)
|
||||
return organization
|
||||
}
|
||||
|
Reference in New Issue
Block a user