forked from belong-inc/go-hubspot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
marketing_email.go
60 lines (50 loc) · 2.09 KB
/
marketing_email.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package hubspot
import (
"fmt"
"github.com/belong-inc/go-hubspot/legacy"
)
const (
// NOTE: THe API of marketing email is not migrated to v3 yet.
marketingEmailBasePath = ""
)
type (
// Statistics is response from marketing email statistics API v1 as of now.
Statistics = legacy.StatisticsResponse
// BulkStatisticsResponse is response from marketing email statistics API v1 as of now.
// This contains list of Statistics.
BulkStatisticsResponse = legacy.BulkResponseResource
)
// MarketingEmailService is an interface of marketing email endpoints of the HubSpot API.
// As of May 2022, HubSpot provides only API v1 therefore the implementation is based on document in
// https://legacydocs.hubspot.com/docs/methods/cms_email/get-the-statistics-for-a-marketing-email.
type MarketingEmailService interface {
GetStatistics(emailID int, statistics interface{}) (*ResponseResource, error)
ListStatistics(statistics interface{}, option *BulkRequestQueryOption) (*ResponseResource, error)
}
type MarketingEmailOp struct {
marketingEmailBasePath string
client *Client
legacyAPIHelper legacy.MarketingEmailHelper
}
var _ MarketingEmailService = (*MarketingEmailOp)(nil)
// NewMarketingEmail creates a new MarketingEmailService.
func NewMarketingEmail(client *Client) MarketingEmailService {
return &MarketingEmailOp{
client: client,
legacyAPIHelper: legacy.NewMarketingEmailHelper(),
}
}
// GetStatistics get a Statistics for given emailID.
func (m *MarketingEmailOp) GetStatistics(emailID int, resource interface{}) (*ResponseResource, error) {
if err := m.client.Get(m.legacyAPIHelper.GetStatisticsPath()+fmt.Sprintf("/%d", emailID), resource, nil); err != nil {
return nil, err
}
return &ResponseResource{Properties: resource}, nil
}
// ListStatistics get a list of Statistics.
func (m *MarketingEmailOp) ListStatistics(resource interface{}, option *BulkRequestQueryOption) (*ResponseResource, error) {
if err := m.client.Get(m.legacyAPIHelper.GetStatisticsPath(), resource, option); err != nil {
return nil, err
}
return &ResponseResource{Properties: resource}, nil
}