customerio

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

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

Go to latest
Published: Jan 14, 2016 License: MIT Imports: 7 Imported by: 0

README

customerio

customerio is a Go package for integration with the Customer.io email service.

Install

go get github.com/joeshaw/customerio

API

The API is built on top of the Customer.io REST API.

Full API docs are available on godoc.

c := customerio.Client{
    SiteID: "my-site-id",
    APIKey: "my-api-key",
    HTTPClient: http.DefaultClient,
}

// Create a new customer with ID 5, email address customer@example.com,
// and a couple custom attributes
err := c.Identify("5", "customer@example.com", map[string]interface{}{
    "name": "Bob",
    "plan": "premium",
})
if err != nil {
    // uh oh
}

// Track an event named "purchased" on customer ID 5, with some custom
// event attributes.
err = c.Track("5", "purchased", map[string]interface{}{
    "price": 23.45,
}
if err != nil {
    // uh oh
}

You may pass in a nil map to either Identify or Track.

Documentation

Overview

Package customerio is a wrapper around the Customer.io REST API, documented at http://customer.io/docs/api/rest.html

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewContext

func NewContext(ctx context.Context, c *Client) context.Context

NewContext creates a new context.Context with the Client associated

Types

type Client

type Client struct {
	SiteID string
	APIKey string

	// The http.Client used to make connections to the Customer.io
	// REST API.  You may use your own or http.DefaultClient.
	HTTPClient *http.Client
}

Client represents a client to the Customer.io REST API.

func FromContext

func FromContext(ctx context.Context) *Client

FromContext returns the *Client associated with a context.Context, if any. Otherwise a nil *Client is returned.

func (*Client) Delete

func (c *Client) Delete(id string) error

Delete will remove a customer, and all their information from Customer.io. The REST endpoint is documented here: http://customer.io/docs/api/rest.html#section-Deleting_customers

func (*Client) Identify

func (c *Client) Identify(id string, email string, attrs map[string]interface{}) error

Identify creates or updates a customer. id is a unique, non-email identifier for a customer. The attrs map may be nil, or contain attributes which Customer.io can use to personalize triggered emails or affect the logic of who receives them. The REST endpoint is documented here: http://customer.io/docs/api/rest.html#section-Creating_or_updating_customers

func (*Client) Track

func (c *Client) Track(id string, eventName string, attrs map[string]interface{}) error

Track will send an event to Customer.io. The attrs map may be nil, or contain any information to attach to this event. These attributes can be used in triggers to control who should receive triggered email. The REST endpoint is documented here: http://customer.io/docs/api/rest.html#section-Track_a_custom_event

func (*Client) TrackRecipient

func (c *Client) TrackRecipient(recipient, eventName string, attrs map[string]interface{}) error

Sends an event email to a address that is not associated with a user in Customer.io. The attrs may be nil, and recipient will be assigned to "recipient" within it. The REST endpoint is documented here: http://customer.io/docs/invitation-emails.html

type Error

type Error struct {
	StatusCode int
}

Error represents an error from the Customer.io API, containing an HTTP status code returned by the request. Errors are documented in the REST API here: http://customer.io/docs/api/rest.html#section-Errors

func (*Error) Error

func (err *Error) Error() string

Returns the string representation of the error. Implements the built-in error interface.

Jump to

Keyboard shortcuts

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