mailerlite

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2022 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package maierlite provides a client for using the MailerLite API.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckResponse

func CheckResponse(r *http.Response) error

CheckResponse checks the API response for errors, and returns them if present. A response is considered an error if it has a status code outside the 200 range. API error responses are expected to have response body, and a JSON response body that maps to ErrorResponse.

The error type will be *RateLimitError for rate limit exceeded errors, *AcceptedError for 202 Accepted status codes, and *TwoFactorAuthError for two-factor authentication errors.

Types

type CampaignsService

type CampaignsService service

CampaignsService handles communication with the campaign related methods of the MailerLite API.

MailerLite API docs: https://developers.mailerlite.com/reference/campaigns-by-type

type Client

type Client struct {

	// Services used for talking to different parts of the MailerLite API.
	Campaigns   *CampaignsService
	Segments    *SegmentsService
	Subscribers *SubscribersService
	Groups      *GroupsService
	Fields      *FieldsService
	Webhooks    *WebhooksService
	Stats       *StatsService
	Settings    *SettingsService
	// contains filtered or unexported fields
}

A Client manages communication with the MailerLite API.

func NewClient

func NewClient(apiKey string, opts ...ClientOption) (*Client, error)

NewClient returns a new MailerLite API client.

func (*Client) BareDo

func (c *Client) BareDo(req *http.Request) (*Response, error)

BareDo sends an API request and lets you handle the api response. If an error or API Error occurs, the error will contain more information. Otherwise you are supposed to read and close the response's Body. If rate limit is exceeded and reset time is in the future, BareDo returns *RateLimitError immediately without making a network API call.

func (*Client) Do

func (c *Client) Do(req *http.Request, v interface{}) (*Response, error)

Do sends an API request and returns the API response. The API response is JSON decoded and stored in the value pointed to by v, or returned as an error if an API error has occurred. If v implements the io.Writer interface, the raw response body will be written to v, without attempting to first decode it. If v is nil, and no error hapens, the response is returned as is.

func (*Client) NewRequest

func (c *Client) NewRequest(ctx context.Context, method string, urlStr string, body interface{}) (*http.Request, error)

NewRequest creates an API request. A relative URL can be provided in urlStr, in which case it is resolved relative to the baseURL of the Client. Relative URLs should always be specified without a preceding slash. If specified, the value pointed to by body is JSON encoded and included as the request body.

type ClientOption

type ClientOption interface {
	// contains filtered or unexported methods
}

ClientOption configures a Client.

func BaseURL

func BaseURL(baseURL *url.URL) ClientOption

BaseURL tells a Client where to send API requests to. Defaults to the public MailerLite API, but can be set to a different URL. BaseURL should always be specified with a trailing slash.

func HTTPClient

func HTTPClient(httpClient *http.Client) ClientOption

HTTPClient configures a Client to use a specific HTTP client for communicating with the API.

func UserAgent

func UserAgent(userAgent string) ClientOption

UserAgent configures a Client to send API requests with a specific user agent header.

type Error

type Error struct {
	Code    int    `json:"code"`    // Error code (optional)
	Message string `json:"message"` // Human-readable error message
}

Error contains details about what went wrong during a failed API request.

func (Error) Error

func (e Error) Error() string

type ErrorResponse

type ErrorResponse struct {
	Response *http.Response // HTTP response that caused this error

	Err Error `json:"error"`
}

ErrorResponse wraps the returned HTTP response and error.

func (*ErrorResponse) Error

func (r *ErrorResponse) Error() string

type Field

type Field struct {
	ID          WeakInt   `json:"id"`
	Title       string    `json:"title"`
	Key         string    `json:"key"`
	Type        FieldType `json:"type"`
	DateUpdated Timestamp `json:"date_updated"`
	DateCreated Timestamp `json:"date_created"`
}

Field represents a custom field in a subscriber profile.

type FieldType

type FieldType string

FieldType represents the type of data a field can store.

const (
	Text   FieldType = "TEXT"
	Number FieldType = "NUMBER"
	Date   FieldType = "DATE"
)

type FieldUpdate

type FieldUpdate struct {
	Title string `json:"title,omitempty"`
}

