inboxroad

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2021 License: MIT Imports: 7 Imported by: 0

README

Inboxroad Library for Go

Getting Started

You will need an inboxroad account to get started.
Once you get an account, you will need to get your api key to use it in the API calls.

Installation

go get https://github.com/inboxroad/inboxroad-go

Usage

package main 

// Import the package
import (
    "fmt"
	"github.com/inboxroad/inboxroad-go"
	"os"
)

// Create the http client, we will need it later:
httpOptions := inboxroad.NewHTTPClientOptions().SetAPIKey(os.Getenv("INBOXROAD_API_KEY"))
httpClient := inboxroad.NewHTTPClient(httpOptions)

// Send email, method 1: 

// Create the message object
message := inboxroad.NewMessage().
    SetFromEmail(os.Getenv("INBOXROAD_SEND_EMAIL_FROM_EMAIL")).
    SetFromName("Inboxroad Go Client - Test Suite").
    SetToEmail(os.Getenv("INBOXROAD_SEND_EMAIL_TO_EMAIL")).
    SetToName("Inboxroad Tester").
    SetReplyToEmail(os.Getenv("INBOXROAD_SEND_EMAIL_FROM_EMAIL")).
    SetSubject("Inboxroad test").
    SetText("This is a test sent via the Inboxroad Go Client").
    SetHTML("<b>This is a test sent via the Inboxroad Go Client</b>").
    SetHeaders(
        inboxroad.NewMessageHeaderCollection().
            Add(inboxroad.NewMessageHeader("X-Test3", "Test 3")).
            Add(inboxroad.NewMessageHeader("X-Test4", "Test 4")),
    ).
    SetAttachments(
        inboxroad.NewMessageAttachmentCollection().
            Add(inboxroad.NewMessageAttachment("test-3.txt", "Test 3", "text/plain")).
            Add(inboxroad.NewMessageAttachment("test-4.txt", "Test 4", "text/plain")),
    )

// Create the endpoint connection
messages := inboxroad.NewMessagesAPI(httpClient)

// Send the message
response, err := messages.Send(message)

// Error?
if err != nil {
    panic(err)
}

// Get the status and the message id
fmt.Println(response.GetIsSuccess(), response.GetMessageID())

// ==

// Send email, method 2: 

// Create the message 
message := inboxroad.NewMessageFromMap(inboxroad.StringAnyMap{
    "fromEmail":    os.Getenv("INBOXROAD_SEND_EMAIL_FROM_EMAIL"),
    "fromName":     "Inboxroad Go Client - Test Suite",
    "toEmail":      os.Getenv("INBOXROAD_SEND_EMAIL_TO_EMAIL"),
    "toName":       "Inboxroad Tester",
    "replyToEmail": os.Getenv("INBOXROAD_SEND_EMAIL_FROM_EMAIL"),
    "subject":      "Inboxroad test",
    "text":         "This is a test sent via the Inboxroad Go Client",
    "html":         "<b>This is a test sent via the Inboxroad Go Client</b>",
    "headers": inboxroad.SliceStringMap{
        {
            "key":   "X-Test1",
            "value": "Test 1",
        },
        {
            "key":   "X-Test2",
            "value": "Test 2",
        },
    },
    "attachments": inboxroad.SliceStringMap{
        {
            "name":     "test-1.txt",
            "content":  "Test 1",
            "mimeType": "text/plain",
        },
        {
            "name":     "test-2.txt",
            "content":  "Test 2",
            "mimeType": "text/plain",
        },
    },
})

// Create the object instance
ir := inboxroad.NewInboxroad(httpClient)

// Send the message
response, err := ir.NewMessagesAPI().Send(message)

// Error?
if err != nil {
    panic(err)
}

// Get the status and the message id
fmt.Println(response.GetIsSuccess(), response.GetMessageID())

License

MIT

Test

Following environment variable must be set in order to test the actual sending process:
INBOXROAD_API_KEY - The API key for accessing the API
INBOXROAD_SEND_EMAIL_ENABLED - Whether the tests should send emails (1 | 0)
INBOXROAD_SEND_EMAIL_FROM_EMAIL - The email address from where the emails come from
INBOXROAD_SEND_EMAIL_TO_EMAIL - The email address where emails will go
Without these, the tests will run but no email will ever be sent.

