Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Visitor Identification module added. #28

Merged
merged 6 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions gohubspot.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ type Client struct {

CRM *CRM
Marketing *Marketing

VisitorIdentification VisitorIdentificationService
Sehbaz marked this conversation as resolved.
Show resolved Hide resolved
}

// RequestPayload is common request structure for HubSpot APIs.
Expand Down Expand Up @@ -68,6 +70,11 @@ func NewClient(setAuthMethod AuthMethod, opts ...Option) (*Client, error) {
apiVersion: defaultAPIVersion,
}

// Initialize the VisitorIdentification field
c.VisitorIdentification = &VisitorIdentificationServiceOp{
client: c,
}

// Set the authentication method specified by the argument.
// Authentication method is either APIKey or OAuth.
setAuthMethod(c)
Expand Down
31 changes: 31 additions & 0 deletions visitor_identification.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package hubspot

const (
visitorIdentificationBasePath = "/conversations/v3/visitor-identification"
)

// VisitorIdentificationService is an interface of visitor identification endpoints of the HubSpot API.
type VisitorIdentificationService interface {
GenerateIdentificationToken(request interface{}) (*IdentificationTokenResponse, error)
}

// VisitorIdentificationServiceOp handles communication with the Visitor Identification related methods of the HubSpot API.
type VisitorIdentificationServiceOp struct {
client *Client
}

type IdentificationTokenResponse struct {
Token string `json:"token"`
}

// Create creates a Identification Token.
// In order to bind the created content, a structure must be specified as an argument.
// When using custom fields, please embed hubspot.request in your own structure.
func (s *VisitorIdentificationServiceOp) GenerateIdentificationToken(request interface{}) (*IdentificationTokenResponse, error) {
Sehbaz marked this conversation as resolved.
Show resolved Hide resolved
response := &IdentificationTokenResponse{}
path := visitorIdentificationBasePath + "/tokens/create"
if err := s.client.Post(path, request, response); err != nil {
return nil, err
}
return response, nil
}
31 changes: 31 additions & 0 deletions visitor_identification_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package hubspot

import (
"os"
"testing"
)

type IdentificationTokenRequest struct {
Email string `json:"email"`
FirstName string `json:"firstName"`
LastName string `json:"lastName"`
}

func TestGenerateIdentificationToken(t *testing.T) {
t.SkipNow()

cli, _ := NewClient(SetPrivateAppToken(os.Getenv("PRIVATE_APP_TOKEN")))
request := &IdentificationTokenRequest{
Email: "[email protected]",
FirstName: "Test",
}

response, err := cli.VisitorIdentification.GenerateIdentificationToken(request)
if err != nil {
t.Error(err)
}

if response.Token == "" {
t.Errorf("expected response.Token to be not empty")
}
}
Loading