Split organization-types into separate file. new file for each endpoint
This commit is contained in:
parent
3d987bb089
commit
582b4c205f
48
itglue/organization-types.go
Normal file
48
itglue/organization-types.go
Normal file
@ -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
|
||||||
|
}
|
@ -4,20 +4,8 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/url"
|
"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.
|
//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
|
//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 {
|
type OrganizationData struct {
|
||||||
@ -50,36 +38,6 @@ type OrganizationList struct {
|
|||||||
Meta struct{ Metadata } `json:"metadata"`
|
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
|
//GetOrganizationByID expects an ITG organization ID
|
||||||
//Returns a pointer to an Organization struct
|
//Returns a pointer to an Organization struct
|
||||||
func (itg *ITGAPI) GetOrganizationByID(organizationID int) (*Organization, error) {
|
func (itg *ITGAPI) GetOrganizationByID(organizationID int) (*Organization, error) {
|
||||||
|
Loading…
Reference in New Issue
Block a user