Run the tests with:

$ go test ./...

Bug Reports

Report here.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HTTPClient

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

func NewHTTPClient

func NewHTTPClient(options HTTPClientOptionsInterface) *HTTPClient

func (*HTTPClient) NewRequest

func (h *HTTPClient) NewRequest() HTTPRequestInterface

type HTTPClientInterface

type HTTPClientInterface interface {
	NewRequest() HTTPRequestInterface
}

type HTTPClientOptions

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

func (HTTPClientOptions) GetAPIKey

func (h HTTPClientOptions) GetAPIKey() string

func (HTTPClientOptions) GetAuthScheme

func (h HTTPClientOptions) GetAuthScheme() string

func (HTTPClientOptions) GetHostURL

func (h HTTPClientOptions) GetHostURL() string

func (HTTPClientOptions) GetTLSConfig

func (h HTTPClientOptions) GetTLSConfig() *tls.Config

func (HTTPClientOptions) GetTimeout

func (h HTTPClientOptions) GetTimeout() time.Duration

func (*HTTPClientOptions) SetAPIKey

func (*HTTPClientOptions) SetAuthScheme

func (h *HTTPClientOptions) SetAuthScheme(scheme string) HTTPClientOptionsInterface

func (*HTTPClientOptions) SetHostURL

func (*HTTPClientOptions) SetTLSConfig

func (h *HTTPClientOptions) SetTLSConfig(config *tls.Config) HTTPClientOptionsInterface

func (*HTTPClientOptions) SetTimeout

type HTTPClientOptionsInterface

type HTTPClientOptionsInterface interface {
	SetHostURL(url string) HTTPClientOptionsInterface
	GetHostURL() string
	SetAuthScheme(scheme string) HTTPClientOptionsInterface
	GetAuthScheme() string
	SetAPIKey(apiKey string) HTTPClientOptionsInterface
	GetAPIKey() string
	SetTimeout(timeout time.Duration) HTTPClientOptionsInterface
	GetTimeout() time.Duration
	SetTLSConfig(config *tls.Config) HTTPClientOptionsInterface
	GetTLSConfig() *tls.Config
}

func NewHTTPClientOptions

func NewHTTPClientOptions() HTTPClientOptionsInterface

type HTTPRequest

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

func (*HTTPRequest) Get

func (*HTTPRequest) GetBody

func (h *HTTPRequest) GetBody() string

func (*HTTPRequest) Post

func (*HTTPRequest) SetBody

func (h *HTTPRequest) SetBody(body string) HTTPRequestInterface

type HTTPRequestInterface

type HTTPRequestInterface interface {
	SetBody(body string) HTTPRequestInterface
	GetBody() string
	Get(url string) (HTTPResponseInterface, error)
	Post(url string) (HTTPResponseInterface, error)
}

type HTTPResponse

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

func (HTTPResponse) GetBody

func (h HTTPResponse) GetBody() string

func (HTTPResponse) GetIsSuccess

func (h HTTPResponse) GetIsSuccess() bool

func (HTTPResponse) GetStatusCode

func (h HTTPResponse) GetStatusCode() int

func (*HTTPResponse) SetBody

func (h *HTTPResponse) SetBody(body string) HTTPResponseInterface

func (*HTTPResponse) SetIsSuccess

func (h *HTTPResponse) SetIsSuccess(isSuccess bool) HTTPResponseInterface

func (*HTTPResponse) SetStatusCode

func (h *HTTPResponse) SetStatusCode(statusCode int) HTTPResponseInterface

type HTTPResponseInterface

type HTTPResponseInterface interface {
	SetBody(body string) HTTPResponseInterface
	GetBody() string
	SetStatusCode(statusCode int) HTTPResponseInterface
	GetStatusCode() int
	SetIsSuccess(isSuccess bool) HTTPResponseInterface
	GetIsSuccess() bool
}

func NewHTTPResponse

func NewHTTPResponse() HTTPResponseInterface

type Inboxroad

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

func NewInboxroad

func NewInboxroad(httpClient HTTPClientInterface) *Inboxroad

func (Inboxroad) NewMessagesAPI

func (ir Inboxroad) NewMessagesAPI() MessagesAPIInterface

type InboxroadInterface

