-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathorganization.go
104 lines (84 loc) · 2.99 KB
/
organization.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package zed
import (
"fmt"
)
// OrganizationResponse struct
type OrganizationResponse struct {
Organization *Organization `json:"organization"`
}
// OrganizationCollectionResponse struct
type OrganizationCollectionResponse struct {
Organizations []Organization `json:"organizations,omitempty"`
NextPage *string `json:"next_page,omitempty"`
PreviousPage *string `json:"previous_page,omitempty"`
Count *int `json:"count,omitempty"`
}
// Organization struct
type Organization struct {
URL *string `json:"url,omitempty"`
ID *int `json:"id,omitempty"`
Name *string `json:"name,omitempty"`
SharedTickets *bool `json:"shared_tickets,omitempty"`
SharedComments *bool `json:"shared_comments,omitempty"`
ExternalID *string `json:"external_id,omitempty"`
CreatedAt *string `json:"created_at,omitempty"`
UpdatedAt *string `json:"updated_at,omitempty"`
DomainNames []string `json:"domain_names,omitempty"`
Details *string `json:"details,omitempty"`
Notes *string `json:"notes,omitempty"`
GroupID *int `json:"group_id,omitempty"`
Tags []string `json:"tags,omitempty"`
OrganizationFields map[string]string `json:"organization_fields,omitempty"`
}
// OrganizationService struct
type OrganizationService struct {
client *Client
}
// Get finds an organization in Zendesk by ID
func (s *OrganizationService) Get(organizationID string) (*Organization, *Response, error) {
org := OrganizationResponse{}
url := fmt.Sprintf("organizations/%s.json", organizationID)
req, err := s.client.NewRequest("GET", url, nil)
if err != nil {
return nil, nil, err
}
resp, err := s.client.Do(req, &org)
if err != nil {
return nil, nil, err
}
return org.Organization, resp, err
}
// Update updates and organization by id
func (s *OrganizationService) Update(org *Organization) (*Organization, error) {
organization := &Organization{}
url := fmt.Sprintf("organizations/%d.json", *org.ID)
or := &OrganizationResponse{Organization: org}
req, err := s.client.NewRequest("PUT", url, or)
if err != nil {
return organization, err
}
result := OrganizationResponse{}
_, err = s.client.Do(req, &result)
if err != nil {
return organization, err
}
organization = result.Organization
return organization, err
}
//Create creates a new organization
func (s *OrganizationService) Create(org *Organization) (*Organization, error) {
organization := &Organization{}
or := &OrganizationResponse{Organization: org}
url := fmt.Sprintf("organizations.json")
req, err := s.client.NewRequest("POST", url, or)
if err != nil {
return organization, err
}
result := OrganizationResponse{}
_, err = s.client.Do(req, &result)
if err != nil {
return organization, err
}
organization = result.Organization
return organization, nil
}