forked from belong-inc/go-hubspot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
crm_properties.go
114 lines (100 loc) · 4.84 KB
/
crm_properties.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
package hubspot
import (
"fmt"
)
const (
crmPropertiesPath = "properties"
)
type CrmPropertiesList struct {
Results []*CrmProperty `json:"results,omitempty"`
}
type CrmProperty struct {
UpdatedAt *HsTime `json:"updatedAt,omitempty"`
CreatedAt *HsTime `json:"createdAt,omitempty"`
ArchivedAt *HsTime `json:"archivedAt,omitempty"`
Name *HsStr `json:"name,omitempty"`
Label *HsStr `json:"label,omitempty"`
Type *HsStr `json:"type,omitempty"`
FieldType *HsStr `json:"fieldType,omitempty"`
Description *HsStr `json:"description,omitempty"`
GroupName *HsStr `json:"groupName,omitempty"`
Options []*CrmPropertyOptions `json:"options,omitempty"`
CreatedUserId *HsStr `json:"createdUserId,omitempty"`
UpdatedUserId *HsStr `json:"updatedUserId,omitempty"`
ReferencedObjectType *HsStr `json:"referencedObjectType,omitempty"`
DisplayOrder *HsInt `json:"displayOrder,omitempty"`
Calculated *HsBool `json:"calculated,omitempty"`
ExternalOptions *HsBool `json:"externalOptions,omitempty"`
Archived *HsBool `json:"archived,omitempty"`
HasUniqueValue *HsBool `json:"hasUniqueValue,omitempty"`
Hidden *HsBool `json:"hidden,omitempty"`
HubspotDefined *HsBool `json:"hubspotDefined,omitempty"`
ShowCurrencySymbol *HsBool `json:"showCurrencySymbol,omitempty"`
ModificationMetaData *CrmPropertyModificationMeta `json:"modificationMetadata,omitempty"`
FormField *HsBool `json:"formField,omitempty"`
CalculationFormula *HsStr `json:"calculationFormula,omitempty"`
}
type CrmPropertyModificationMeta struct {
Archivable *HsBool `json:"archivable,omitempty"`
ReadOnlyDefition *HsBool `json:"readOnlyDefinition,omitempty"`
ReadOnlyValue *HsBool `json:"readOnlyValue,omitempty"`
ReadOnlyOptions *HsBool `json:"readOnlyOptions,omitempty"`
}
type CrmPropertyOptions struct {
Label *HsStr `json:"label,omitempty"`
Value *HsStr `json:"value,omitempty"`
Description *HsStr `json:"description,omitempty"`
DisplayOrder *HsInt `json:"displayOrder,omitempty"`
Hidden *HsBool `json:"hidden,omitempty"`
}
// CrmPropertiesService is an interface of CRM properties endpoints of the HubSpot API.
// Reference: https://developers.hubspot.com/docs/api/crm/properties
type CrmPropertiesService interface {
List(objectType string) (*CrmPropertiesList, error)
Create(objectType string, reqData interface{}) (*CrmProperty, error)
Get(objectType string, propertyName string) (*CrmProperty, error)
Delete(objectType string, propertyName string) error
Update(objectType string, propertyName string, reqData interface{}) (*CrmProperty, error)
}
// CrmPropertiesServiceOp handles communication with the CRM properties endpoint.
type CrmPropertiesServiceOp struct {
client *Client
crmPropertiesPath string
}
var _ CrmPropertiesService = (*CrmPropertiesServiceOp)(nil)
func (s *CrmPropertiesServiceOp) List(objectType string) (*CrmPropertiesList, error) {
var resource CrmPropertiesList
path := fmt.Sprintf("%s/%s", s.crmPropertiesPath, objectType)
if err := s.client.Get(path, &resource, nil); err != nil {
return nil, err
}
return &resource, nil
}
func (s *CrmPropertiesServiceOp) Get(objectType, propertyName string) (*CrmProperty, error) {
var resource CrmProperty
path := fmt.Sprintf("%s/%s/%s", s.crmPropertiesPath, objectType, propertyName)
if err := s.client.Get(path, &resource, nil); err != nil {
return nil, err
}
return &resource, nil
}
func (s *CrmPropertiesServiceOp) Create(objectType string, reqData interface{}) (*CrmProperty, error) {
var resource CrmProperty
path := fmt.Sprintf("%s/%s", s.crmPropertiesPath, objectType)
if err := s.client.Post(path, reqData, &resource); err != nil {
return nil, err
}
return &resource, nil
}
func (s *CrmPropertiesServiceOp) Delete(objectType string, propertyName string) error {
path := fmt.Sprintf("%s/%s/%s", s.crmPropertiesPath, objectType, propertyName)
return s.client.Delete(path, nil)
}
func (s *CrmPropertiesServiceOp) Update(objectType string, propertyName string, reqData interface{}) (*CrmProperty, error) {
var resource CrmProperty
path := fmt.Sprintf("%s/%s/%s", s.crmPropertiesPath, objectType, propertyName)
if err := s.client.Patch(path, reqData, &resource); err != nil {
return nil, err
}
return &resource, nil
}