FieldUpdate represents information that needs to be updated in a field.

type FieldsService

type FieldsService service

FieldsService handles communication with the field related methods of the MailerLite API.

MailerLite API docs: https://developers.mailerlite.com/reference/all-fields

func (*FieldsService) Create

func (s *FieldsService) Create(ctx context.Context, newField NewField) (*Field, *Response, error)

Create a new field.

MailerLite API docs: https://developers.mailerlite.com/reference/create-field

func (*FieldsService) Delete

func (s *FieldsService) Delete(ctx context.Context, id int) (*Response, error)

Delete a field.

MailerLite API docs: https://developers.mailerlite.com/reference/all-fields

func (*FieldsService) List

func (s *FieldsService) List(ctx context.Context) ([]Field, *Response, error)

List all fields.

MailerLite API docs: https://developers.mailerlite.com/reference/all-fields

func (*FieldsService) Update

func (s *FieldsService) Update(ctx context.Context, id int, update FieldUpdate) (*Field, *Response, error)

Update a field.

MailerLite API docs: https://developers.mailerlite.com/reference/update-field

type GroupsService

type GroupsService service

GroupsService handles communication with the group related methods of the MailerLite API.

MailerLite API docs: https://developers.mailerlite.com/reference/groups

func (*GroupsService) AddSubscriber

func (s *GroupsService) AddSubscriber(ctx context.Context, id int, newSubscriber NewSubscriberInGroup) (*Subscriber, *Response, error)

Add a subscriber to a group.

MailerLite API docs: https://developers.mailerlite.com/reference/add-single-subscriber

type ListOptions

type ListOptions struct {
	Offset int `url:"offset,omitempty"`
	Limit  int `url:"limit,omitempty"`
}

ListOptions specifies the optional parameters to various List methods that support pagination.

type NewField

type NewField struct {
	Title string    `json:"title,omitempty"`
	Type  FieldType `json:"type,omitempty"`
}

NewField represents a new field to be created.

type NewSubscriberInGroup

type NewSubscriberInGroup struct {
	Email          string            `json:"email,omitempty"`
	Name           string            `json:"name,omitempty"`
	Fields         map[string]string `json:"fields,omitempty"`
	Resubscribe    *bool             `json:"resubscribe,omitempty"`
	AutoResponders *bool             `json:"autoresponders,omitempty"`
	Type           SubscriptionType  `json:"type,omitempty"`
}

NewSubscriberInGroup represents a new subscriber in a group.

type Response

type Response struct {
	*http.Response
}

Response is a MailerLite API response. This wraps the standard http.Response returned from MailerLite and provides convenient access to things like rate limit information.

type SegmentsService

type SegmentsService service

SegmentsService handles communication with the segment related methods of the MailerLite API.

MailerLite API docs: https://developers.mailerlite.com/reference/segments-1

type SettingsService

type SettingsService service

SettingsService handles communication with the setting related methods of the MailerLite API.

MailerLite API docs: https://developers.mailerlite.com/reference/get-double-optin-status

type StatGetOptions

type StatGetOptions struct {
	// Specify UNIX timestamp if you want to receive stats values at the specific point in the past.
	// Default: none
	Timestamp int32 `url:"visibility,omitempty"`
}

StatGetOptions specifies the optional parameters to the StatsService.Get method.

type Stats

type Stats struct {
	Subscribed   int     `json:"subscribed"`
	Unsubscribed int     `json:"unsubscribed"`
	Campaigns    int     `json:"campaigns"`
	SentEmails   int     `json:"sent_emails"`
	OpenRate     float64 `json:"open_rate"`
	ClickRate    float64 `json:"click_rate"`
	BounceRate   float64 `json:"bounce_rate"`
}

Stats represents account statistics.

type StatsService

type StatsService service

StatsService handles communication with the stat related methods of the MailerLite API.

MailerLite API docs: https://developers.mailerlite.com/reference/stats

func (*StatsService) Get

func (s *StatsService) Get(ctx context.Context, opts *StatGetOptions) (*Stats, *Response, error)

Get basic stats for of account, such as subscribers, open/click rates and so on.

