forked from mailtarget/mailtarget-go-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
layang.go
45 lines (37 loc) · 809 Bytes
/
layang.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
package layang
import (
"errors"
"github.com/go-resty/resty/v2"
)
const (
APIBase = "https://apiconfig.mailtarget.co"
)
type Layang struct {
apiBase string
apiVersion string
apiKey string
resty *resty.Client
}
func NewLayang(apiKey string) *Layang {
return &Layang{
apiBase: APIBase,
apiKey: apiKey,
apiVersion: "v1",
resty: resty.New(),
}
}
func (l *Layang) IsValid() error {
if l.apiKey == "" {
return errors.New("api key is empty")
}
return nil
}
func (l *Layang) Send(message *Message) (*SuccessResponse, *ErrorResponse, error) {
if err := l.IsValid(); err != nil {
return &SuccessResponse{}, &ErrorResponse{}, err
}
if err := message.IsValid(); err != nil {
return &SuccessResponse{}, &ErrorResponse{}, err
}
return l.sendMessage(message)
}