goinblue

package module
v0.0.0-...-3ce63f9 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2017 License: MIT Imports: 9 Imported by: 0

README

GoDoc

Goinblue


A work in progress package for golang to send email and SMS through sendinblue.com
Usage

Example:

package main

import (
	"github.com/JesusIslam/goinblue"
	"fmt"
)

func main() {
	myApiKey := "thisisyourapikey"

	email := &goinblue.Email{
		To: map[string]string{
			"to@example.com": "Mr. To",
		},
		Subject: "Test",
		From: []string{
			"from@example.com", "From",
		},
		Text: "This is just a test.",
	}

	client := goinblue.NewClient(myApiKey)
	res, err := client.SendEmail(email)
	if err != nil {
		panic(err)
	}
	fmt.Println(res)
}

Documentation

Index

Constants

View Source
const (
	BASE_URL            = "https://api.sendinblue.com/v2.0"
	CONTENT_TYPE        = "application/json"
	EMAIL_URL           = "/email"
	EMAIL_TEMPLATE_URL  = "/template"
	SMS_URL             = "/sms"
	POST                = "POST"
	CONTENT_TYPE_HEADER = "Content-Type"
	API_KEY_HEADER      = "api-key"
)
View Source
const (
	TIME_FORMAT = "2013-06-20 20:09:22"
)

Variables

View Source
var (
	DEFAULT_SEND_TIMEOUT time.Duration = time.Second * 30
)

Functions

This section is empty.

Types

type Attachment

type Attachment map[string]string

This is here for documentation purpose

type AttachmentUrl

type AttachmentUrl []string

This is here for documentation purpose

type Email

type Email struct {
	To          map[string]string `json:"to"`
	Subject     string            `json:"subject"`
	From        []string          `json:"from"`
	Html        string            `json:"html"`
	Text        string            `json:"text"`
	Cc          map[string]string `json:"cc"`
	Bcc         map[string]string `json:"bcc"`
	ReplyTo     []string          `json:"replyto"`
	Attachment  interface{}       `json:"attachment"`
	Headers     map[string]string `json:"headers"`
	InlineImage map[string]string `json:"inline_image"`
}

Email request to be send

type EmailTemplate

type EmailTemplate struct {
	Id            int               `json:"id"`
	To            map[string]string `json:"to"`
	Cc            map[string]string `json:"cc"`
	Bcc           map[string]string `json:"bcc"`
	Attr          map[string]string `json:"attr"`
	AttachmentUrl []string          `json:"attachment_url"`
	Attachment    map[string]string `json:"attachment"`
	Headers       map[string]string `json:"headers"`
}

Email template request to be send

type Goinblue

type Goinblue struct {
	ApiKey            string
	Timeout           time.Duration
	BaseUrl           string
	ContentType       string
	Method            string
	ContentTypeHeader string
	ApiKeyHeader      string
	EmailUrl          string
	EmailTemplateUrl  string
	SMSUrl            string
}

The main struct of this package

func NewClient

func NewClient(apiKey string) *Goinblue

Create new Goinblue client with default values

func (*Goinblue) SendEmail

func (g *Goinblue) SendEmail(email *Email) (*Response, error)

Send email

func (*Goinblue) SendEmailTemplate

func (g *Goinblue) SendEmailTemplate(emailTemplate *EmailTemplate) (*Response, error)

Send email using template

func (*Goinblue) SendSMS

func (g *Goinblue) SendSMS(sms *SMS) (*Response, error)

type Response

type Response struct {
	Code    string      `json:"code"`
	Message string      `json:"message"`
	Data    interface{} `json:"data"`
}

The response from server

func (*Response) GetMessageId

func (r *Response) GetMessageId() (string, error)

To get message-id of a sent message

func (*Response) GetSMSResponseData

func (r *Response) GetSMSResponseData() (*SMSResponseData, error)

type SMS

type SMS struct {
	To     string `json:"to"`
	From   string `json:"from"`
	Text   string `json:"text"`
	WebUrl string `json:"web_url"`
	Tag    string `json:"tag"`
	Type   string `json:"type"`
}

type SMSResponseData

type SMSResponseData struct {
	Status          string            `json:"status"`
	Message         string            `json:"message"`
	NumberSent      int               `json:"number_sent"`
	To              string            `json:"to"`
	SMSCount        int               `json:"sms_count"`
	CreditsUsed     float64           `json:"credits_used"`
	RemainingCredit float64           `json:"remaining_credit"`
	Reference       map[string]string `json:"reference"`
	Description     string            `json:"description"`
	Reply           string            `json:"reply"`
	BounceType      string            `json:"bounce_type"`
	ErrorCode       int               `json:"error_code"`
}

type WebhookResponse

type WebhookResponse struct {
	Event         string    `json:"event"`
	Email         string    `json:"email"`
	Id            int64     `json:"id"`
	Date          time.Time `json:"date_time"`
	Ts            int64     `json:"ts"` // timestamp (same as Date but GMT)
	Subject       string    `json:"subject"`
	SendingIP     net.IP    `json:"sending-ip"`
	MessageId     string    `json:"message-id"`
	Tag           string    `json:"tag"`
	XMailinCustom string    `json:"X-Mailin-custom"`
	Reason        string    `json:"reason,omitempty"` // for "bounce" and "deferred" events only
	Link          string    `json:"link,omitempty"`   // for "click" events only
}

func (*WebhookResponse) UnmarshalJSON

func (e *WebhookResponse) UnmarshalJSON(b []byte) error

Jump to

Keyboard shortcuts

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