sendy

package module
v0.0.0-...-bbf3477 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2023 License: BSD-3-Clause Imports: 9 Imported by: 0

README

sendygo nlshield

A simple Go client to interface with the Sendy API (https://sendy.co/api)

Project Links: Issues - Mailing List - Contributing

Version: 0.1.0

Sendy API Version: 6.0.3

Author Netlandish (http://www.netlandish.com)

Dependencies

  • It was written for Go 1.18+
  • No external dependencies are required

Installation

go get hg.code.netlandish.com/~netlandish/sendygo

Use

All the variables and response values are described in the Sendy API docs

Usage is simple:

import "hg.code.netlandish.com/~netlandish/sendygo" 

baseURL := "https://your-sendy-install.com/sendy/"
apiKey := "YOUR_API_KEY"
debug := true

client := sendy.NewClient(baseURL, apiKey, debug)

Subscribe :

    err := client.Subscribe(sendy.SusbcribeParams{
        List:     "list id here",
        Email:    "email@address.com",
        Name:     "Name",
        Country:  "NI",
        Referrer: "https://webpage.com",
        GDPR:     true,
    })

Fields

  • Email: user's email
  • List: the list id you want to subscribe a user to
  • Name: user's name (optional)
  • Country: user's 2 letter country code (optional)
  • IPAddress: user's IP address (optional)
  • Referrer: the URL where the user signed up from (optional)
  • GDPR: if you're signing up EU users in a GDPR compliant manner, set this to "true" (optional)
  • Silent: set to true if your list is 'Double opt-in' but you want to bypass that and signup the user to the list as 'Single Opt-in instead' (optional)
  • HP: include this 'honeypot' field to prevent spambots from signing up via this API call. (optional)

Unsubscribe :

    err := client.Unsubscribe(sendy.UnsusbcribeParams{
        List:     "list id here",
        Email:    "email@address.com",
    })

Delete :

    err := client.DeleteSubscriber(sendy.ActionParams{
        List:     "list id here",
        Email:    "email@address.com",
    })

Subscription Status :

    status, err = client.SubscriptionStatus(&sendy.ActionParams{
        List:     "list id here",
        Email:    "email@address.com",
    })

Subscriber Count :

	count, err := client.SubscriberCount(sendy.ActionParams{
        List:     "list id here",
	})

Create Campaign :

action, err := client.CreateCampaign(sendy.CreateCampaignParams{
	FromName:           "Your Name",
	FromEmail:          "Your Sender Email",
	ReplyTo:            "Your Reply-to Email",
	Title:              "Email Title",
	Subject:            "Email Subject",
	PlainText:          "Plain text for the email",
	HTMLText:           "<p>Html format for the email</p>",
	ListIDS:            "listIDOne,listIDTwo,listIDThree",
	BrandID:            "Your Brand ID",
	QueryString:        "Your Query String",
	SendCampaign:       1,
	SegmentIDS:         "SegmentOne, SegmentTwo",
	ExcludeListIDS:     "listIDOne,listIDTwo,listIDThree",
	ExcludeSegmentsIDS: "SegmentOne, SegmentTwo",
	TrackOpens:         1,
	TrackClicks:        1,
	ScheduleDateTime:   "June 15, 2023 6:05pm",
	ScheduleTimeZone:   "America/New_York",
})

Contributing

We accept patches submitted via hg email which is the patchbomb extension included with Mercurial.

Please see our contributing document for more information.

The mailing list where you submit your patches is ~netlandish/public-inbox@lists.code.netlandish.com. You can also view the archives on the web here:

https://lists.code.netlandish.com/~netlandish/public-inbox

To quickly setup your clone of sendygo to submit to the mailing list just edit your .hg/hgrc file and add the following:

[email]
to = ~netlandish/public-inbox@lists.code.netlandish.com

[patchbomb]
flagtemplate = {separate(' ', 'sendygo', flags)}

[diff]
git = 1

We have more information on the topic here:

All documentation, libraries, and sample code are Copyright 2022 Netlandish Inc. <hello@netlandish.com>. The library and sample code are made available to you under the terms of the BSD license which is contained in the included file, LICENSE.

Commercial Support

This software, and lots of other software like it, has been built in support of many of Netlandish's own projects, and the projects of our clients. We would love to help you on your next project so get in touch by dropping us a note at hello@netlandish.com.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrAPIResponse = errors.New("An API error occurred")

ErrAPIResponse APIError generic error type

View Source
var ErrParamsMissing = errors.New("required params missing")

ErrParamsMissing is raised when the required params are missing

Functions

func CleanParams

func CleanParams(values url.Values)

CleanParams strips out empty parameters

func ValidateParams

func ValidateParams(values url.Values, required []string) error

ValidateParams validates required params

Types

type ActionParams

type ActionParams struct {
	List  string
	Email string
}

ActionParams is aimed to perform actions over already registered email like subscription_status, delete and subscriber_count

Email: user's email List: the list id you want to subscribe a user to

type Brand

type Brand struct {
	ID   string `json:"id"`
	Name string `json:"name"`
}

Brand ...

type Client

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

Client defines the API host, API Key and the http Client to use, by default it is a http.Client instance, but you can change it using the SetDefault method

func NewClient

func NewClient(host, apiKey string, debug bool) *Client

NewClient return a new Client "instance"

func (*Client) Call

func (c *Client) Call(endpoint string, params url.Values, required []string) (*http.Response, error)

Call is a simple wrapper for client logic. It is used internally by all the endpoint func and get the request params and return a http.Response or an error. The params are: endpoind: API endpoint params: a url.Values map of the EP params required: a string slice with the required params for this EP

func (*Client) CreateCampaign

func (c *Client) CreateCampaign(p CreateCampaignParams) (string, error)

CreateCampaign endpoint. If succes it returns a string describing the action. It might be `Campaign created`, `Campaign created and now sending` or `Campaign scheduled`. Otherwise it returns an error. It reicives as params a CreateCampaignParams struct. The following fields are required FromName, FromEmail, ReplyTo, Title, Subject, HTMLText, TraskOpens, TrackClicks, ScheduleDateTime, ScheduleTimeZone.

func (*Client) DeleteSubscriber

func (c *Client) DeleteSubscriber(p ActionParams) error

DeleteSubscriber endpoint. It returns an error or nil if the request was sucessful It reicives as params a ActionParams struct where Email and List are required.

func (*Client) GetBrands

func (c *Client) GetBrands() ([]Brand, error)

GetBrands endpoint. If succeed returns a slice of Brand Otherwhise it returns an error

func (*Client) GetLists

func (c *Client) GetLists(p GetListsParams) ([]List, error)

GetLists endpoint. If succeed returns an slice of List Otherwhise it returns an error

Params BrandID: the id of the brand you want to get the list of lists from. IncludeHidden (optional): if you want to retrieve lists that are hidden as well, set this to yes. Default is no.

func (*Client) SetClient

func (c *Client) SetClient(newClient httpClient)

SetClient changes the http Client used for sending requests to the API Changing this might be useful for test purposes or using a proxy. By default it is an instance of http.Client. The new client must fulfill the `httpClient` interface that implements a PostForm func

func (*Client) Subscribe

func (c *Client) Subscribe(p SusbcribeParams) error

Subscribe endpoint. It returns an error or nil if the request was sucessful It reicives as params a SubscribeParam struct where Email and List are required. Optional fields are: Name, Country, IPAddress, Referrer, Silent, GDPR and HP

func (*Client) SubscriberCount

func (c *Client) SubscriberCount(p ActionParams) (string, error)

SubscriberCount endpoint. If success it returns a string describing the subscriber number, otherwise an error. It reicives as params a ActionParams struct where List is required

func (*Client) SubscriptionStatus

func (c *Client) SubscriptionStatus(p ActionParams) (string, error)

SubscriptionStatus endpoint. If success it returns a string describing the status, otherwise an error. Status might be `Subscribed`, `Unsubscribed`, `Unconfirmed`, `Bounced`, `Soft bounced` or `Complained` It reicives as params a ActionParams struct where Email and List are required.

func (*Client) Unsubscribe

func (c *Client) Unsubscribe(p UnsusbcribeParams) error

Unsubscribe endpoint. It returns an error or nil if the request was sucessful It reicives as params a UnsusbcribeParams struct where Email and List are required.

type CreateCampaignParams

type CreateCampaignParams struct {
	FromName           string
	FromEmail          string
	ReplyTo            string
	Title              string
	Subject            string
	PlainText          string
	HTMLText           string
	ListIDS            string
	BrandID            string
	QueryString        string
	SendCampaign       int64
	SegmentIDS         string
	ExcludeListIDS     string
	ExcludeSegmentsIDS string
	TrackOpens         int64
	TrackClicks        int64
	ScheduleDateTime   string
	ScheduleTimeZone   string
}

CreateCampaignParams ...

FormName: the 'From name' of your campaign FromEmail: the 'From email' of your campaign ReplyTo: the 'Reply to' of your campaign Title: the 'Title' of your campaign Subject: the 'Subject' of your campaign PlainText: the 'Plain text version' of your campaign (optional) HTMLText: the 'HTML version' of your campaign ListIDS: Required only if you set SendCampaign to 1 and no SegmentIDS are passed in. List IDs should be single or comma-separated. SegmentIDS: Required only if you set send_campaign to 1 and no list_ids are passed in. Segment IDs should be single or comma-separated. ExcludeList: ids Lists to exclude from your campaign. List IDs should be single or comma-separated.(optional) ExcludeSegmentsIDS: Segments to exclude from your campaign. Segment IDs should be single or comma-separated. (optional) BrandID: Required only if you are creating a 'Draft' campaign QueryString: eg. Google Analytics tags (optional) TrackOpens: Set to 0 to disable, 1 to enable and 2 for anonymous opens tracking. TrackClicks: Set to 0 to disable, 1 to enable and 2 for anonymous clicks tracking. SendCampaign: Set to 1 if you want to send the campaign as well and not just create a draft. Default is 0. ScheduleDateTime: Campaign will be scheduled if a valid date/time is passed. Date/time format. eg. June 15, 2021 6:05pm. ScheduleTimeZone: Eg. 'America/New_York'.

type GetListsParams

type GetListsParams struct {
	BrandID       string
	IncludeHidden string
}

GetListsParams ...

BrandID: the id of the brand you want to get the list of lists from. IncludeHidden: if you want to retrieve lists that are hidden as well, set this to yes. Default is no.

type List

type List struct {
	ID   string `json:"id"`
	Name string `json:"name"`
}

List ...

type SusbcribeParams

type SusbcribeParams struct {
	List      string
	Email     string
	Name      string
	Country   string
	IPAddress string
	Referrer  string
	Silent    bool
	GDPR      bool
	HP        string
}

SusbcribeParams ...

Email: user's email List: the list id you want to subscribe a user to Name: user's name (optional) Country: user's 2 letter country code (optional) IPAddress: user's IP address (optional) Referrer: the URL where the user signed up from (optional) GDPR: if you're signing up EU users in a GDPR compliant manner, set this to "true" (optional) Silent: set to true if your list is 'Double opt-in' but you want to bypass that and signup the user to the list as 'Single Opt-in instead' (optional) HP: include this 'honeypot' field to prevent spambots from signing up via this API call. (optional)

type UnsusbcribeParams

type UnsusbcribeParams struct {
	List  string
	Email string
}

UnsusbcribeParams ...

Email: user's email List: the list id you want to subscribe a user to

Jump to

Keyboard shortcuts

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