You've already forked email-api-client
All checks were successful
🚀 Publish Release Package / publish (push) Successful in 22s
40 lines
806 B
Go
Executable File
40 lines
806 B
Go
Executable File
package client
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/json"
|
|
"net/http"
|
|
"time"
|
|
)
|
|
|
|
type EmailCreateResponse struct {
|
|
Id string `json:"id"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
}
|
|
|
|
func (client *Client) SendEmail(request *EmailRequest) (*EmailCreateResponse, error) {
|
|
jsonData, _ := json.Marshal(request)
|
|
|
|
httpClient := &http.Client{}
|
|
req, _ := http.NewRequest(
|
|
"POST",
|
|
client.config.Endpoint+"/api/email",
|
|
bytes.NewReader(jsonData),
|
|
)
|
|
req.Header.Set("Authorization", client.token.TokenType+" "+client.token.AccessToken)
|
|
req.Header.Set("Content-Type", "application/json")
|
|
|
|
resp, err := httpClient.Do(req)
|
|
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
response, err := readResponseBody[Response[EmailCreateResponse]](resp)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &response.Payload, nil
|
|
}
|