-
Notifications
You must be signed in to change notification settings - Fork 1
/
User.go
77 lines (64 loc) · 2.61 KB
/
User.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
package activecampaign
import (
a_types "github.com/leapforce-libraries/go_activecampaign/types"
errortools "github.com/leapforce-libraries/go_errortools"
go_http "github.com/leapforce-libraries/go_http"
go_types "github.com/leapforce-libraries/go_types"
"net/http"
)
type UsersResponse struct {
Users []User `json:"users"`
Meta Meta `json:"meta"`
}
type User struct {
Username *string `json:"username,omitempty"`
FirstName *string `json:"firstName,omitempty"`
LastName *string `json:"lastName,omitempty"`
Email *string `json:"email,omitempty"`
Password *string `json:"password,omitempty"`
Phone *string `json:"phone,omitempty"`
Signature *string `json:"signature,omitempty"`
Language *string `json:"lang,omitempty"`
LocalZoneId *string `json:"localZoneid,omitempty"`
PasswordUpdatedUtcTimestamp *a_types.DateTimeString `json:"password_updated_utc_timestamp,omitempty"`
CreatedDate *a_types.DateTimeTimezoneString `json:"cdate,omitempty"`
UpdatedDate *a_types.DateTimeTimezoneString `json:"udate,omitempty"`
MfaEnabled *go_types.BoolString `json:"mfaEnabled,omitempty"`
Links *Links `json:"links,omitempty"`
Id *go_types.Int64String `json:"id,omitempty"`
Group *int64 `json:"group,omitempty"`
}
func (service *Service) GetUsers() (*[]User, *errortools.Error) {
usersResponse := UsersResponse{}
requestConfig := go_http.RequestConfig{
Method: http.MethodGet,
Url: service.url("users"),
ResponseModel: &usersResponse,
}
_, _, e := service.httpRequest(&requestConfig)
if e != nil {
return nil, e
}
return &usersResponse.Users, nil
}
func (service *Service) CreateUser(user *User) (*User, *errortools.Error) {
if user == nil {
return nil, nil
}
userResponse := struct {
User User `json:"user"`
}{}
requestConfig := go_http.RequestConfig{
Method: http.MethodPost,
Url: service.url("users"),
BodyModel: struct {
User User `json:"user"`
}{*user},
ResponseModel: &userResponse,
}
_, _, e := service.httpRequest(&requestConfig)
if e != nil {
return nil, e
}
return &userResponse.User, nil
}