Skip to content

NdoleStudio/plunk-go

Repository files navigation

plunk-go

Build codecov Scrutinizer Code Quality Go Report Card GitHub contributors GitHub license PkgGoDev

This is an unofficial client library for interacting with the Plunk API using Go.

Card

Installation

Make sure your project is using Go Modules (it will have a go.mod file in its root if it already is):

go mod init

Then, reference plunk-go in a Go program with import:

import (
	"github.com/NdoleStudio/plunk-go"
)

Run any of the normal go commands (build/install). The Go toolchain will resolve and fetch the plunk-go module automatically. Alternatively, you can also explicitly go get the package into a project:

go get github.com/NdoleStudio/plunk-go

Implemented

  • Contacts
    • POST /contacts: Create a new contact or update existing (upsert by email)
    • DELETE /contacts/{id}: Permanently delete a contact
    • GET /contacts: Get a paginated list of contacts with cursor-based pagination
  • Track
    • POST /track: Track an event for a contact

Usage

Initializing the Client

An instance of the client can be created using plunk.New().

package main

import (
	"github.com/NdoleStudio/plunk-go"
)

func main()  {
	plunkClient := plunk.New(plunk.WithSecretKey(/* Secret Key from https://next-app.useplunk.com/settings?tab=general*/))
}

Error handling

All API calls return an error as the last return object. All successful calls will return a nil error.

request := &plunk.CreateContactRequest{
    Email: "user@example.com"
    Subscribed: true
    Data: map[string]any{
        "firstName": "John",
        "lastName": "Doe",
        "plan": "premium",
    }
}

contact, response, err := plunkClient.Contacts.Create(context.Background(), request)
if err != nil {
    //handle error
}

Testing

You can run the unit tests for this client from the root directory using the command below:

go test -v

License

This project is licensed under the MIT License - see the LICENSE file for details

About

Unofficial SDK for the useplunk.com API

Topics

Resources

License

Stars

Watchers

Forks

Languages