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 4 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
14 changes: 14 additions & 0 deletions conversation.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package hubspot

type Conversation struct {
VisitorIdentification VisitorIdentificationService
IdentificationTokenRequest IdentificationTokenRequest
Sehbaz marked this conversation as resolved.
Show resolved Hide resolved
}

func newConversation(c *Client) *Conversation {
return &Conversation{
VisitorIdentification: &VisitorIdentificationServiceOp{
client: c,
},
}
}
34 changes: 34 additions & 0 deletions conversation_visitor_identity.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package hubspot

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

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

type IdentificationTokenRequest struct {
FirstName string `json:"firstname"`
Sehbaz marked this conversation as resolved.
Show resolved Hide resolved
LastName string `json:"lastname"`
Email string `json:"email"`
}

type VisitorIdentificationService interface {
GenerateIdentificationToken(option IdentificationTokenRequest) (*IdentificationTokenResponse, error)
}

type VisitorIdentificationServiceOp struct {
Sehbaz marked this conversation as resolved.
Show resolved Hide resolved
client *Client
}

var _ VisitorIdentificationService = (*VisitorIdentificationServiceOp)(nil)

func (s *VisitorIdentificationServiceOp) GenerateIdentificationToken(option IdentificationTokenRequest) (*IdentificationTokenResponse, error) {
response := &IdentificationTokenResponse{}
path := visitorIdentificationBasePath + "/tokens/create"
if err := s.client.Post(path, option, response); err != nil {
return nil, err
}
return response, nil
}
5 changes: 3 additions & 2 deletions export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ var (
)

var (
ExportNewCRM = newCRM
ExportNewMarketing = newMarketing
ExportNewCRM = newCRM
ExportNewMarketing = newMarketing
ExportNewConversation = newConversation

ExportSetupProperties = (*RequestQueryOption).setupProperties

Expand Down
6 changes: 4 additions & 2 deletions gohubspot.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ type Client struct {

authenticator Authenticator

CRM *CRM
Marketing *Marketing
CRM *CRM
Marketing *Marketing
Conversation *Conversation
}

// RequestPayload is common request structure for HubSpot APIs.
Expand Down Expand Up @@ -79,6 +80,7 @@ func NewClient(setAuthMethod AuthMethod, opts ...Option) (*Client, error) {
// Since the baseURL and apiVersion may change, initialize the service after applying the options.
c.CRM = newCRM(c)
c.Marketing = newMarketing(c)
c.Conversation = newConversation(c)

return c, nil
}
Expand Down
1 change: 1 addition & 0 deletions gohubspot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ func TestNewClient(t *testing.T) {
want.ExportSetBaseURL(tt.settings.baseURL)
want.CRM = hubspot.ExportNewCRM(want)
want.Marketing = hubspot.ExportNewMarketing(want)
want.Conversation = hubspot.ExportNewConversation(want)
tt.settings.authMethod(want)
}

Expand Down
Loading