convertkit

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2019 License: MPL-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package convertkit provides a client to the ConvertKit API v3. See http://help.convertkit.com/article/33-api-documentation-v3

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrKeyMissing is returned when the API key is required, but not present.
	ErrKeyMissing = errors.New("ConvertKit API key missing")

	// ErrSecretMissing is returned when the API secret is required, but not present.
	ErrSecretMissing = errors.New("ConvertKit API secret missing")
)

Functions

This section is empty.

Types

type Client

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

Client is the client to the ConvertKit API. Create a client with NewClient.

func NewClient

func NewClient(c *Config) (*Client, error)

NewClient returns a new client for the given configuration.

func (*Client) CreateTagSubscription added in v0.4.1

func (c *Client) CreateTagSubscription(req SubscriptionRequest) (Subscription, error)

CreateTagSubscription tags a subscriber with a tag whild allowing access to set the optional parameters allowed by ConvertKit through a `SubscriptionRequest`

func (*Client) Subscribers

func (c *Client) Subscribers(query *SubscriberQuery) ([]Subscriber, error)

Subscribers returns a list of all confirmed subscribers.

func (*Client) TagSubscriber added in v0.4.1

func (c *Client) TagSubscriber(email string, tagID int) (Subscription, error)

TagSubscriber adds a tag to a subscriber

This method will also create a subscriber with the email address provided if one does not exist.

func (*Client) TotalSubscribers

func (c *Client) TotalSubscribers() (int, error)

TotalSubscribers returns the number of confirmed subscribers.

type Config

type Config struct {
	Endpoint string
	Key      string
	Secret   string

	ConcurrentRequests int

	HTTPClient *http.Client
}

Config is used to configure the creation of the client.

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns a default configuration for the client. It parses the environment variables CONVERTKIT_ENDPOINT, CONVERTKIT_API_KEY, and CONVERTKIT_API_SECRET.

type Subscriber

type Subscriber struct {
	ID           int               `json:"id"`
	FirstName    string            `json:"first_name"`
	EmailAddress string            `json:"email_address"`
	State        string            `json:"state"`
	CreatedAt    time.Time         `json:"created_at"`
	Fields       map[string]string `json:"fields"`
}

Subscriber describes a ConvertKit subscriber.

type SubscriberQuery added in v0.3.0

type SubscriberQuery struct {
	Since, Until string // TODO: turn this into time.Date
	Reverse      bool
	Cancelled    bool
	EmailAddress string
}

SubscriberQuery parameterizes what subscriber data to request.

type Subscription added in v0.4.1

type Subscription struct {
	ID               int        `json:"id"`
	State            string     `json:"state"`
	CreatedAt        time.Time  `json:"created_at"`
	Source           string     `json:"source"`
	Referrer         string     `json:"referrer"`
	SubscribableID   int        `json:"subscribable_id"`
	SubscribableType string     `json:"subscribable_type"`
	Subscriber       Subscriber `json:"subscriber"`
}

Subscription is a subscriber's association with a tag

type SubscriptionRequest added in v0.4.1

type SubscriptionRequest struct {
	Email     string            `json:"email"`
	FirstName string            `json:"first_name"`
	Fields    map[string]string `json:"fields"`
	Tags      []int             `json:"tags"`
	APIKey    string            `json:"api_key"`
}

SubscriptionRequest is a set of parameters to subscriber a subscriber to a tag

`ApiKey` will use the client's ApiKey if unspecified `Email` and at least one `Tags` are required. `Fields` keys must be custom field names already specified in ConvertKit. This API call cannot create new custom fields.

func (*SubscriptionRequest) AddTag added in v0.4.1

func (r *SubscriptionRequest) AddTag(newTag int)

AddTag appends newTag to Tags if it is not alredy in Tags

Jump to

Keyboard shortcuts

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