-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Visitor Identification module added.
- Loading branch information
Showing
3 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { | ||
response := &IdentificationTokenResponse{} | ||
path := visitorIdentificationBasePath + "/tokens/create" | ||
if err := s.client.Post(path, request, response); err != nil { | ||
return nil, err | ||
} | ||
return response, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() // Remove this line when you're ready to run the test | ||
|
||
cli, _ := NewClient(SetPrivateAppToken(os.Getenv("PRIVATE_APP_TOKEN"))) | ||
request := &IdentificationTokenRequest{ | ||
Email: "test@example.com", | ||
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") | ||
} | ||
} |