-
Notifications
You must be signed in to change notification settings - Fork 30
/
crm_imports.go
73 lines (62 loc) · 2.12 KB
/
crm_imports.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
61
62
63
64
65
66
67
68
69
70
71
72
73
package hubspot
import (
"fmt"
)
const (
crmImportsBasePath = "imports"
)
// CrmImportsService is an interface of CRM bulk import endpoints of the HubSpot API.
// Reference: https://developers.hubspot.com/docs/api/crm/imports
type CrmImportsService interface {
Active(option *CrmActiveImportOptions) (interface{}, error)
Get(int64) (interface{}, error)
Cancel(int64) (interface{}, error)
Errors(int64, *CrmImportErrorsOptions) (interface{}, error)
Start(*CrmImportConfig) (interface{}, error)
}
// CrmImportsServiceOp handles communication with the bulk CRM import endpoints of the HubSpot API.
type CrmImportsServiceOp struct {
client *Client
crmImportsPath string
}
var _ CrmImportsService = (*CrmImportsServiceOp)(nil)
type CrmImportErrorsOptions struct {
After string `url:"after,omitempty"`
Limit int `url:"limit,omitempty"`
}
func (s *CrmImportsServiceOp) Errors(importId int64, option *CrmImportErrorsOptions) (interface{}, error) {
resource := make(map[string]interface{})
path := fmt.Sprintf("%s/%d/errors", s.crmImportsPath, importId)
if err := s.client.Get(path, &resource, option); err != nil {
return nil, err
}
return resource, nil
}
type CrmActiveImportOptions struct {
Before string `url:"before,omitempty"`
After string `url:"after,omitempty"`
Offset int `url:"offset,omitempty"`
}
func (s *CrmImportsServiceOp) Active(option *CrmActiveImportOptions) (interface{}, error) {
resource := make(map[string]interface{})
if err := s.client.Get(s.crmImportsPath, &resource, option); err != nil {
return nil, err
}
return resource, nil
}
func (s *CrmImportsServiceOp) Get(importId int64) (interface{}, error) {
resource := make(map[string]interface{})
path := fmt.Sprintf("%s/%d", s.crmImportsPath, importId)
if err := s.client.Get(path, &resource, nil); err != nil {
return nil, err
}
return resource, nil
}
func (s *CrmImportsServiceOp) Cancel(importId int64) (interface{}, error) {
resource := make(map[string]interface{})
path := fmt.Sprintf("%s/%d/cancel", s.crmImportsPath, importId)
if err := s.client.Post(path, &resource, nil); err != nil {
return nil, err
}
return resource, nil
}