GoEngage is a Golang API wrapper for engage.so's v1 API. This package implements the User and List resources as covered in the v1 api docs
$ go get github.com/heroshe/goengage
It's quite simple and straightforward. The package supports two configuration styles.
You can read credentials from environment variables or provide them as arguments.
-
EnvCredentials: This looks for the following environment variables
ENGAGE_SO_PUBLIC_KEY
andENGAGE_SO_PRIVATE_KEY
. If the keys aren't found or, they contain blank values, no error will be returned at this step. An error will be returned when truing to initialize a new client using this config -
StaticCredentials: Sets the public and private keys based on provided arguments.
package main
import (
"github.com/heroshe/goengage"
"log"
"net/http"
"time"
)
func main() {
// Reading Credentials From Environment Variables
cfg := goengage.NewConfig().WithCredentials(goengage.NewEnvCredentials())
// Using Provided Credentials
cfg = goengage.NewConfig().WithCredentials(goengage.NewStaticCredentials("your_public_key", "your_private_key"))
// Optionally: Use your own *http.Client
cfg = goengage.NewConfig().WithCredentials(goengage.NewEnvCredentials()).WithHttpClient(&http.Client{
Timeout: 5 * time.Second,
})
// Crete a new client
client, err := goengage.New(cfg)
if err != nil {
//handle error
}
users, err := client.Users.List(&goengage.PaginatorInput{
Limit: goengage.Int(50),
})
if err != nil {
// handle error
}
// Do something with users.Data
log.Print(users.Data)
}
All resources are interfaces. That means you can create mocks or fake resources that can be used for testing.
The following endpoints are supported on the user resource. Documentation Link: https://engage.so/docs/api/users
Create()
: Creates a new userGet()
: Retrieves a single userList()
: Retrieves a list of usersUpdateAttributes()
: Updates user data and attributesAddEvent()
: Add user events
The following endpoints are supported on the list resource. Documentation Link: https://engage.so/docs/api/lists
CreateList()
: creates a newGetAllLists()
: returns as array of listsGetList()
: retrieves the details of a listUpdateList()
: updates properties of the listArchiveList()
: archives listSubscribeList()
: creates a user and subscribes to a listUnsubscribeList()
: Remove subscribers from list
The resources in package are both interfaces which mean you can create your custom client struct that have fake implementation of the resources.
go test --race -cover -coverprofile=cover.out -v ./...
Contributors and contributions are welcome. Open and issue or PR :)