From 582b4c205fd1edacc4f0ffba20de77e6d1e57126 Mon Sep 17 00:00:00 2001 From: Steven Polley Date: Sun, 22 Jul 2018 02:19:22 -0600 Subject: [PATCH] Split organization-types into separate file. new file for each endpoint --- itglue/organization-types.go | 48 ++++++++++++++++++++++++++++++++++++ itglue/organizations.go | 42 ------------------------------- 2 files changed, 48 insertions(+), 42 deletions(-) create mode 100644 itglue/organization-types.go diff --git a/itglue/organization-types.go b/itglue/organization-types.go new file mode 100644 index 0000000..3b8e13a --- /dev/null +++ b/itglue/organization-types.go @@ -0,0 +1,48 @@ +package itglue + +import ( + "encoding/json" + "fmt" + "time" +) + +type OrganizationTypeData struct { + ID string `json:"id"` + Type string `json:"type"` + Attributes struct { + Name string `json:"name"` + CreatedAt time.Time `json:"created-at"` + UpdatedAt time.Time `json:"updated-at"` + Synced bool `json:"synced"` + } `json:"attributes"` +} + +type OrganizationType struct { + Data struct{ OrganizationTypeData } `json:"data"` + Meta struct{ Metadata } `json:"metadata"` +} + +type OrganizationTypeList struct { + Data []struct{ OrganizationTypeData } `json:"data"` + Meta struct{ Metadata } `json:"metadata"` +} + +///organization_types +func (itg *ITGAPI) GetOrganizationTypes() (*OrganizationTypeList, error) { + itgurl, err := itg.BuildURL("/organization_types") + if err != nil { + return nil, fmt.Errorf("could not build URL: %s", err) + } + body, err := itg.GetRequest(itgurl) + if err != nil { + return nil, fmt.Errorf("request failed: %s", err) + } + + organizationTypes := &OrganizationTypeList{} + err = json.Unmarshal(body, organizationTypes) + if err != nil { + return nil, fmt.Errorf("could not get organization types: %s", err) + } + + return organizationTypes, nil +} diff --git a/itglue/organizations.go b/itglue/organizations.go index fd175d4..1592404 100644 --- a/itglue/organizations.go +++ b/itglue/organizations.go @@ -4,20 +4,8 @@ import ( "encoding/json" "fmt" "net/url" - "time" ) -type OrganizationTypeData struct { - ID string `json:"id"` - Type string `json:"type"` - Attributes struct { - Name string `json:"name"` - CreatedAt time.Time `json:"created-at"` - UpdatedAt time.Time `json:"updated-at"` - Synced bool `json:"synced"` - } `json:"attributes"` -} - //OrganizationData 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 OrganizationData struct { @@ -50,36 +38,6 @@ type OrganizationList struct { Meta struct{ Metadata } `json:"metadata"` } -type OrganizationType struct { - Data struct{ OrganizationTypeData } `json:"data"` - Meta struct{ Metadata } `json:"metadata"` -} - -type OrganizationTypeList struct { - Data []struct{ OrganizationTypeData } `json:"data"` - Meta struct{ Metadata } `json:"metadata"` -} - -///organization_types -func (itg *ITGAPI) GetOrganizationTypes() (*OrganizationTypeList, error) { - itgurl, err := itg.BuildURL("/organization_types") - if err != nil { - return nil, fmt.Errorf("could not build URL: %s", err) - } - body, err := itg.GetRequest(itgurl) - if err != nil { - return nil, fmt.Errorf("request failed: %s", err) - } - - organizationTypes := &OrganizationTypeList{} - err = json.Unmarshal(body, organizationTypes) - if err != nil { - return nil, fmt.Errorf("could not get organization types: %s", err) - } - - return organizationTypes, nil -} - //GetOrganizationByID expects an ITG organization ID //Returns a pointer to an Organization struct func (itg *ITGAPI) GetOrganizationByID(organizationID int) (*Organization, error) {