-
Notifications
You must be signed in to change notification settings - Fork 0
/
companyContacts.go
136 lines (127 loc) · 4.3 KB
/
companyContacts.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
package connect
import "encoding/json"
type CompanyContact struct {
Id KId `json:"id"`
Name string `json:"name"` // name of company contact (caption of item in list of contacts)
Company string `json:"company"`
Street string `json:"street"`
Locality string `json:"locality"`
State string `json:"state"`
Zip string `json:"zip"`
Country string `json:"country"`
Url string `json:"url"`
Phone string `json:"phone"`
Fax string `json:"fax"`
DomainId KId `json:"domainId"` // id of domain associated with company contact
}
// CompanyContactList - List of company contacts
type CompanyContactList []CompanyContact
// Company contacts management
// CompanyContactsCreate - Create new company contacts.
// Return
// errors - error message list
// result - particular results for all items
func (s *ServerConnection) CompanyContactsCreate(companyContacts CompanyContactList) (ErrorList, CreateResultList, error) {
params := struct {
CompanyContacts CompanyContactList `json:"companyContacts"`
}{companyContacts}
data, err := s.CallRaw("CompanyContacts.create", params)
if err != nil {
return nil, nil, err
}
errors := struct {
Result struct {
Errors ErrorList `json:"errors"`
Result CreateResultList `json:"result"`
} `json:"result"`
}{}
err = json.Unmarshal(data, &errors)
return errors.Result.Errors, errors.Result.Result, err
}
// CompanyContactsGet - Obtain a list of company contacts.
// Parameters
// query - query conditions and limits
// Return
// list - list of company contacts
// totalItems - amount of company contacts for given search condition, useful when limit is defined in SearchQuery
func (s *ServerConnection) CompanyContactsGet(query SearchQuery) (CompanyContactList, int, error) {
query = addMissedParametersToSearchQuery(query)
params := struct {
Query SearchQuery `json:"query"`
}{query}
data, err := s.CallRaw("CompanyContacts.get", params)
if err != nil {
return nil, 0, err
}
list := struct {
Result struct {
List CompanyContactList `json:"list"`
TotalItems int `json:"totalItems"`
} `json:"result"`
}{}
err = json.Unmarshal(data, &list)
return list.Result.List, list.Result.TotalItems, err
}
// CompanyContactsGetAvailable - - Only company contacts for given domain and global company contacts are listed.
// Parameters
// domainId - Only company contacts for given domain and global company contacts are listed.
// Return
// companyContactList - list of user templates
func (s *ServerConnection) CompanyContactsGetAvailable(domainId KId) (CompanyContactList, error) {
params := struct {
DomainId KId `json:"domainId"`
}{domainId}
data, err := s.CallRaw("CompanyContacts.getAvailable", params)
if err != nil {
return nil, err
}
companyContactList := struct {
Result struct {
CompanyContactList CompanyContactList `json:"companyContactList"`
} `json:"result"`
}{}
err = json.Unmarshal(data, &companyContactList)
return companyContactList.Result.CompanyContactList, err
}
// CompanyContactsRemove - Remove company contacts.
// Return
// errors - error message list
func (s *ServerConnection) CompanyContactsRemove(companyContactsIds KIdList) (ErrorList, error) {
params := struct {
CompanyContactsIds KIdList `json:"companyContactsIds"`
}{companyContactsIds}
data, err := s.CallRaw("CompanyContacts.remove", params)
if err != nil {
return nil, err
}
errors := struct {
Result struct {
Errors ErrorList `json:"errors"`
} `json:"result"`
}{}
err = json.Unmarshal(data, &errors)
return errors.Result.Errors, err
}
// CompanyContactsSet - Set existing company contacts to given pattern.
// Parameters
// companyContactsIds - list of the company contacts's global identifier(s)
// pattern - pattern to use for new values
// Return
// errors - error message list
func (s *ServerConnection) CompanyContactsSet(companyContactsIds KIdList, pattern CompanyContact) (ErrorList, error) {
params := struct {
CompanyContactsIds KIdList `json:"companyContactsIds"`
Pattern CompanyContact `json:"pattern"`
}{companyContactsIds, pattern}
data, err := s.CallRaw("CompanyContacts.set", params)
if err != nil {
return nil, err
}
errors := struct {
Result struct {
Errors ErrorList `json:"errors"`
} `json:"result"`
}{}
err = json.Unmarshal(data, &errors)
return errors.Result.Errors, err
}