-
Notifications
You must be signed in to change notification settings - Fork 4
/
import_service.go
110 lines (86 loc) · 2.12 KB
/
import_service.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package listmonk
import (
"context"
"encoding/json"
"net/http"
)
type ImportStatus struct {
Name string `json:"name"`
Total uint `json:"total"`
Imported uint `json:"imported"`
Status string `json:"status"`
}
type GetImportStatusService struct {
c ClientInterface
}
func (s *GetImportStatusService) Do(ctx context.Context, opts ...requestOption) (*ImportStatus, error) {
r := &request{
method: http.MethodGet,
endpoint: "/import/subscribers",
}
data, err := s.c.callAPI(ctx, r, opts...)
if err != nil {
return nil, err
}
var result map[string]*ImportStatus
if err := json.Unmarshal(data, &result); err != nil {
return nil, err
}
return result["data"], nil
}
type GetImportLogsService struct {
c ClientInterface
}
func (s *GetImportLogsService) Do(ctx context.Context, opts ...requestOption) (*string, error) {
r := &request{
method: http.MethodGet,
endpoint: "/import/subscribers/logs",
}
data, err := s.c.callAPI(ctx, r, opts...)
if err != nil {
return nil, err
}
var result map[string]*string
if err := json.Unmarshal(data, &result); err != nil {
return nil, err
}
return result["data"], nil
}
type ImportSubscribersService struct {
c ClientInterface
file []byte
params map[string]interface{}
}
func (s *ImportSubscribersService) File(file []byte) *ImportSubscribersService {
s.file = file
return s
}
func (s *ImportSubscribersService) Params(params map[string]interface{}) *ImportSubscribersService {
s.params = params
return s
}
func (s *ImportSubscribersService) Do(ctx context.Context, opts ...requestOption) error {
r := &request{
method: http.MethodPost,
endpoint: "/import/subscribers",
}
param, err := json.Marshal(s.params)
if err != nil {
return err
}
r.setJsonParam("params", param)
r.setJsonParam("file", s.file)
_, err = s.c.callAPI(ctx, r, opts...)
return err
}
type DeleteImportService struct {
c ClientInterface
}
func (s *DeleteImportService) Do(ctx context.Context, opts ...requestOption) error {
r := &request{
method: http.MethodDelete,
endpoint: "/import/subscribers",
}
_, err := s.c.callAPI(ctx, r, opts...)
return err
}