Skip to content

tilebox/loops-go

Repository files navigation

Loops GO SDK

Introduction

A Go SDK for interacting with Loops's API.

Installation

go get github.com/tilebox/loops-go

Usage

Below are a few examples of how to use the SDK to send API requests. For some full, working examples, see the examples directory.

Create a client:

package main

import (
	"context"
	"github.com/tilebox/loops-go"
	"log/slog"
)

func main() {
	ctx := context.Background()
	client, err := loops.NewClient(loops.WithAPIKey("YOUR_LOOPS_API_KEY"))
	if err != nil {
		slog.Error("failed to create client", slog.Any("error", err.Error()))
		return
	}
	
	// now use the client to make requests
}

Contacts

Find a contact

contact, err := client.FindContact(ctx, &loops.ContactIdentifier{
    Email: loops.String("[email protected]"),
})
if err != nil {
    slog.Error("failed to find contact", slog.Any("error", err.Error()))
    return
}

Create a contact

contactID, err := client.CreateContact(ctx, &loops.Contact{
    Email:      "[email protected]",
    FirstName:  loops.String("Neil"),
    LastName:   loops.String("Armstrong"),
    UserGroup:  loops.String("Astronauts"),
    Subscribed: true,
    // custom user defined properties for contacts
    CustomProperties: map[string]interface{}{
        "role": "Astronaut",
    },
})
if err != nil {
    slog.Error("failed to create contact", slog.Any("error", err.Error()))
    return
}

Delete a contact

err = client.DeleteContact(ctx, &loops.ContactIdentifier{
    Email: loops.String("[email protected]"),
})
if err != nil {
    slog.Error("failed to delete contact", slog.Any("error", err.Error()))
    return
}

Events

Send an event

err = client.SendEvent(ctx, &loops.Event{
    Email:     loops.String("[email protected]"),
    EventName: "joinedMission",
    EventProperties: &map[string]interface{}{
        "mission": "Apollo 11",
    },
})
if err != nil {
    slog.Error("failed to send event", slog.Any("error", err.Error()))
    return
}

Transactional emails

Send a transactional email

err = client.SendTransactionalEmail(ctx, &loops.TransactionalEmail{
    TransactionalId: "cm...",
    Email:           "[email protected]",
    DataVariables: &map[string]interface{}{
        "name": "Recipient Name",
    },
})
if err != nil {
    slog.Error("failed to send transactional email", slog.Any("error", err.Error()))
    return
}

API Documentation

The API documentation is part of the official Loops Documentation and can be found here.

Contributing

Contributions are welcome! Especially if the loops API is updated, please feel free to open PRs for new or updated endpoints.

Authors

Created by Tilebox - The Solar System’s #1 developer tool for space data management.

License

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

Development

Testing

go test ./...

Linting

golangci-lint run --fix  ./...

About

Go library for the Loops.so API

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages