dyspatch

package module
v2.0.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2019 License: Apache-2.0 Imports: 21 Imported by: 0

README

Go API client for Dyspatch

Introduction

The Dyspatch API is based on the REST paradigm, and features resource based URLs with standard HTTP response codes to indicate errors. We use standard HTTP authentication and request verbs, and all responses are JSON formatted.

See our Implementation Guide for more details on how to implement Dyspatch. ## API Client Libraries Dyspatch provides API Clients for popular languages and web frameworks.

Overview

This API client was generated by the swagger-codegen project. By using the swagger-spec from a remote server, you can easily generate an API client.

  • API version: 2019.03
  • Package version: 2.0.0
  • Build package: io.swagger.codegen.languages.GoClientCodegen

For more information, please visit https://docs.dyspatch.io

Installation

Install the following dependencies:

go get github.com/stretchr/testify/assert
go get golang.org/x/oauth2
go get golang.org/x/net/context
go get github.com/antihax/optional

Install the latest version of the client project:

go get -u github.com/getdyspatch/dyspatch-golang

Installing a versioned client:

go get gopkg.in/getdyspatch/dyspatch-golang.v2

Importing a versioned client:

import "gopkg.in/getdyspatch/dyspatch-golang.v2"

Read more at gopkg.in

Getting Started

package main

import (
	"fmt"
	"github.com/antihax/optional"
	"gopkg.in/getdyspatch/dyspatch-golang.v2"
	"golang.org/x/net/context"
)

func main() {
	cfg := dyspatch.NewConfiguration()
	auth := context.WithValue(context.Background(), dyspatch.ContextAPIKey, dyspatch.APIKey{
		Key:    "DYSPATCH_API_KEY",
		Prefix: "Bearer",
	})

	api := dyspatch.NewAPIClient(cfg)
	opts := dyspatch.TemplatesGetOpts{Cursor: optional.NewString("")} // Use this to page API results
	templates, _, err := api.TemplatesApi.TemplatesGet(auth, &opts)

	if err != nil {
		fmt.Println(err)
	}

	for _, template := range templates.Data {
		fmt.Println(template.Name)
	}
}

Documentation for API Endpoints

All URIs are relative to https://api.dyspatch.io

Class Method HTTP request Description
LocalizationsApi LocalizationsLocalizationIdGet Get /localizations/{localizationId} Get Localization Object by ID
TemplatesApi TemplatesGet Get /templates List Templates
TemplatesApi TemplatesTemplateIdGet Get /templates/{templateId} Get Template by ID

Documentation For Models

Documentation For Authorization

Bearer

  • Type: API key

Example

auth := context.WithValue(context.Background(), sw.ContextAPIKey, sw.APIKey{
	Key: "APIKEY",
	Prefix: "Bearer", // Omit if not necessary.
})
r, err := client.Service.Operation(auth, args)

Author

support@dyspatch.io

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ContextOAuth2 takes a oauth2.TokenSource as authentication for the request.
	ContextOAuth2 = contextKey("token")

	// ContextBasicAuth takes BasicAuth as authentication for the request.
	ContextBasicAuth = contextKey("basic")

	// ContextAccessToken takes a string oauth2 access token as authentication for the request.
	ContextAccessToken = contextKey("accesstoken")

	// ContextAPIKey takes an APIKey as authentication for the request
	ContextAPIKey = contextKey("apikey")
)

Functions

func CacheExpires

func CacheExpires(r *http.Response) time.Time

CacheExpires helper function to determine remaining time before repeating a request.

Types

type APIClient

type APIClient struct {
	LocalizationsApi *LocalizationsApiService

	TemplatesApi *TemplatesApiService
	// contains filtered or unexported fields
}

APIClient manages communication with the Dyspatch API API v2019.03 In most cases there should be only one, shared, APIClient.

func NewAPIClient

func NewAPIClient(cfg *Configuration) *APIClient

NewAPIClient creates a new API client. Requires a userAgent string describing your application. optionally a custom http.Client to allow for advanced features such as caching.

func (*APIClient) ChangeBasePath

