Skip to content

Commit

Permalink
Implement /users/merge method
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrei Hetmanski committed Dec 12, 2023
1 parent 61e84f8 commit f293a65
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions users.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const (
usersCreateAliasPath = "/users/alias/new"
usersDeletePath = "/users/delete"
usersIdentifyPath = "/users/identify"
usersMergePath = "/users/merge"
)

var (
Expand All @@ -33,6 +34,7 @@ type UsersEndpoint interface {
Delete(ctx context.Context, r *UsersDeleteRequest) (*Response, error)
Identify(ctx context.Context, r *UsersIdentifyRequest) (*Response, error)
CreateAlias(ctx context.Context, r *UsersCreateAliasRequest) (*Response, error)
Merge(ctx context.Context, r *UsersMergeRequest) (*Response, error)
}

type (
Expand Down Expand Up @@ -60,6 +62,10 @@ type UsersIdentifyRequest struct{}

type UsersCreateAliasRequest struct{}

type UsersMergeRequest struct {
MergeUpdates []*UsersMergeUpdates `json:"merge_updates,omitempty"`
}

// https://www.braze.com/docs/api/objects_filters/user_attributes_object/
type UserAttributes struct {
// Of the unique user identifier.
Expand Down Expand Up @@ -201,6 +207,21 @@ type UserEvent struct {
// TODO
type UserPurchase struct{}

type UsersMergeUpdates struct {
IdentifierToMerge *UsersIdentifierToMerge `json:"identifier_to_merge,omitempty"`
IdentifierToKeep *UsersIdentifierToKeep `json:"identifier_to_keep,omitempty"`
}

// Note: Braze supports more options for merging. See https://www.braze.com/docs/api/endpoints/user_data/post_users_merge/#request-parameters for more details. Update this structure if needed.
type UsersIdentifierToMerge struct {
ExternalID *string `json:"external_id,omitempty"`
}

// Note: Braze supports more options for keeping. See https://www.braze.com/docs/api/endpoints/user_data/post_users_merge/#request-parameters for more details. Update this structure if needed.
type UsersIdentifierToKeep struct {
ExternalID *string `json:"external_id,omitempty"`
}

func (s *UsersService) Track(ctx context.Context, r *UsersTrackRequest) (*Response, error) {
req, err := s.client.http.newRequest(http.MethodPost, usersTrackPath, r)
if err != nil {
Expand Down Expand Up @@ -236,3 +257,17 @@ func (s *UsersService) Identify(ctx context.Context, r *UsersIdentifyRequest) (*
func (s *UsersService) CreateAlias(ctx context.Context, r *UsersCreateAliasRequest) (*Response, error) {
panic(errors.New("not implemented"))
}

func (s *UsersService) Merge(ctx context.Context, r *UsersMergeRequest) (*Response, error) {
req, err := s.client.http.newRequest(http.MethodPost, usersMergePath, r)
if err != nil {
return nil, err
}

var res Response
if err := s.client.http.do(ctx, req, &res); err != nil {
return nil, err
}

return &res, nil
}

0 comments on commit f293a65

Please sign in to comment.