type InboxroadInterface interface {
	NewMessagesAPI() MessagesAPIInterface
}

type Message

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

func (Message) GetAttachments

func (m Message) GetAttachments() MessageAttachmentCollectionInterface

func (Message) GetFromEmail

func (m Message) GetFromEmail() string

func (Message) GetFromName

func (m Message) GetFromName() string

func (Message) GetHTML

func (m Message) GetHTML() string

func (Message) GetHeaders

func (Message) GetMessageID

func (m Message) GetMessageID() string

func (Message) GetReplyToEmail

func (m Message) GetReplyToEmail() string

func (Message) GetSubject

func (m Message) GetSubject() string

func (Message) GetText

func (m Message) GetText() string

func (Message) GetToEmail

func (m Message) GetToEmail() string

func (Message) GetToName

func (m Message) GetToName() string

func (*Message) SetAttachments

func (m *Message) SetAttachments(attachments MessageAttachmentCollectionInterface) MessageInterface

func (*Message) SetFromEmail

func (m *Message) SetFromEmail(email string) MessageInterface

func (*Message) SetFromName

func (m *Message) SetFromName(name string) MessageInterface

func (*Message) SetHTML

func (m *Message) SetHTML(html string) MessageInterface

func (*Message) SetHeaders

func (*Message) SetMessageID

func (m *Message) SetMessageID(messageID string) MessageInterface

func (*Message) SetReplyToEmail

func (m *Message) SetReplyToEmail(email string) MessageInterface

func (*Message) SetSubject

func (m *Message) SetSubject(subject string) MessageInterface

func (*Message) SetText

func (m *Message) SetText(text string) MessageInterface

func (*Message) SetToEmail

func (m *Message) SetToEmail(email string) MessageInterface

func (*Message) SetToName

func (m *Message) SetToName(name string) MessageInterface

func (Message) ToInboxroadMap

func (m Message) ToInboxroadMap() StringAnyMap

func (Message) ToMap

func (m Message) ToMap() StringAnyMap

type MessageAttachment

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

func (MessageAttachment) GetContent

func (m MessageAttachment) GetContent() string

func (MessageAttachment) GetContentAsBase64

func (m MessageAttachment) GetContentAsBase64() string

func (MessageAttachment) GetMimeType

func (m MessageAttachment) GetMimeType() string

func (MessageAttachment) GetName

func (m MessageAttachment) GetName() string

func (*MessageAttachment) SetContent

func (m *MessageAttachment) SetContent(content string) MessageAttachmentInterface

func (*MessageAttachment) SetMimeType

func (m *MessageAttachment) SetMimeType(mimeType string) MessageAttachmentInterface

func (*MessageAttachment) SetName

func (MessageAttachment) ToInboxroadMap

func (m MessageAttachment) ToInboxroadMap() StringMap

func (MessageAttachment) ToMap

func (m MessageAttachment) ToMap() StringMap

type MessageAttachmentCollection

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

func (*MessageAttachmentCollection) Add

func (*MessageAttachmentCollection) GetItems

func (MessageAttachmentCollection) ToInboxroadSliceMap

func (m MessageAttachmentCollection) ToInboxroadSliceMap() SliceStringMap

func (MessageAttachmentCollection) ToSliceMap

type MessageAttachmentCollectionInterface

type MessageAttachmentCollectionInterface interface {
	Add(header MessageAttachmentInterface) MessageAttachmentCollectionInterface
	GetItems() []MessageAttachmentInterface
	ToSliceMap() SliceStringMap
	ToInboxroadSliceMap() SliceStringMap
}

func NewMessageAttachmentCollection

func NewMessageAttachmentCollection() MessageAttachmentCollectionInterface

func NewMessageAttachmentCollectionFromSliceMap

func NewMessageAttachmentCollectionFromSliceMap(rawAttachments SliceStringMap) MessageAttachmentCollectionInterface

type MessageAttachmentInterface

type MessageAttachmentInterface interface {
	SetName(name string) MessageAttachmentInterface
	GetName() string
	SetContent(content string) MessageAttachmentInterface
	GetContent() string
	SetMimeType(mimeType string) MessageAttachmentInterface
	GetMimeType() string
	GetContentAsBase64() string
	ToMap() StringMap
	ToInboxroadMap() StringMap
}

