Commit from m3o/m3o action

This commit is contained in:
m3o-actions
2022-01-26 13:06:45 +00:00
parent 9cd82a849f
commit 9547c26947
25 changed files with 1314 additions and 1186 deletions

View File

@@ -5,7 +5,9 @@ import (
)
type Email interface {
Parse(*ParseRequest) (*ParseResponse, error)
Send(*SendRequest) (*SendResponse, error)
Validate(*ValidateRequest) (*ValidateResponse, error)
}
func NewEmailService(token string) *EmailService {
@@ -20,6 +22,14 @@ type EmailService struct {
client *client.Client
}
// Parse an RFC5322 address e.g "Joe Blogs <joe@example.com>"
func (t *EmailService) Parse(request *ParseRequest) (*ParseResponse, error) {
rsp := &ParseResponse{}
return rsp, t.client.Call("email", "Parse", request, rsp)
}
// Send an email by passing in from, to, subject, and a text or html body
func (t *EmailService) Send(request *SendRequest) (*SendResponse, error) {
@@ -28,6 +38,26 @@ func (t *EmailService) Send(request *SendRequest) (*SendResponse, error) {
}
// Validate an email address format
func (t *EmailService) Validate(request *ValidateRequest) (*ValidateResponse, error) {
rsp := &ValidateResponse{}
return rsp, t.client.Call("email", "Validate", request, rsp)
}
type ParseRequest struct {
// The address to parse. Can be of the format "Joe Blogs <joe@example.com>" or "joe@example.com"
Address string `json:"address"`
}
type ParseResponse struct {
// the email address
Address string `json:"address"`
// associated name e.g Joe Blogs
Name string `json:"name"`
}
type SendRequest struct {
// the display name of the sender
From string `json:"from"`
@@ -45,3 +75,11 @@ type SendRequest struct {
type SendResponse struct {
}
type ValidateRequest struct {
Address string `json:"address"`
}
type ValidateResponse struct {
IsValid bool `json:"is_valid"`
}