Skip to content

Commit

Permalink
Conversation visitor identification code refactored & all test cases …
Browse files Browse the repository at this point in the history
…failure issue resolved.
  • Loading branch information
Sehbaz committed Jan 3, 2024
1 parent 1920661 commit 79d951b
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 72 deletions.
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
}

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"`
LastName string `json:"lastname"`
Email string `json:"email"`
}

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

type VisitorIdentificationServiceOp struct {
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
11 changes: 4 additions & 7 deletions gohubspot.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,9 @@ type Client struct {

authenticator Authenticator

CRM *CRM
Marketing *Marketing

VisitorIdentification VisitorIdentificationService
CRM *CRM
Marketing *Marketing
Conversation *Conversation
}

// RequestPayload is common request structure for HubSpot APIs.
Expand Down Expand Up @@ -70,9 +69,6 @@ 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 All @@ -84,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
37 changes: 0 additions & 37 deletions visitor_identification.go

This file was deleted.

26 changes: 0 additions & 26 deletions visitor_identification_test.go

This file was deleted.

0 comments on commit 79d951b

Please sign in to comment.