func NewMessageAttachment

func NewMessageAttachment(name, content, mimeType string) MessageAttachmentInterface

type MessageHeader

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

func (MessageHeader) GetKey

func (m MessageHeader) GetKey() string

func (MessageHeader) GetValue

func (m MessageHeader) GetValue() string

func (*MessageHeader) SetKey

func (*MessageHeader) SetValue

func (m *MessageHeader) SetValue(value string) MessageHeaderInterface

func (MessageHeader) ToInboxroadMap

func (m MessageHeader) ToInboxroadMap() StringMap

func (MessageHeader) ToMap

func (m MessageHeader) ToMap() StringMap

type MessageHeaderCollection

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

func (*MessageHeaderCollection) Add

func (*MessageHeaderCollection) GetItems

func (MessageHeaderCollection) ToInboxroadMap

func (m MessageHeaderCollection) ToInboxroadMap() StringMap

func (MessageHeaderCollection) ToSliceMap

func (m MessageHeaderCollection) ToSliceMap() SliceStringMap

type MessageHeaderCollectionInterface

type MessageHeaderCollectionInterface interface {
	Add(header MessageHeaderInterface) MessageHeaderCollectionInterface
	GetItems() []MessageHeaderInterface
	ToSliceMap() SliceStringMap
	ToInboxroadMap() StringMap
}

func NewMessageHeaderCollection

func NewMessageHeaderCollection() MessageHeaderCollectionInterface

func NewMessageHeaderCollectionFromSliceMap

func NewMessageHeaderCollectionFromSliceMap(rawHeaders SliceStringMap) MessageHeaderCollectionInterface

type MessageHeaderInterface

type MessageHeaderInterface interface {
	SetKey(key string) MessageHeaderInterface
	GetKey() string
	SetValue(value string) MessageHeaderInterface
	GetValue() string
	ToMap() StringMap
	ToInboxroadMap() StringMap
}

func NewMessageHeader

func NewMessageHeader(key, value string) MessageHeaderInterface

type MessageInterface

type MessageInterface interface {
	SetMessageID(messageID string) MessageInterface
	GetMessageID() string
	SetFromEmail(email string) MessageInterface
	GetFromEmail() string
	SetFromName(name string) MessageInterface
	GetFromName() string
	SetToEmail(email string) MessageInterface
	GetToEmail() string
	SetToName(name string) MessageInterface
	GetToName() string
	SetReplyToEmail(email string) MessageInterface
	GetReplyToEmail() string
	SetSubject(subject string) MessageInterface
	GetSubject() string
	SetText(text string) MessageInterface
	GetText() string
	SetHTML(subject string) MessageInterface
	GetHTML() string
	SetHeaders(headers MessageHeaderCollectionInterface) MessageInterface
	GetHeaders() MessageHeaderCollectionInterface
	SetAttachments(attachments MessageAttachmentCollectionInterface) MessageInterface
	GetAttachments() MessageAttachmentCollectionInterface
	ToMap() StringAnyMap
	ToInboxroadMap() StringAnyMap
}

func NewMessage

func NewMessage() MessageInterface

func NewMessageFromMap

func NewMessageFromMap(params StringAnyMap) MessageInterface

type MessagesAPI

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

func NewMessagesAPI

func NewMessagesAPI(httpClient HTTPClientInterface) *MessagesAPI

func (*MessagesAPI) Send

type MessagesAPIInterface

type MessagesAPIInterface interface {
	Send(message MessageInterface) (MessagesAPISendResponseInterface, error)
}

type MessagesAPISendResponse

type MessagesAPISendResponse struct {
	HTTPResponse
}

func (MessagesAPISendResponse) GetMessageID

func (m MessagesAPISendResponse) GetMessageID() string

type MessagesAPISendResponseInterface

type MessagesAPISendResponseInterface interface {
	HTTPResponseInterface
	GetMessageID() string
}

func NewMessagesAPISendResponse

func NewMessagesAPISendResponse() MessagesAPISendResponseInterface

type SliceStringMap

type SliceStringMap = []StringMap

type StringAnyMap

type StringAnyMap = map[string]interface{}

type StringMap

type StringMap = map[string]string //nolint:nolintlint,gofumpt

Jump to

Keyboard shortcuts

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