MailerLite API docs: https://developers.mailerlite.com/reference/stats

type Subscriber

type Subscriber struct {
	ID      int              `json:"id"`
	Name    string           `json:"name"`
	Email   string           `json:"email"`
	Sent    int              `json:"sent"`
	Opened  int              `json:"opened"`
	Clicked int              `json:"clicked"`
	Type    SubscriptionType `json:"type"`
	// CountryID             string            `json:"country_id"`
	SignupIP              *string           `json:"signup_ip"`
	SignupTimestamp       *string           `json:"signup_timestamp"`
	ConfirmationIP        *string           `json:"confirmation_ip"`
	ConfirmationTimestamp *string           `json:"confirmation_timestamp"`
	Fields                []SubscriberField `json:"fields"`
	DateSubscribe         *Timestamp        `json:"date_subscribe"`
	DateUnsubscribe       *Timestamp        `json:"date_unsubscribe"`
	DateCreated           Timestamp         `json:"date_created"`
	DateUpdated           *Timestamp        `json:"date_updated"`
}

Subscriber represents an email subscriber.

type SubscriberField

type SubscriberField struct {
	Key   string `json:"key"`
	Value string `json:"value"`
	Type  string `json:"type"`
}

SubscriberField represents a custom field and its value.

type SubscriberListOptions

type SubscriberListOptions struct {
	Type SubscriptionType `url:"type,omitempty"`

	ListOptions
}

SubscriberListOptions specifies the optional parameters to the SubscribersService.List method.

type SubscriberUpdate added in v0.0.4

type SubscriberUpdate struct {
	Name                 string            `json:"name,omitempty"`
	Type                 SubscriptionType  `json:"type,omitempty"`
	Fields               []SubscriberField `json:"fields,omitempty"`
	ResendAutoresponders *bool             `json:"resend_autoresponders,omitempty"`
}

SubscriberUpdate

type SubscribersService

type SubscribersService service

SubscribersService handles communication with the subscriber related methods of the MailerLite API.

MailerLite API docs: https://developers.mailerlite.com/reference/subscribers

func (*SubscribersService) Get

Get fetches a subscriber.

MailerLite API docs: https://developers.mailerlite.com/reference/single-subscriber

func (*SubscribersService) List

List all subscribers.

MailerLite API docs: https://developers.mailerlite.com/reference/subscribers

func (*SubscribersService) Update added in v0.0.4

func (s *SubscribersService) Update(ctx context.Context, email string, update SubscriberUpdate) (*Subscriber, *Response, error)

Update updates a subscriber.

MailerLite API docs: https://developers.mailerlite.com/reference/update-subscriber

type SubscriptionType

type SubscriptionType string

SubscriptionType represents the current state of the subscription.

const (
	Unsubscribed SubscriptionType = "unsubscribed"
	Active       SubscriptionType = "active"
	Unconfirmed  SubscriptionType = "unconfirmed"
	Bounced      SubscriptionType = "bounced"
	Junk         SubscriptionType = "junk"
)

type Timestamp

type Timestamp struct {
	time.Time
}

Timestamp represents a time that can be unmarshalled from a JSON string formatted as either an RFC3339 or Unix timestamp. All exported methods of time.Time can be called on Timestamp.

func (Timestamp) Equal

func (t Timestamp) Equal(u Timestamp) bool

Equal reports whether t and u are equal based on time.Equal.

func (Timestamp) String

func (t Timestamp) String() string

func (*Timestamp) UnmarshalJSON

func (t *Timestamp) UnmarshalJSON(data []byte) (err error)

UnmarshalJSON implements the json.Unmarshaler interface. Time is expected in RFC3339 or Unix format.

type WeakInt

type WeakInt int

WeakInt can be used in places where the return type may be both int and string.

func (*WeakInt) UnmarshalJSON

func (w *WeakInt) UnmarshalJSON(data []byte) (err error)

UnmarshalJSON implements the json.Unmarshaler interface.

type WebhooksService

type WebhooksService service

WehooksService handles communication with the webhook related methods of the MailerLite API.

MailerLite API docs: https://developers.mailerlite.com/reference/get-webhooks-list

Jump to

Keyboard shortcuts

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