common

package
v0.0.0-...-8083f43 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 31, 2020 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SubscribersEndpoint = "/subscribers"
	SubscribeEndpoint   = "/subscribe"
	UnsubscribeEndpoint = "/unsubscribe"
	ComplaintsEndpoint  = "/complaints"
	ConfirmEndpoint     = "/confirm"
	ParamNewsletter     = "newsletter"
	ParamToken          = "token"
	ParamEmail          = "email"
	ParamName           = "name"
)
View Source
const (
	SoftBounceType = "sb"
	HardBounceType = "hb"
	ComplaintType  = "ct"
)

Variables

This section is empty.

Functions

func Sign

func Sign(secret, value string) string

Sign a value.

func Unsign

func Unsign(secret, msg string) (string, bool)

Unsign a value.

Types

type Bounce

type Bounce struct {
	BounceType        string          `json:"bounceType"`
	BounceSubType     string          `json:"bounceSubType"`
	BouncedRecipients []MailRecipient `json:"bouncedRecipients"`
	Timestamp         string          `json:"timestamp"`
	FeedbackID        string          `json:"feedbackId"`
	RemoteMtaIp       string          `json:"remoteMtaIp"`
}

type Complaint

type Complaint struct {
	UserAgent             string          `json:"userAgent"`
	ComplainedRecipients  []MailRecipient `json:"complainedRecipients"`
	ComplaintFeedbackType string          `json:"complaintFeedbackType"`
	ArrivalDate           string          `json:"arrivalDate"`
	Timestamp             string          `json:"timestamp"`
	FeedbackID            string          `json:"feedbackId"`
}

type JSONTime

type JSONTime time.Time

JSONTime is the time.Time with JSON marshal and unmarshal capability

func JsonTimeNow

func JsonTimeNow() JSONTime

JsonTimeNow() is an alias to time.Now() casted to JSONTime

func (*JSONTime) MarshalJSON

func (t *JSONTime) MarshalJSON() ([]byte, error)

MarshalJSON will marshal using 2006-01-02T15:04:05+07:00 layout

func (JSONTime) String

func (t JSONTime) String() string

String returns the time in the custom format

func (JSONTime) Time

func (t JSONTime) Time() time.Time

Time returns builtin time.Time for current JSONTime

func (*JSONTime) UnmarshalJSON

func (t *JSONTime) UnmarshalJSON(b []byte) error

UnmarshalJSON will unmarshal using 2006-01-02T15:04:05+07:00 layout

type Mail

type Mail struct {
	Timestamp        string                 `json:"timestamp"`
	Source           string                 `json:"source"`
	MessageId        string                 `json:"messageId"`
	HeadersTruncated bool                   `json:"headersTruncated"`
	Destination      []string               `json:"destination"`
	Headers          []map[string]string    `json:"headers"`
	CommonHeaders    map[string]interface{} `json:"commonHeaders"`
}

type MailRecipient

type MailRecipient struct {
	EmailAddress string `json:"emailAddress"`
}

type Mailer

type Mailer interface {
	SendConfirmation(newsletter, email, name, confirmURL string) error
}

Mailer is an interface for sending confirmation emails for subscriptions

type NotificationsStore

type NotificationsStore interface {
	AddBounce(email, from string, isTransient bool) error
	AddComplaint(email, from string) error
	Notifications() (notifications []*SesNotification, err error)
}

NotificationsStore is an interface used to manage SES bounce and complaint notifications from sesnotify API

type SesMessage

type SesMessage struct {
	NotificationType string                 `json:"notificationType"`
	Content          string                 `json:"content"`
	Mail             Mail                   `json:"mail"`
	Bounce           Bounce                 `json:"bounce"`
	Complaint        Complaint              `json:"complaint"`
	Receipt          map[string]interface{} `json:"receipt"`
}

type SesNotification

type SesNotification struct {
	Email        string   `json:"email"`
	From         string   `json:"from"`
	ReceivedAt   JSONTime `json:"received_at"`
	Notification string   `json:"notification"`
}

type Subscriber

type Subscriber struct {
	Name           string   `json:"name,omitempty"`
	Newsletter     string   `json:"newsletter"`
	Email          string   `json:"email"`
	CreatedAt      JSONTime `json:"created_at"`
	UnsubscribedAt JSONTime `json:"unsubscribed_at"`
	ConfirmedAt    JSONTime `json:"confirmed_at"`
	UserID         string   `json:"user_id,omitempty"`
}

Subscriber incapsulates newsletter subscriber information stored in the DynamoDB table

func (*Subscriber) Confirmed

func (s *Subscriber) Confirmed() bool

Confirmed checks if subscriber has confirmed the email via link

func (*Subscriber) Unsubscribed

func (s *Subscriber) Unsubscribed() bool

Unsubscribed checks if subscriber pressed "Unsubscribe" link

func (*Subscriber) Validate

func (s *Subscriber) Validate()

type SubscriberEx

type SubscriberEx struct {
	Name         string `json:"name" yaml:"name"`
	Newsletter   string `json:"newsletter" yaml:"newsletter"`
	Email        string `json:"email" yaml:"email"`
	Token        string `json:"token" yaml:"token"`
	Confirmed    bool   `json:"confirmed" yaml:"confirmed"`
	Unsubscribed bool   `json:"unsubscribed" yaml:"unsubscribed"`
	UserID       string `json:"user_id" yaml:"user_id"`
}

func NewSubscriberEx

func NewSubscriberEx(s *Subscriber, secret string) *SubscriberEx

type SubscriberKey

type SubscriberKey struct {
	Newsletter string `json:"newsletter"`
	Email      string `json:"email"`
}

SubscriberKey is used for deletion of subscribers

type SubscribersStore

type SubscribersStore interface {
	AddSubscriber(newsletter, email, name string) error
	RemoveSubscriber(newsletter, email string) error
	Subscribers(newsletter string) (subscribers []*Subscriber, err error)
	AddSubscribers(subscribers []*Subscriber) error
	DeleteSubscribers(keys []*SubscriberKey) error
	ConfirmSubscriber(newsletter, email string) error
	GetSubscriber(newsletter, email string) (*Subscriber, error)
}

SubscribersStore is an interface used to manage subscribers DB from the main API

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL