From 06e73821e0086b44114204db2b1f4e1cc51a0130 Mon Sep 17 00:00:00 2001 From: Steven Polley Date: Fri, 29 Jun 2018 23:37:34 -0600 Subject: [PATCH] Fix Organization structs to work around annoying ITG "data" wrapper JSON object. --- itglue/organizations.go | 45 ++++++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/itglue/organizations.go b/itglue/organizations.go index 4375d47..d447adc 100644 --- a/itglue/organizations.go +++ b/itglue/organizations.go @@ -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