Help us shape the future of Go! Take the 2026 Go Developer Survey

sendpulse

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2019 License: MIT Imports: 9 Imported by: 0

README

SendPulse REST client library

A SendPulse REST client library and example for Go (Golang).

API Documentation https://sendpulse.com/api

Build Status codecov Go Report Card License

Download
go get -u github.com/dimuska139/sendpulse-sdk-go
Example
package main

import (
	"fmt"
	"github.com/dimuska139/sendpulse-sdk-go"
)
const ApiUserId = "12345"
const ApiSecret = "12345"
const ApiTimeout = 5

func main() {
	addressBookId := 12345

	client, e := sendpulse.ApiClient(ApiUserId, ApiSecret, ApiTimeout)
	if e != nil {
		switch err := e.(type) {
		case *sendpulse.ResponseError: // Http error
			fmt.Println(err.HttpCode)
			fmt.Println(err.Url)
			fmt.Println(err.Body)
		default: // Another errors
			fmt.Println(e)
		}
	}

	// Get address book info by id
	bookInfo, e := client.Books.Get(uint(addressBookId))
	if e != nil {
		switch err := e.(type) {
		case *sendpulse.SendpulseError: // Sendpulse error
			fmt.Println(err.HttpCode)
			fmt.Println(err.Url)
			fmt.Println(err.Body)
			fmt.Println(err.Message)
		default: // Another errors
			fmt.Println(e)
		}
	} else {
		fmt.Println(*bookInfo)
	}

	// Get address books list
	limit := 10
	offset := 20
	books, err := client.Books.List(uint(limit), uint(offset))
	if err != nil {
		switch err := e.(type) {
		case *sendpulse.SendpulseError: // Sendpulse error
			fmt.Println(err.HttpCode)
			fmt.Println(err.Url)
			fmt.Println(err.Body)
			fmt.Println(err.Message)
		default: // Another errors
			fmt.Println(e)
		}
	} else {
		fmt.Println(*books)
	}

	// Add emails to address book
	emails := []sendpulse.Email{
		sendpulse.Email{
			Email:     "alex@test.net",
			Variables: map[string]string{
				"name": "Alex",
				"age": "25",
			},
		},
		sendpulse.Email{
			Email:     "dima@test.net",
			Variables: make(map[string]string),
		},
	}
	
	extraParams := make(map[string]string)
	
	err = client.Books.AddEmails(uint(addressBookId), emails, extraParams)
	if err != nil {
		switch err := e.(type) {
		case *sendpulse.SendpulseError: // Sendpulse error
			fmt.Println(err.HttpCode)
			fmt.Println(err.Url)
			fmt.Println(err.Body)
			fmt.Println(err.Message)
		default: // Another errors
			fmt.Println(e)
		}
	}
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Book

type Book struct {
	ID               uint   `json:"id"`
	Name             string `json:"name"`
	AllEmailQty      uint   `json:"all_email_qty"`
	ActiveEmailQty   uint   `json:"active_email_qty"`
	InactiveEmailQty uint   `json:"inactive_email_qty"`
	CreationDate     string `json:"creationdate"`
	Status           uint   `json:"status"`
	StatusExplain    string `json:"status_explain"`
}

type Email

type Email struct {
	Email     string                 `json:"email"`
	Variables map[string]interface{} `json:"variables"`
}

type SendpulseClient

type SendpulseClient struct {
	Books         *books
	Automation360 *automation360
}

func ApiClient

func ApiClient(apiUserId string, apiSecret string, timeout int) (*SendpulseClient, error)

type SendpulseError

type SendpulseError struct {
	HttpCode int
	Url      string
	Body     string
	Message  string
}

func (*SendpulseError) Error

func (e *SendpulseError) Error() string

Jump to

Keyboard shortcuts

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