-
Notifications
You must be signed in to change notification settings - Fork 1
/
ContactFieldValue.go
69 lines (57 loc) · 2.13 KB
/
ContactFieldValue.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
package activecampaign
import (
"fmt"
"net/http"
"net/url"
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"
)
type ContactFieldValues struct {
FieldValues []ContactFieldValue `json:"fieldValues"`
Meta Meta `json:"meta"`
}
type ContactFieldValue struct {
ContactId go_types.Int64String `json:"contact"`
FieldId go_types.Int64String `json:"field"`
Value string `json:"value"`
CreatedDate a_types.DateTimeTimezoneString `json:"cdate,omitempty"`
UpdatedDate a_types.DateTimeTimezoneString `json:"udate,omitempty"`
CreatedBy *go_types.String `json:"created_by,omitempty"`
UpdatedBy *go_types.String `json:"updated_by,omitempty"`
Id go_types.Int64String `json:"id,omitempty"`
OwnerId go_types.Int64String `json:"owner,omitempty"`
Links *Links `json:"links,omitempty"`
}
type GetContactFieldValuesConfig struct {
ContactId *int64
FieldId *int64
Value *string
}
func (service *Service) GetContactFieldValues(getFieldValuesConfig *GetContactFieldValuesConfig) (*ContactFieldValues, bool, *errortools.Error) {
params := url.Values{}
fieldValues := ContactFieldValues{}
path := "fieldValues"
if getFieldValuesConfig != nil {
if getFieldValuesConfig.ContactId != nil {
path = fmt.Sprintf("contacts/%v/fieldValues", *getFieldValuesConfig.ContactId)
}
if getFieldValuesConfig.FieldId != nil {
params.Add("filters[fieldid]", fmt.Sprintf("%v", *getFieldValuesConfig.FieldId))
}
if getFieldValuesConfig.Value != nil {
params.Add("filters[val]", *getFieldValuesConfig.Value)
}
}
requestConfig := go_http.RequestConfig{
Method: http.MethodGet,
Url: service.url(fmt.Sprintf("%s?%s", path, params.Encode())),
ResponseModel: &fieldValues,
}
_, _, e := service.httpRequest(&requestConfig)
if e != nil {
return nil, true, e
}
return &fieldValues, false, nil
}