sgmock

package module
v0.0.0-...-31dbe18 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2018 License: MIT Imports: 1 Imported by: 0

README

sgmock

SendGrid API v3 mock for using in tests

API

  • /v3/mail/send -- mock for SendGrid API v3 send email endpoint
  • /ctl/list -- list all sent messages, message format is the same like for send operation
  • /ctl/clear -- clear list of sent messages

Examples

Send message:

POST http://dockerhost:9001/v3/mail/send
Content-Type: application/json
Accept: application/json
Authorization: Bearer key

{
    "personalizations": [
        {
            "subject": "test",
            "to": [
                {
                    "email": "user@mail.com"
                }
            ]
        }
    ],
    "from": {
        "email": "sender@mail.com"
    },
    "content": {
        "type": "text/plain",
        "value": "Hello!"
    }
}

List messages:

GET http://dockerhost:9001/ctl/list

Clear messages:

POST http://dockerhost:9001/ctl/clear

Docker

Image: vbogretsov/0.1.0

Port: 9001

Environment variables:

  • SGMOCK_KEY -- test value for SendGrid API key

License

See the LICENSE file.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Address

type Address struct {
	Email string `json:"email,omitempty"`
	Name  string `json:"name,omitempty"`
}

Address represents an email address.

type Content

type Content struct {
	Type  string `json:"type"`
	Value string `json:"value"`
}

Content represents SendGrid V3 API email body.

type Message

type Message struct {
	From             Address            `json:"from"`
	Personalizations []Personalizations `json:"personalizations"`
	Content          Content            `json:"content"`
}

Message represents SendGrid V3 API message.

type Mock

type Mock interface {
	Send(Message) error
	List() []Message
	Clear()
}

Mock represents SendGrid V3 test API.

func New

func New() Mock

New creates a new API.

type Personalizations

type Personalizations struct {
	Subject string    `json:"subject"`
	To      []Address `json:"to"`
	Cc      []Address `json:"cc,omitempty"`
	Bcc     []Address `json:"bcc,omitempty"`
}

Personalizations represents SendGrid V3 API personalizations.

Directories

Path Synopsis
cmd
sgmock command

Jump to

Keyboard shortcuts

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