func (c *APIClient) ChangeBasePath(path string)

Change base path to allow switching to mocks

type APIKey

type APIKey struct {
	Key    string
	Prefix string
}

APIKey provides API key based authentication to a request passed via context using ContextAPIKey

type APIResponse

type APIResponse struct {
	*http.Response `json:"-"`
	Message        string `json:"message,omitempty"`
	// Operation is the name of the swagger operation.
	Operation string `json:"operation,omitempty"`
	// RequestURL is the request URL. This value is always available, even if the
	// embedded *http.Response is nil.
	RequestURL string `json:"url,omitempty"`
	// Method is the HTTP method used for the request.  This value is always
	// available, even if the embedded *http.Response is nil.
	Method string `json:"method,omitempty"`
	// Payload holds the contents of the response body (which may be nil or empty).
	// This is provided here as the raw response.Body() reader will have already
	// been drained.
	Payload []byte `json:"-"`
}

func NewAPIResponse

func NewAPIResponse(r *http.Response) *APIResponse

func NewAPIResponseWithError

func NewAPIResponseWithError(errorMessage string) *APIResponse

type ApiError

type ApiError struct {
	// Error code:   * server_error - Internal server error.   * invalid_parameter - Validation error, parameter will contain invalid field and message will contain the reason.   * invalid_body - Body could not be parsed, message will contain the reason.   * invalid_request - Validation error, the protocol used to make the request was not https.   * unauthorized - Credentials were found but permissions were not sufficient.   * unauthenticated - Credentials were not found or were not valid.   * not_found - The requested resource was not found.   * rate_limited - The request was refused because a rate limit was exceeded. There is an account wide rate limit of 3600 requests per-minute, although that is subject to change. The current remaining rate limit can be viewed by checking the X-Ratelimit-Remaining header.
	Code string `json:"code,omitempty"`
	// Human readable error message
	Message string `json:"message,omitempty"`
	// The invalid parameter, if 'code' is invalid_parameter
	Parameter string `json:"parameter,omitempty"`
}

type BasicAuth

type BasicAuth struct {
	UserName string `json:"userName,omitempty"`
	Password string `json:"password,omitempty"`
}

BasicAuth provides basic http authentication to a request passed via context using ContextBasicAuth

type CompiledRead

type CompiledRead struct {
	// Sender address
	Sender string `json:"sender,omitempty"`
	// Reply-To address
	ReplyTo string `json:"replyTo,omitempty"`
	// Base64 encoded template subject line
	Subject string `json:"subject,omitempty"`
	// Base64 encoded template HTML body
	Html string `json:"html,omitempty"`
	// Base64 encoded template text body
	Text string `json:"text,omitempty"`
}

type Configuration

type Configuration struct {
	BasePath      string            `json:"basePath,omitempty"`
	Host          string            `json:"host,omitempty"`
	Scheme        string            `json:"scheme,omitempty"`
	DefaultHeader map[string]string `json:"defaultHeader,omitempty"`
	UserAgent     string            `json:"userAgent,omitempty"`
	HTTPClient    *http.Client
}

func NewConfiguration

func NewConfiguration() *Configuration

func (*Configuration) AddDefaultHeader

func (c *Configuration) AddDefaultHeader(key string, value string)

type Cursor

type Cursor struct {
	// A cursor to fetch the next page of results
	Next string `json:"next,omitempty"`
	// Whether there is a next page of results
	HasMore bool `json:"hasMore,omitempty"`
}

Information about paginated results

type GenericSwaggerError

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

GenericSwaggerError Provides access to the body, error and model on returned errors.

func (GenericSwaggerError) Body

func (e GenericSwaggerError) Body() []byte

Body returns the raw bytes of the response

func (GenericSwaggerError) Error

func (e GenericSwaggerError) Error() string

Error returns non-empty string if there was an error.

func (GenericSwaggerError) Model

func (e GenericSwaggerError) Model() interface{}

Model returns the unpacked model of the error

type LocalizationMetaRead

