Added GetOrganizationByName. Update README.MD with usage
This commit is contained in:
parent
06e73821e0
commit
f8eac0388a
25
README.md
25
README.md
@ -1,4 +1,27 @@
|
|||||||
# go-itg
|
# go-itg
|
||||||
IT Glue API Structs + Receivers for the Go
|
IT Glue API Structs + Receivers for the Go
|
||||||
|
|
||||||
This is not complete, and at least for now, I will only be adding support the functionality required for use within my organization. Feel free to send a pull request if you'd like to contribute anything that's missing.
|
This is nowhere near complete, and at least for now, I will only be adding support the functionality required for use within my organization. Feel free to send a pull request if you'd like to contribute anything that's missing.
|
||||||
|
|
||||||
|
#Installation
|
||||||
|
```
|
||||||
|
go get github.com/StevenPolley/go-itg
|
||||||
|
```
|
||||||
|
|
||||||
|
#Usage
|
||||||
|
```
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/StevenPolley/go-itg/itglue"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
itgAPI := itglue.NewITGAPI("ITG.XXXXXXXXXXXXX555555YOURAPIDKEYHERE2222222222222222XXXXXX")
|
||||||
|
fmt.Println((*itgAPI).GetOrganizationByID(1234242).Data.Attributes.Name) //Returns the name of the Organization with ID 1234242
|
||||||
|
fmt.Println((*itgAPI).GetOrganizationByName("test Org Inc.").Data[0].Attributes.Description) //Returns the description of the Organization with Name "Test Org Inc."
|
||||||
|
|
||||||
|
}
|
||||||
|
```
|
@ -3,6 +3,7 @@ package itglue
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net/url"
|
||||||
)
|
)
|
||||||
|
|
||||||
//OrganizationInternalData contains the schema of an Organization in IT Glue without the "data" wrapper.
|
//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
|
//Returns a pointer to an Organization struct
|
||||||
func (itg *ITGAPI) GetOrganizationByID(organizationID int) *Organization {
|
func (itg *ITGAPI) GetOrganizationByID(organizationID int) *Organization {
|
||||||
itgurl := itg.BuildURL(fmt.Sprintf("/organizations/%d", organizationID))
|
itgurl := itg.BuildURL(fmt.Sprintf("/organizations/%d", organizationID))
|
||||||
|
|
||||||
body := itg.GetRequest(itgurl)
|
body := itg.GetRequest(itgurl)
|
||||||
|
|
||||||
organization := &Organization{}
|
organization := &Organization{}
|
||||||
err := json.Unmarshal(body, organization)
|
err := json.Unmarshal(body, organization)
|
||||||
check(err)
|
check(err)
|
||||||
|
|
||||||
return organization
|
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
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user