Added GetOrganizationByName. Update README.MD with usage

This commit is contained in:
2018-06-29 23:54:16 -06:00
parent 06e73821e0
commit f8eac0388a
2 changed files with 38 additions and 5 deletions

View File

@ -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
}