Skip to content

Commit

Permalink
Update crm objects to better match stated response schemas
Browse files Browse the repository at this point in the history
  • Loading branch information
sblackstone committed Apr 19, 2023
1 parent 23d24a1 commit 0644886
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 47 deletions.
51 changes: 29 additions & 22 deletions crm_properties.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,41 +9,48 @@ const (
)

type CrmPropertiesList struct {
Results []*CrmProperty
Results []*CrmProperty `json:"results,omitempty"`
}

type CrmProperty struct {
Calculated *HsBool `json:"calculated,omitempty"`
Description *HsStr `json:"description,omitempty"`
DisplayOrder *HsInt `json:"displayOrder,omitempty"`
ExternalOptions *HsBool `json:"externalOptions,omitempty"`
FieldType *HsStr `json:"fieldType,omitempty"`
FormField *HsBool `json:"formField,omitempty"`
GroupName *HsStr `json:"groupName,omitempty"`
HasUniqueValue *HsBool `json:"hasUniqueValue,omitempty"`
Hidden *HsBool `json:"hidden,omitempty"`
HubspotDefined *HsBool `json:"hubspotDefined,omitempty"`
Label *HsStr `json:"label,omitempty"`
ModificationMeta *CrmPropertyModificationMeta `json:"modificationMeta,omitempty"`
Name *HsStr `json:"name,omitempty"`
Options []*CrmPropertyOptions `json:"options,omitempty"`
Type *HsStr `json:"type,omitempty"`
CreatedUserId *HsStr `json:"createdUserId,omitempty"`
UpdatedUserId *HsStr `json:"updatedUserId,omitempty"`
CreatedAt *HsTime `json:"createdAt,omitempty"`
UpdatedAt *HsTime `json:"updatedAt,omitempty"`
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 {
DisplayOrder *HsInt `json:"displayOrder,omitempty"`
Hidden *HsBool `json:"hidden,omitempty"`
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.
Expand Down
3 changes: 1 addition & 2 deletions crm_properties_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ func TestGetCrmProperty(t *testing.T) {
if err != nil {
t.Error(err)
}

if *res.Name != "model" {
t.Errorf("expected res.Name to be model, got %s", res.Name)
}
Expand Down Expand Up @@ -61,7 +60,7 @@ func TestUpdateProperty(t *testing.T) {
cli, _ := NewClient(SetPrivateAppToken(os.Getenv("PRIVATE_APP_TOKEN")))

updateProp := make(map[string]interface{})
updateProp["label"] = fmt.Sprintf("Updated Label %d", time.Now().UnixMicro())
updateProp["label"] = fmt.Sprintf("Updated Label %s", time.Now().String())

res, err := cli.CRM.Properties.Update("cars", "mileage", &updateProp)
if err != nil {
Expand Down
47 changes: 24 additions & 23 deletions crm_schemas.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,52 +9,53 @@ const (
)

type CrmSchemaAssociation struct {
Cardinality *HsStr `json:"cardinality"`
CreatedAt *HsTime `json:"createdAt"`
FromObjectTypeId *HsStr `json:"fromObjectTypeId"`
ID *HsStr `json:"id"`
InverseCardinality *HsStr `json:"inverseCardinality"`
Name *HsStr `json:"name"`
ToObjectTypeId *HsStr `json:"toObjectTypeId"`
Name *HsStr `json:"name"`
ID *HsStr `json:"id"`
CreatedAt *HsTime `json:"createdAt"`
UpdatedAt *HsTime `json:"updatedAt"`
Cardinality *HsStr `json:"cardinality"`
InverseCardinality *HsStr `json:"inverseCardinality"`
}

type CrmSchemaLabels struct {
Plural *HsStr `json:"plural"`
Singular *HsStr `json:"singular"`
Plural *HsStr `json:"plural"`
}

type CrmSchemasList struct {
Results []*CrmSchema
}

type CrmSchema struct {
Labels *CrmSchemaLabels `json:"labels,omitempty"`
PrimaryDisplayProperty *HsStr `json:"primaryDisplayProperty,omitempty"`
Archived *HsBool `json:"archived,omitempty"`
Associations []*CrmSchemaAssociation `json:"associations,omitempty"`
FullyQualifiedName *HsStr `json:"fullyQualifiedName,omitempty"`
ID *HsStr `json:"id,omitempty"`
Labels *CrmSchemaLabels `json:"labels,omitempty"`
MetaType *HsStr `json:"metaType,omitempty"`
Name *HsStr `json:"name,omitempty"`
FullyQualifiedName *HsStr `json:"fullyQualifiedName,omitempty"`
CreatedAt *HsTime `json:"createdAt,omitempty"`
UpdatedAt *HsTime `json:"updatedAt,omitempty"`
ObjectTypeId *HsStr `json:"objectTypeId,omitempty"`
PrimaryDisplayProperty *HsStr `json:"primaryDisplayProperty,omitempty"`
Properties []*CrmProperty `json:"properties,omitempty"`
Associations []*CrmSchemaAssociation `json:"associations,omitempty"`
Name *HsStr `json:"name,omitempty"`
MetaType *HsStr `json:"metaType,omitempty"`
RequiredProperties []*HsStr `json:"requiredProperties,omitempty"`
Restorable *HsBool `json:"restorable,omitempty"`
SearchableProperties []*HsStr `json:"searchableProperties,omitempty"`
SecondaryDisplayProperties []*HsStr `json:"secondaryDisplayProperties,omitempty"`
CreatedAt *HsTime `json:"createdAt,omitempty"`
UpdatedAt *HsTime `json:"updatedAt,omitempty"`
PortalId *HsInt `json:"portalId"`
}

// CrmSchemasService is an interface of CRM schemas endpoints of the HubSpot API.
// Reference: https://developers.hubspot.com/docs/api/crm/crm-custom-objects
type CrmSchemasService interface {
List() (*CrmSchemasList, error)
Create(reqData interface{}) (*CrmSchema, error)
Get(schemaIdentifier string) (*CrmSchema, error)
Delete(schemaIdentifier string, option *RequestQueryOption) error
Update(schemaIdentifier string, reqData interface{}) (*CrmSchema, error)
Get(objectType string) (*CrmSchema, error)
Delete(objectType string, option *RequestQueryOption) error
Update(objectType string, reqData interface{}) (*CrmSchema, error)
}

// CrmSchemasServiceOp handles communication with the CRM schemas endpoint.
Expand All @@ -81,23 +82,23 @@ func (s *CrmSchemasServiceOp) Create(reqData interface{}) (*CrmSchema, error) {
return &resource, nil
}

func (s *CrmSchemasServiceOp) Get(schemaIdentifier string) (*CrmSchema, error) {
func (s *CrmSchemasServiceOp) Get(objectType string) (*CrmSchema, error) {
var resource CrmSchema
path := fmt.Sprintf("%s/%s", s.crmSchemasPath, schemaIdentifier)
path := fmt.Sprintf("%s/%s", s.crmSchemasPath, objectType)
if err := s.client.Get(path, &resource, nil); err != nil {
return nil, err
}
return &resource, nil
}

func (s *CrmSchemasServiceOp) Delete(schemaIdentifier string, option *RequestQueryOption) error {
path := fmt.Sprintf("%s/%s", s.crmSchemasPath, schemaIdentifier)
func (s *CrmSchemasServiceOp) Delete(objectType string, option *RequestQueryOption) error {
path := fmt.Sprintf("%s/%s", s.crmSchemasPath, objectType)
return s.client.Delete(path, option)
}

func (s *CrmSchemasServiceOp) Update(schemaIdentifier string, reqData interface{}) (*CrmSchema, error) {
func (s *CrmSchemasServiceOp) Update(objectType string, reqData interface{}) (*CrmSchema, error) {
var resource CrmSchema
path := fmt.Sprintf("%s/%s", s.crmSchemasPath, schemaIdentifier)
path := fmt.Sprintf("%s/%s", s.crmSchemasPath, objectType)
if err := s.client.Patch(path, reqData, &resource); err != nil {
return nil, err
}
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/belong-inc/go-hubspot
go 1.16

require (
github.com/davecgh/go-spew v1.1.1
github.com/google/go-cmp v0.5.4
github.com/google/go-querystring v1.0.0
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/google/go-cmp v0.5.4 h1:L8R9j+yAqZuZjsqh/z+F1NCffTKKLShY6zXTItVIZ8M=
github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-querystring v1.0.0 h1:Xkwi/a1rcvNg1PPYe5vI8GbeBY/jrVuDX5ASuANWTrk=
Expand Down

0 comments on commit 0644886

Please sign in to comment.