Skip to content

Commit

Permalink
Merge pull request #28 from KareHero/visitor-identification
Browse files Browse the repository at this point in the history
Visitor Identification module added.
  • Loading branch information
kk-no authored Jan 10, 2024
2 parents 4f48fed + a96869a commit 993402a
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 4 deletions.
18 changes: 18 additions & 0 deletions conversation.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package hubspot

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

type Conversation struct {
VisitorIdentification VisitorIdentificationService
}

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

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

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

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

type VisitorIdentificationServiceOp struct {
client *Client
basePath string
}

var _ VisitorIdentificationService = (*VisitorIdentificationServiceOp)(nil)

func (s *VisitorIdentificationServiceOp) GenerateIdentificationToken(option IdentificationTokenRequest) (*IdentificationTokenResponse, error) {
response := &IdentificationTokenResponse{}
path := s.basePath + "/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

0 comments on commit 993402a

Please sign in to comment.