forked from sendgrid/sendgrid-go
-
Notifications
You must be signed in to change notification settings - Fork 1
/
sendgrid.go
57 lines (48 loc) · 1.48 KB
/
sendgrid.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
package sendgrid
import (
"github.com/sendgrid/rest"
)
// sendGridOptions for CreateRequest
type sendGridOptions struct {
Key string
Endpoint string
Host string
Subuser string
}
// GetRequest
// @return [Request] a default request object
func GetRequest(key, endpoint, host string) rest.Request {
return createSendGridRequest(sendGridOptions{key, endpoint, host, ""})
}
// GetRequestSubuser like GetRequest but with On-Behalf of Subuser
// @return [Request] a default request object
func GetRequestSubuser(key, endpoint, host, subuser string) rest.Request {
return createSendGridRequest(sendGridOptions{key, endpoint, host, subuser})
}
// createSendGridRequest create Request
// @return [Request] a default request object
func createSendGridRequest(sgOptions sendGridOptions) rest.Request {
options := options{
"Bearer " + sgOptions.Key,
sgOptions.Endpoint,
sgOptions.Host,
sgOptions.Subuser,
}
if options.Host == "" {
options.Host = "https://api.sendgrid.com"
}
return requestNew(options)
}
// NewSendClient constructs a new Twilio SendGrid client given an API key
func NewSendClient(key string) *Client {
request := GetRequest(key, "/v3/mail/send", "")
request.Method = "POST"
return &Client{request}
}
// GetRequestSubuser like NewSendClient but with On-Behalf of Subuser
// @return [Client]
func NewSendClientSubuser(key, subuser string) *Client {
request := GetRequestSubuser(key, "/v3/mail/send", "", subuser)
request.Method = "POST"
return &Client{request}
}