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

Add client of Marketing domain to handle marketing email statistics #6

Merged
merged 8 commits into from
Jun 8, 2022
Merged
Show file tree
Hide file tree
Changes from 6 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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,4 @@ $(GOFMPT): | $(BIN) ## Install gofumpt

.PHONY: fmt
fmt: | $(GOFMPT) ## format files via gofumpt and list impacted files
$(BIN)/gofumpt -l -w .
@$(BIN)/gofumpt -l -w . ./legacy
22 changes: 22 additions & 0 deletions doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright 2021 Belong Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/*
Package hubspot is the root of packages used to access Hubspot APIs.

This library is targeting HubSpot API v3.
Docs are available in https://developers.hubspot.com/docs/api/overview.

*/
package hubspot
65 changes: 55 additions & 10 deletions example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package hubspot_test
import (
"fmt"
"log"
"os"

"github.com/belong-inc/go-hubspot"
)
Expand All @@ -16,7 +17,7 @@ type ExampleContact struct {
}

func ExampleContactServiceOp_Create() {
cli, _ := hubspot.NewClient(hubspot.SetAPIKey("apikey"))
cli, _ := hubspot.NewClient(hubspot.SetAPIKey(os.Getenv("API_KEY")))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made apikey to env var to prevent upload real apikey after testing.


example := &ExampleContact{
email: "hubspot@example.com",
Expand Down Expand Up @@ -53,7 +54,7 @@ func ExampleContactServiceOp_Create() {
}

func ExampleContactServiceOp_Update() {
cli, _ := hubspot.NewClient(hubspot.SetAPIKey("apikey"))
cli, _ := hubspot.NewClient(hubspot.SetAPIKey(os.Getenv("API_KEY")))

example := &ExampleContact{
email: "hubspot@example.com",
Expand Down Expand Up @@ -91,7 +92,7 @@ func ExampleContactServiceOp_Update() {
}

func ExampleContactServiceOp_Get() {
cli, _ := hubspot.NewClient(hubspot.SetAPIKey("apikey"))
cli, _ := hubspot.NewClient(hubspot.SetAPIKey(os.Getenv("API_KEY")))

res, err := cli.CRM.Contact.Get("contact001", &hubspot.Contact{}, nil)
if err != nil {
Expand All @@ -112,7 +113,7 @@ func ExampleContactServiceOp_Get() {
}

func ExampleContactServiceOp_AssociateAnotherObj() {
cli, _ := hubspot.NewClient(hubspot.SetAPIKey("apikey"))
cli, _ := hubspot.NewClient(hubspot.SetAPIKey(os.Getenv("API_KEY")))

res, err := cli.CRM.Contact.AssociateAnotherObj("contact001", &hubspot.AssociationConfig{
ToObject: hubspot.ObjectTypeDeal,
Expand Down Expand Up @@ -144,7 +145,7 @@ type ExampleDeal struct {
}

func ExampleDealServiceOp_Create_apikey() {
cli, _ := hubspot.NewClient(hubspot.SetAPIKey("apikey"))
cli, _ := hubspot.NewClient(hubspot.SetAPIKey(os.Getenv("API_KEY")))

example := &ExampleDeal{
amount: "1500.00",
Expand Down Expand Up @@ -227,7 +228,7 @@ type CustomDeal struct {
}

func ExampleDealServiceOp_Create_custom() {
cli, _ := hubspot.NewClient(hubspot.SetAPIKey("apikey"))
cli, _ := hubspot.NewClient(hubspot.SetAPIKey(os.Getenv("API_KEY")))

example := &ExampleDeal{
amount: "1500.00",
Expand Down Expand Up @@ -266,7 +267,7 @@ func ExampleDealServiceOp_Create_custom() {
}

func ExampleDealServiceOp_Update() {
cli, _ := hubspot.NewClient(hubspot.SetAPIKey("apikey"))
cli, _ := hubspot.NewClient(hubspot.SetAPIKey(os.Getenv("API_KEY")))

example := &ExampleDeal{
amount: "1500.00",
Expand Down Expand Up @@ -302,7 +303,7 @@ func ExampleDealServiceOp_Update() {
}

func ExampleDealServiceOp_Get() {
cli, _ := hubspot.NewClient(hubspot.SetAPIKey("apikey"))
cli, _ := hubspot.NewClient(hubspot.SetAPIKey(os.Getenv("API_KEY")))

res, err := cli.CRM.Deal.Get("deal001", &hubspot.Deal{}, nil)
if err != nil {
Expand All @@ -323,7 +324,7 @@ func ExampleDealServiceOp_Get() {
}

func ExampleDealServiceOp_Get_custom() {
cli, _ := hubspot.NewClient(hubspot.SetAPIKey("apikey"))
cli, _ := hubspot.NewClient(hubspot.SetAPIKey(os.Getenv("API_KEY")))

res, err := cli.CRM.Deal.Get("deal001", &CustomDeal{}, &hubspot.RequestQueryOption{
CustomProperties: []string{
Expand All @@ -349,7 +350,7 @@ func ExampleDealServiceOp_Get_custom() {
}

func ExampleDealServiceOp_AssociateAnotherObj() {
cli, _ := hubspot.NewClient(hubspot.SetAPIKey("apikey"))
cli, _ := hubspot.NewClient(hubspot.SetAPIKey(os.Getenv("API_KEY")))

res, err := cli.CRM.Deal.AssociateAnotherObj("deal001", &hubspot.AssociationConfig{
ToObject: hubspot.ObjectTypeContact,
Expand All @@ -372,3 +373,47 @@ func ExampleDealServiceOp_AssociateAnotherObj() {

// // Output:
}

func ExampleMarketingEmailOp_GetStatistics() {
cli, _ := hubspot.NewClient(hubspot.SetAPIKey(os.Getenv("API_KEY")))

emailID := 0 // Set proper value.
res, err := cli.Marketing.Email.GetStatistics(emailID, &hubspot.Statistics{}, nil)
if err != nil {
log.Fatal(err)
}

r, ok := res.Properties.(*hubspot.Statistics)
if !ok {
log.Fatal("unable to type assertion")
}

// use properties
_ = r

fmt.Printf("%+v", r)

// // Output:
}

func ExampleMarketingEmailOp_ListStatistics() {
cli, _ := hubspot.NewClient(hubspot.SetAPIKey(os.Getenv("API_KEY")))

statistics := make([]hubspot.Statistics, 0, 50)
res, err := cli.Marketing.Email.ListStatistics(&hubspot.BulkStatisticsResponse{Objects: statistics}, nil)
if err != nil {
log.Fatal(err)
}

r, ok := res.Properties.(*hubspot.BulkStatisticsResponse)
if !ok {
log.Fatal("unable to type assertion")
}

// use properties
_ = r

fmt.Printf("%+v", r)

// // Output:
}
3 changes: 2 additions & 1 deletion export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ var (
)

var (
ExportNewCRM = newCRM
ExportNewCRM = newCRM
ExportNewMarketing = newMarketing

ExportSetupProperties = (*RequestQueryOption).setupProperties

Expand Down
4 changes: 3 additions & 1 deletion gohubspot.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ type Client struct {

authenticator Authenticator

CRM *CRM
CRM *CRM
Marketing *Marketing
}

// RequestPayload is common request structure for HubSpot APIs.
Expand Down Expand Up @@ -77,6 +78,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)

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

Expand Down Expand Up @@ -165,6 +166,7 @@ func TestClient_NewRequest(t *testing.T) {
apiVersion string
authMethod hubspot.AuthMethod
crm *hubspot.CRM
marketing *hubspot.Marketing
}
type args struct {
method string
Expand Down
22 changes: 22 additions & 0 deletions legacy/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright 2021 Belong Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/*
Package legacy is the package for legacy APIs in Hubspot.

Not all APIs of Hubspot have been migrated v3 therefore components for legacy API is put in this package.
Docs are available in https://legacydocs.hubspot.com/docs/overview.

*/
package legacy
Loading