dyspatch_client

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2018 License: Apache-2.0 Imports: 21 Imported by: 0

README

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.

Overview

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

  • API version: 2018.08
  • Package version: 1.0.0
  • Build package: org.openapitools.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.v1

Importing a versioned client:

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

Read more at gopkg.in

Getting Started

package main

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

func main() {
	cfg := dyspatch_client.NewConfiguration()
	accept := "application/vnd.dyspatch.2018.08+json" // Accept header used in this API version

	auth := context.WithValue(context.Background(), dyspatch_client.ContextAPIKey, dyspatch_client.APIKey{
		Key:    "DYSPATCH_API_KEY",
		Prefix: "Bearer", // Omit if not necessary.
	})

	api := dyspatch_client.NewAPIClient(cfg)
	opts := dyspatch_client.TemplatesGetOpts{Cursor: optional.NewString("")}
	templates, resp, err := api.TemplatesApi.TemplatesGet(auth, accept, &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(), dyspatch_client.ContextAPIKey, dyspatch_client.APIKey{
	Key: "DYSPATCH_API_KEY", 
	Prefix: "Bearer",
})
r, err := client.Service.Operation(auth, accept, args) // Service: TemplatesApi or LocalizationsApi

Author

support@dyspatch.io

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ContextOAuth2 takes an 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 v2018.08 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 OpenAPI 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 GenericOpenAPIError

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

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

func (GenericOpenAPIError) Body

func (e GenericOpenAPIError) Body() []byte

Body returns the raw bytes of the response

func (GenericOpenAPIError) Error

func (e GenericOpenAPIError) Error() string

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

func (GenericOpenAPIError) Model

func (e GenericOpenAPIError) 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, accept string) (LocalizationRead, *http.Response, error)

LocalizationsApiService Get Localization Object by ID Returns a specific localization object with a matching ID

  • @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
  • @param localizationId A localization ID
  • @param accept A version of the API that should be used for the request. For example, to use version \"2018.08\", set the value to \"application/vnd.dyspatch.2018.08+json\"

@return LocalizationRead

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, accept string, localVarOptionals *TemplatesGetOpts) (TemplatesRead, *http.Response, error)

func (*TemplatesApiService) TemplatesTemplateIdGet

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

TemplatesApiService Get Template by ID Gets a template object with the matching ID. If the template has published content the \"compiled\" field will contain the template .

  • @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
  • @param templateId A template ID
  • @param accept A version of the API that should be used for the request. For example, to use version \"2018.08\", set the value to \"application/vnd.dyspatch.2018.08+json\"

@return TemplateRead

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"`
}

Jump to

Keyboard shortcuts

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