email

package
v0.0.0-...-8d1786a Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2020 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// StatusSubscribed means a member is subscribed
	StatusSubscribed Status = "subscribed"

	// StatusUnsubscribed means a member is unsubscribed
	StatusUnsubscribed = "unsubscribed"

	// StatusInvalid means a member's status is invalid
	StatusInvalid = "invalid"

	// StatusPending means a member is pending or waiting of opt in
	StatusPending = "pending"
)
View Source
const (
	// ErrTitleResourceNotFound is the error response from Mailchimp
	ErrTitleResourceNotFound = "resource not found"
	// ErrTitleMemberExists is the error response from Mailchimp
	ErrTitleMemberExists = "member exists"
)
View Source
const (
	// ServiceNameMailchimp is the service name for Mailchimp
	ServiceNameMailchimp = "mailchimp"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Emailer

type Emailer struct {
	// contains filtered or unexported fields
}

Emailer is a struct that wraps around an Email provider and makes it a little easier to use.

func NewEmailer

func NewEmailer(apiKey string) *Emailer

NewEmailer is a convenience function that returns a new Emailer struct with the given apiKey

func NewEmailerWithSandbox

func NewEmailerWithSandbox(apiKey string, useSandbox bool) *Emailer

NewEmailerWithSandbox is a convenience function that returns a new Emailer struct with the given apiKey for use with the Sendgrid sandbox. FOR TESTING PURPOSES, use NewEmailer for production code.

func (*Emailer) SendEmail

func (e *Emailer) SendEmail(req *SendEmailRequest) error

SendEmail sends a basic email via the Email provider

func (*Emailer) SendTemplateEmail

func (e *Emailer) SendTemplateEmail(req *SendTemplateEmailRequest) error

SendTemplateEmail sends an email based on a template in the email provider.

type ListMember

type ListMember struct {
	ServiceID       string
	EmailAddress    string
	Status          Status
	SignupDate      time.Time
	LastUpdatedDate time.Time
	Tags            []Tag
}

ListMember represents some basic data about a member of a list.

type ListMemberManager

type ListMemberManager interface {
	// ServiceName returns the underlying mailing list service (sendgrid, mailchimp, etc.)
	ServiceName() string
	// GetListMember returns this member of the given list
	GetListMember(listID string, email string) (*ListMember, error)
	// IsSubscribedToList checks if email is subscribed to the given list
	IsSubscribedToList(listID string, email string) (bool, error)
	// SubscribeToList subscribes the email to a given list using the params
	SubscribeToList(listID string, email string, params *SubscriptionParams) error
	// UnsubscribeFromList unsubscribes the email from the given list. If delete
	// flag is true, will permanently delete from list.
	UnsubscribeFromList(listID string, email string, delete bool) error
}

ListMemberManager is an interface that represents a service that manages email lists consisting of members. This

type MailchimpAPI

type MailchimpAPI struct {
	// contains filtered or unexported fields
}

MailchimpAPI is a wrapper around the MailChimp API. Uses the gochimp lib.

func NewMailchimpAPI

func NewMailchimpAPI(apiKey string) *MailchimpAPI

NewMailchimpAPI is a convenience function to instantiate a new MailChimpAPI struct

func (*MailchimpAPI) GetListMember

func (m *MailchimpAPI) GetListMember(listID string, email string) (*ListMember, error)

GetListMember returns a Mailchimp mailing list member

func (*MailchimpAPI) IsSubscribedToList

func (m *MailchimpAPI) IsSubscribedToList(listID string, email string) (bool, error)

IsSubscribedToList returns true if an email is subscribed on a specified list

func (*MailchimpAPI) ServiceName

func (m *MailchimpAPI) ServiceName() string

ServiceName returns the underlying mailing list service

func (*MailchimpAPI) SubscribeToList

func (m *MailchimpAPI) SubscribeToList(listID string, email string, params *SubscriptionParams) error

SubscribeToList adds an email address to a specified list. Only adds tags on creation, not re-subscribes

func (*MailchimpAPI) UnsubscribeFromList

func (m *MailchimpAPI) UnsubscribeFromList(listID string, email string, delete bool) error

UnsubscribeFromList unsubscribes an email address from a specified list. The delete flag will completely delete it from a list.

type MailchimpTag

type MailchimpTag string

MailchimpTag is a Mailchimp tag

type Member

type Member struct {
	ID              string                 `json:"id"`
	EmailAddress    string                 `json:"email_address"`
	UniqueEmailID   string                 `json:"unique_email_id"`
	EmailType       members.EmailType      `json:"email_type,omitempty"`
	Status          members.Status         `json:"status"`
	MergeFields     map[string]interface{} `json:"merge_fields,omitempty"`
	Interests       map[string]bool        `json:"interests,omitempty"`
	Stats           *members.Stats         `json:"stats,omitempty"`
	IPSignup        string                 `json:"ip_signup,omitempty"`
	TimestampSignup time.Time              `json:"timestamp_signup,omitempty"`
	IPOpt           string                 `json:"ip_opt,omitempty"`
	TimestampOpt    time.Time              `json:"timestamp_opt,omitempty"`
	MemberRating    uint8                  `json:"member_rating,omitempty"`
	LastChanged     time.Time              `json:"last_changed,omitempty"`
	Language        string                 `json:"language,omitempty"`
	VIP             bool                   `json:"vip,omitempty"`
	EmailClient     string                 `json:"email_client,omitempty"`
	Location        *members.Location      `json:"location,omitempty"`
	LastNote        *members.Note          `json:"last_note,omitempty"`
	ListID          string                 `json:"list_id"`
	Tags            []*MemberTag           `json:"tags,omitempty"`
}

Member defines a single member within a list that adds a field for tags

type MemberTag

type MemberTag struct {
	ID   int    `json:"id,omitempty"`
	Name string `json:"name,omitempty"`
}

MemberTag represents a tag on a Member struct

type NewMemberParams

type NewMemberParams struct {
	EmailType       members.EmailType      `json:"email_type,omitempty"`
	Status          members.Status         `json:"status"`
	MergeFields     map[string]interface{} `json:"merge_fields,omitempty"`
	Interests       map[string]bool        `json:"interests,omitempty"`
	Language        string                 `json:"language,omitempty"`
	VIP             bool                   `json:"vip,omitempty"`
	Location        *members.Location      `json:"location,omitempty"`
	IPSignup        string                 `json:"ip_signup,omitempty"`
	TimestampSignup time.Time              `json:"timestamp_signup,omitempty"`
	IPOpt           string                 `json:"ip_opt,omitempty"`
	TimestampOpt    time.Time              `json:"timestamp_opt,omitempty"`
	EmailAddress    string                 `json:"email_address"`
	Tags            []MailchimpTag         `json:"tags,omitempty"`
}

NewMemberParams is a version of NewParams that adds a tags field

func (*NewMemberParams) MarshalJSON

func (np *NewMemberParams) MarshalJSON() ([]byte, error)

MarshalJSON handles custom JSON marshalling for the NewMembersParams object. Added here to correct the invalid timestamp format issue.

type SendEmailRequest

type SendEmailRequest struct {
	ToName    string
	ToEmail   string
	FromName  string
	FromEmail string
	Subject   string
	Text      string
	HTML      string
}

SendEmailRequest provides all the parameters to SendEmail to deliver an email.

type SendTemplateEmailRequest

type SendTemplateEmailRequest struct {
	ToName       string
	ToEmail      string
	FromName     string
	FromEmail    string
	TemplateID   string
	TemplateData TemplateData
	AsmGroupID   int
}

SendTemplateEmailRequest provides all the parameters to SendTemplateEmail to deliver an templated email.

type Status

type Status string

Status represents a status of a member in the mailing list service

type SubscriptionParams

type SubscriptionParams struct {
	Tags []Tag
}

SubscriptionParams is any data can be passed along for a subscription

type Tag

type Tag string

Tag is a tag on a mailing list member

type TemplateData

type TemplateData map[string]interface{}

TemplateData represents the key-value data for the template

Jump to

Keyboard shortcuts

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