msActionMailgun

package
v0.0.0-...-0bff97c Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2017 License: Apache-2.0 Imports: 3 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NewMailgunMessageAction = func(jsonAction *json.RawMessage) (common.Action, error) {
	// Create an Action object from JSON.
	var action Action
	err := json.Unmarshal(*jsonAction, &action)
	if err != nil {
		return nil, err
	}

	client := mailgun.NewMailgun(
		action.MailgunDomain,
		action.MailgunAPIKey,
		action.MailgunPublicAPIKey,
	)
	action.SetMailgunClient(client)

	return action, nil
}

NewMailgunMessageAction implements the ActionFactory function type. It creates a Mailgun Message Action based on the given JSON-object, and initializes it by injecting the required Mailgun client.

Functions

This section is empty.

Types

type Action

type Action struct {
	// Common fields and functions for all Actions.
	common.ActionBase

	// Mailgun configuration.
	MailgunDomain       string `json:"mailgun_domain"`
	MailgunAPIKey       string `json:"mailgun_api_key"`
	MailgunPublicAPIKey string `json:"mailgun_public_api_key"`

	// Message details.
	MessageFrom    string `json:"message_from"`
	MessageTo      string `json:"message_to"`
	MessageSubject string `json:"message_subject"`
	MessageBody    string `json:"message_body"`
	// contains filtered or unexported fields
}

Action implements the common.Action interface. It provides an Action that sends an email message via Mailgun. The details of the message are hardcoded per action at the moment, but template capabilities will be provided in the future.

func (Action) Do

func (action Action) Do() error

Do Implements common.Action.Do(). It executes the Mailgun Action by sending the email message via Mailgun.

func (*Action) SetMailgunClient

func (action *Action) SetMailgunClient(client MailgunClient)

SetMailgunClient allows to inject a Mailgun client into the corresponding field.

type MailgunClient

type MailgunClient interface {
	Send(m *mailgun.Message) (string, string, error)
}

MailgunClient is an interface that is used to allow dependency injection of the client that makes the request to the Mailgun API. Dependency injection is necessary for testing purposes.

Jump to

Keyboard shortcuts

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