Skip to content

Commit

Permalink
Merge pull request #6 from belong-inc/feature/add-marketing-email-sta…
Browse files Browse the repository at this point in the history
…tistics

Add client of Marketing domain to handle marketing email statistics
  • Loading branch information
ttyfky authored Jun 8, 2022
2 parents bf2c28e + 6956095 commit 9b2ab52
Show file tree
Hide file tree
Showing 15 changed files with 1,049 additions and 27 deletions.
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: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,17 +189,17 @@ fmt.Println(customDeal.CustomA, customDeal.CustomB)

# API availability

|Category | API | Availability |
|-------------|---------|--------------|
|CRM | Deal | Available |
|CRM | Contact | Available |
|CMS | All | Not Implemented |
|Conversations| All | Not Implemented |
|Events | All | Not Implemented |
|Marketing | All | Not Implemented |
|Files | All | Not Implemented |
|Settings | All | Not Implemented |
|Webhooks | All | Not Implemented |
|Category | API | Availability |
|-------------|-----------------|-----------------|
|CRM | Deal | Available |
|CRM | Contact | Available |
|CMS | All | Not Implemented |
|Conversations| All | Not Implemented |
|Events | All | Not Implemented |
|Marketing | Marketing Email | Available |
|Files | All | Not Implemented |
|Settings | All | Not Implemented |
|Webhooks | All | Not Implemented |

# Authentication availability

Expand Down
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
67 changes: 56 additions & 11 deletions example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ package hubspot_test
import (
"fmt"
"log"
"os"

"github.com/belong-inc/go-hubspot"
hubspot "github.com/belong-inc/go-hubspot"
)

type ExampleContact struct {
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")))

example := &ExampleContact{
email: "[email protected]",
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: "[email protected]",
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{})
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}, &hubspot.BulkRequestQueryOption{Limit: 10})
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
6 changes: 4 additions & 2 deletions 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 Expand Up @@ -218,7 +220,7 @@ func isErrorStatusCode(code int) bool {
}

// Get performs a GET request for the given path and saves the result in the given resource.
func (c *Client) Get(path string, resource interface{}, option *RequestQueryOption) error {
func (c *Client) Get(path string, resource interface{}, option interface{}) error {
return c.CreateAndDo(http.MethodGet, path, nil, option, resource)
}

Expand Down
4 changes: 3 additions & 1 deletion gohubspot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"testing"
"time"

"github.com/belong-inc/go-hubspot"
hubspot "github.com/belong-inc/go-hubspot"
"github.com/google/go-cmp/cmp"
)

Expand Down 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

0 comments on commit 9b2ab52

Please sign in to comment.