createsend

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2020 License: MIT Imports: 15 Imported by: 0

README

createsend

GitHub release (latest by date including pre-releases) Build Status Go Report Card codecov GitHub license GitHub issues

Campaign Monitor API wrapper in Go

Installation
go get github.com/xitonix/createsend

Example

package main

import (
    "fmt"
    "log"

    "github.com/xitonix/createsend"
)

func main() {
    client, err := createsend.New(createsend.WithAPIKey("[Your API Key]"))
    if err != nil {
        log.Fatal(err)
    }
    
    clients, err := client.Accounts().Clients()
    if err != nil {
        log.Fatal(err)
    }
    
    for _, client := range clients {
        fmt.Printf("%s: %s\n", client.ID, client.Name)
    }
}

You can also use oAuth authentication token:

client, err := createsend.New(createsend.WithOAuthToken("[OAuth Token]"))
if err != nil {
  log.Fatal(err)
}

Documentation

Index

Constants

View Source
const (
	// DefaultBaseURL the default API base URL.
	DefaultBaseURL = "https://api.createsend.com/api/v3.2/"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client represents a client to access Campaign Monitor API.

func New

func New(options ...Option) (*Client, error)

New creates a new client.

func (*Client) Accounts

func (c *Client) Accounts() accounts.API

Accounts accesses the Campaign Monitor accounts API.

func (*Client) Clients added in v0.0.2

func (c *Client) Clients() clients.API

Clients accesses the Campaign Monitor clients API.

type ClientErrorCode

type ClientErrorCode int

ClientErrorCode client side error codes.

const (
	// ErrCodeDataProcessing indicates that processing the input/output data has failed.
	ErrCodeDataProcessing ClientErrorCode = -1
	// ErrCodeNilHTTPClient the provided internal HTTP client is nil.
	ErrCodeNilHTTPClient ClientErrorCode = -2
	// ErrCodeAuthenticationNotSet neither API key nor Oauth token was provided.
	ErrCodeAuthenticationNotSet ClientErrorCode = -3
	// ErrCodeEmptyOAuthToken the provided Oauth token was empty.
	ErrCodeEmptyOAuthToken ClientErrorCode = -4
	// ErrCodeEmptyAPIKey the provided API key was empty.
	ErrCodeEmptyAPIKey ClientErrorCode = -5
	// ErrCodeEmptyURL the requested URL was empty.
	ErrCodeEmptyURL ClientErrorCode = -6
	// ErrCodeInvalidURL the requested UTL was invalid.
	ErrCodeInvalidURL ClientErrorCode = -7
	// ErrCodeInvalidJSON the provided JSON payload was invalid.
	ErrCodeInvalidJSON ClientErrorCode = -8
	// ErrCodeInvalidRequestBody the provided request was invalid.
	ErrCodeInvalidRequestBody ClientErrorCode = -9
)

func (ClientErrorCode) String

func (c ClientErrorCode) String() string

String returns the string representation of the error code.

type Error

type Error struct {
	// Code error code.
	Code int
	// Message error message.
	Message string
	// contains filtered or unexported fields
}

Error wraps server side and client side errors.

func (*Error) Error

func (e *Error) Error() string

Error returns the string representation of the error.

func (*Error) Is

func (e *Error) Is(target error) bool

Is returns true if the error is of the same type as the target.

func (*Error) IsFromServer

func (e *Error) IsFromServer() bool

IsFromServer returns true if the error reported by the server.

The method will return false if this is a client side error.

func (*Error) Unwrap

func (e *Error) Unwrap() error

Unwrap returns the internal error.

type HTTPClient

type HTTPClient interface {
	Do(request *http.Request) (*http.Response, error)
}

HTTPClient is an interface for the internal HTTP client.

type Option

type Option func(*Options)

Option represents an optional client configuration function.

func WithAPIKey

func WithAPIKey(apiKey string) Option

WithAPIKey enables API key authentication.

func WithAccountsAPI

func WithAccountsAPI(api accounts.API) Option

WithAccountsAPI overrides the internal object for accessing Accounts API.

You can override the API to mock out Accounts API methods altogether.

func WithBaseURL

func WithBaseURL(url string) Option

WithBaseURL overrides the base URL.

func WithClientsAPI added in v0.0.2

func WithClientsAPI(api clients.API) Option

WithClientsAPI overrides the internal object for accessing Clients API.

You can override the API to mock out Clients API methods altogether.

func WithContext added in v0.0.2

func WithContext(ctx context.Context) Option

WithContext sets the context for all the HTTP requests.

func WithHTTPClient

func WithHTTPClient(client HTTPClient) Option

WithHTTPClient sets the internal HTTP client.

func WithOAuthToken

func WithOAuthToken(token string) Option

WithOAuthToken enables Oauth token authentication.

type Options

type Options struct {
	// contains filtered or unexported fields
}

Options client configurations.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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