Fix Organization structs to work around annoying ITG "data" wrapper JSON object.

This commit is contained in:
Steven Polley 2018-06-29 23:37:34 -06:00
parent 09935e7c69
commit 06e73821e0
1 changed files with 27 additions and 18 deletions

View File

@ -5,25 +5,34 @@ import (
"fmt"
)
//Organization maps JSON data from the ITG Organization resource to Go struct
//OrganizationInternalData contains the schema of an Organization in IT Glue without the "data" wrapper.
//This allows us to reuse the schema when data is either a JSON object or an array, depending on what results are returned
type OrganizationInternalData struct {
ID string `json:"id"`
Type string `json:"type"`
Attributes struct {
Name string `json:"name"`
Description string `json:"description"`
OrganizationTypeID int `json:"organization-type-id"`
OrganizationTypeName string `json:"organization-type-name"`
OrganizationStatusID int `json:"organization-status-id"`
OrganizationStatusName string `json:"organization-status-name"`
Logo string `json:"logo"`
QuickNotes string `json:"quick-notes"`
ShortName string `json:"short-name"`
CreatedAt string `json:"created-at"`
UpdatedAt string `json:"updated-at"`
} `json:"attributes"`
}
//Organization contains a single Organization
type Organization struct {
Data struct {
ID string `json:"id"`
Type string `json:"type"`
Attributes struct {
Name string `json:"name"`
Description string `json:"description"`
OrganizationTypeID int `json:"organization-type-id"`
OrganizationTypeName string `json:"organization-type-name"`
OrganizationStatusID int `json:"organization-status-id"`
OrganizationStatusName string `json:"organization-status-name"`
Logo string `json:"logo"`
QuickNotes string `json:"quick-notes"`
ShortName string `json:"short-name"`
CreatedAt string `json:"created-at"`
UpdatedAt string `json:"updated-at"`
} `json:"attributes"`
} `json:"data"`
Data struct{ OrganizationInternalData } `json:"data"`
}
//OrganizationList contains a slice of Organizations
type OrganizationList struct {
Data []struct{ OrganizationInternalData } `json:"data"`
}
//GetOrganizationByID expects an ITG organization ID