type LocalizationMetaRead struct {
	// An opaque, unique identifier for a localization
	Id string `json:"id,omitempty"`
	// A language identifier comprised of a language and a country identifier.  See [supported languages](https://docs.dyspatch.io/localization/supported_languages/).
	Language string `json:"language,omitempty"`
	// The user-specified name of a localization
	Name string `json:"name,omitempty"`
	// The API url for a specific localization
	Url string `json:"url,omitempty"`
}

type LocalizationRead

type LocalizationRead struct {
	// An opaque, unique identifier for a localization
	Id string `json:"id,omitempty"`
	// A language identifier comprised of a language and a country identifier.  See [supported languages](https://docs.dyspatch.io/localization/supported_languages/).
	Language string `json:"language,omitempty"`
	// The API url for a specific localization
	Url string `json:"url,omitempty"`
	// An opaque, unique identifier for a template
	Template string        `json:"template,omitempty"`
	Compiled *CompiledRead `json:"compiled,omitempty"`
	// The time of initial creation
	CreatedAt time.Time `json:"createdAt,omitempty"`
	// The time of last update
	UpdatedAt time.Time `json:"updatedAt,omitempty"`
	// The user-specified name of a localization
	Name string `json:"name,omitempty"`
}

type LocalizationsApiService

type LocalizationsApiService service

func (*LocalizationsApiService) LocalizationsLocalizationIdGet

func (a *LocalizationsApiService) LocalizationsLocalizationIdGet(ctx context.Context, localizationId string, localVarOptionals *LocalizationsLocalizationIdGetOpts) (LocalizationRead, *http.Response, error)

type LocalizationsLocalizationIdGetOpts

type LocalizationsLocalizationIdGetOpts struct {
	TargetLanguage optional.String
}

type TemplateMetaRead

type TemplateMetaRead struct {
	// An opaque, unique identifier for a template
	Id string `json:"id,omitempty"`
	// The name of a template
	Name string `json:"name,omitempty"`
	// A description of the template
	Description string `json:"description,omitempty"`
	// The API url for a specific template
	Url string `json:"url,omitempty"`
	// A list of the template's available localization objects
	Localizations []LocalizationMetaRead `json:"localizations,omitempty"`
	// The time of initial creation
	CreatedAt time.Time `json:"createdAt,omitempty"`
	// The time of last update
	UpdatedAt time.Time `json:"updatedAt,omitempty"`
}

type TemplateRead

type TemplateRead struct {
	// An opaque, unique identifier for a template
	Id string `json:"id,omitempty"`
	// The name of a template
	Name string `json:"name,omitempty"`
	// A description of the template
	Description string `json:"description,omitempty"`
	// The API url for a specific template
	Url      string        `json:"url,omitempty"`
	Compiled *CompiledRead `json:"compiled,omitempty"`
	// The time of initial creation
	CreatedAt time.Time `json:"createdAt,omitempty"`
	// The time of last update
	UpdatedAt time.Time `json:"updatedAt,omitempty"`
	// A list of the Template's available localizations
	Localizations []LocalizationMetaRead `json:"localizations,omitempty"`
}

type TemplatesApiService

type TemplatesApiService service

func (*TemplatesApiService) TemplatesGet

func (a *TemplatesApiService) TemplatesGet(ctx context.Context, localVarOptionals *TemplatesGetOpts) (TemplatesRead, *http.Response, error)

func (*TemplatesApiService) TemplatesTemplateIdGet

func (a *TemplatesApiService) TemplatesTemplateIdGet(ctx context.Context, templateId string, localVarOptionals *TemplatesTemplateIdGetOpts) (TemplateRead, *http.Response, error)

type TemplatesGetOpts

type TemplatesGetOpts struct {
	Cursor optional.String
}

type TemplatesRead

type TemplatesRead struct {
	Cursor *Cursor `json:"cursor,omitempty"`
	// A list of template metadata objects
	Data []TemplateMetaRead `json:"data,omitempty"`
}

type TemplatesTemplateIdGetOpts

type TemplatesTemplateIdGetOpts struct {
	TargetLanguage optional.String
}

Jump to

Keyboard shortcuts

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