communicator

package
v0.0.0-...-81dae2a Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2024 License: BSD-3-Clause, MIT Imports: 23 Imported by: 20

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type APIResource

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

APIResource represents the base type of all Worldline Global Collect platform API resources.

func NewAPIResource

func NewAPIResource(communicator *Communicator, clientMetaInfo string, pathContext map[string]string) (*APIResource, error)

NewAPIResource creates an APIResource with the given communicator, clientMetaInfo and pathContext

func NewAPIResourceWithParent

func NewAPIResourceWithParent(parent *APIResource, pathContext map[string]string) (*APIResource, error)

NewAPIResourceWithParent creates an APIResource with the given parent and pathContext

func (APIResource) ClientHeaders

func (ar APIResource) ClientHeaders() []communication.Header

ClientHeaders returns the client headers used by the resource

func (APIResource) ClientMetaInfo

func (ar APIResource) ClientMetaInfo() string

ClientMetaInfo returns the ClientMetaInfo used by the resource

func (APIResource) Communicator

func (ar APIResource) Communicator() *Communicator

Communicator returns the Communicator used by the resource

func (APIResource) InstantiateURI

func (ar APIResource) InstantiateURI(uri string) (string, error)

InstantiateURI instantiates the given uri with the path context of the resource

func (APIResource) InstantiateURIWithContext

func (ar APIResource) InstantiateURIWithContext(uri string, pathContext map[string]string) (string, error)

InstantiateURIWithContext instantiates the given URI with the path context

type BodyHandler

type BodyHandler func(headers []communication.Header, reader io.Reader) error

BodyHandler is a function for handling incoming body streams

type CallContext

type CallContext struct {
	IdempotenceKey              string
	IdempotenceRequestTimestamp *int64
}

CallContext can be used to send extra information with a request, and to receive extra information from a response. Please note that this type is not thread-safe. Each request should get its own call context instance.

func NewCallContext

func NewCallContext(idempotenceKey string) *CallContext

NewCallContext creates a CallContext using the given idempotenceKey

func (*CallContext) GetIdempotenceKey

func (c *CallContext) GetIdempotenceKey() string

GetIdempotenceKey returns the idempotence key

func (*CallContext) GetIdempotenceRequestTimestamp

func (c *CallContext) GetIdempotenceRequestTimestamp() *int64

GetIdempotenceRequestTimestamp returns the idempotence timestamp

func (*CallContext) SetIdempotenceRequestTimestamp

func (c *CallContext) SetIdempotenceRequestTimestamp(timestamp *int64)

SetIdempotenceRequestTimestamp sets the idempotence timestamp

type Communicator

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

A Communicator is used to communicate with the Worldline Global Collect platform web services. It contains all the logic to transform a request object to an HTTP request and an HTTP response to a response object. It is also thread safe.

func NewCommunicator

func NewCommunicator(apiEndpoint *url.URL, connection Connection, authenticator authentication.Authenticator, metadataProvider *MetadataProvider, marshaller json.Marshaller) (*Communicator, error)

NewCommunicator creates a communicator with the given apiEndpoint, connection, authenticator, metadata provider and marshaller

func (*Communicator) APIEndpoint

func (c *Communicator) APIEndpoint() *url.URL

APIEndpoint returns the apiEndpoint of the Communicator

func (*Communicator) Authenticator

func (c *Communicator) Authenticator() authentication.Authenticator

Authenticator returns the authenticator of the Communicator

func (*Communicator) Close

func (c *Communicator) Close() error

Close closes the connection of the Communicator

func (*Communicator) CloseExpiredConnections

func (c *Communicator) CloseExpiredConnections()

CloseExpiredConnections is a utility method that delegates the call to this communicator's connection. Also see Connection.CloseExpiredConnections

func (*Communicator) CloseIdleConnections

func (c *Communicator) CloseIdleConnections(duration time.Duration)

CloseIdleConnections is a utility method that delegates the call to this communicator's connection. The duration argument is a specification of how long the connection has to be Idle. Also see Connection.CloseIdleConnections

func (*Communicator) Connection

func (c *Communicator) Connection() Connection

Connection returns the connection of the Communicator

func (*Communicator) Delete

func (c *Communicator) Delete(relativePath string, requestHeaders []communication.Header, requestParameters communication.ParamRequest, context *CallContext, expectedObject interface{}) error

Delete corresponds to the HTTP Delete method

relativePath is the Path to call, relative to the base URI requestHeaders is an optimal list of request headers requestParameters is an optional set of request parameters. If not used set to nil context is an optional Call context which can be used expectedObject is a reference to the expected response object

func (*Communicator) DeleteWithHandler

func (c *Communicator) DeleteWithHandler(relativePath string, requestHeaders []communication.Header, requestParameters communication.ParamRequest, context *CallContext, bodyHandler BodyHandler) error

DeleteWithHandler corresponds to the HTTP Delete method

relativePath is the Path to call, relative to the base URI requestHeaders is an optimal list of request headers requestParameters is an optional set of request parameters. If not used set to nil context is an optional Call context which can be used expectedObject is a reference to the expected response object bodyHandler is a BodyHandler that handles the body stream

func (*Communicator) DisableLogging

func (c *Communicator) DisableLogging()

DisableLogging turns off logging.

func (*Communicator) EnableLogging

func (c *Communicator) EnableLogging(logger logging.CommunicatorLogger)

EnableLogging turns on logging using the given communicator logger.

func (*Communicator) Get

func (c *Communicator) Get(relativePath string, requestHeaders []communication.Header, requestParameters communication.ParamRequest, context *CallContext, expectedObject interface{}) error

Get corresponds to the HTTP Get method

relativePath is the Path to call, relative to the base URI requestHeaders is an optimal list of request headers requestParameters is an optional set of request parameters. If not used set to nil context is an optional Call context which can be used expectedObject is a reference to the expected response object

func (*Communicator) GetWithHandler

func (c *Communicator) GetWithHandler(relativePath string, requestHeaders []communication.Header, requestParameters communication.ParamRequest, context *CallContext, bodyHandler BodyHandler) error

GetWithHandler corresponds to the HTTP Get method

relativePath is the Path to call, relative to the base URI requestHeaders is an optimal list of request headers requestParameters is an optional set of request parameters. If not used set to nil context is an optional Call context which can be used expectedObject is a reference to the expected response object bodyHandler is a BodyHandler that handles the body stream

func (*Communicator) Marshaller

func (c *Communicator) Marshaller() json.Marshaller

Marshaller returns the marshaller of the Communicator

func (*Communicator) MetadataProvider

func (c *Communicator) MetadataProvider() *MetadataProvider

MetadataProvider returns the metadataProvider of the Communicator

func (*Communicator) Post

func (c *Communicator) Post(relativePath string, requestHeaders []communication.Header, requestParameters communication.ParamRequest, requestBody interface{}, context *CallContext, expectedResponse interface{}) error

Post corresponds to the HTTP Post method

relativePath is the Path to call, relative to the base URI requestHeaders is an optimal list of request headers requestParameters is an optional set of request parameters. If not used set it to nil requestBody is the body of the request. If not used set to nil context is an optional Call context which can be used. If not used set it to nil expectedObject is a reference to the expected response object

func (*Communicator) PostWithHandler

func (c *Communicator) PostWithHandler(relativePath string, requestHeaders []communication.Header, requestParameters communication.ParamRequest, requestBody interface{}, context *CallContext, bodyHandler BodyHandler) error

PostWithHandler corresponds to the HTTP Post method

relativePath is the Path to call, relative to the base URI requestHeaders is an optimal list of request headers requestParameters is an optional set of request parameters. If not used set it to nil requestBody is the body of the request. If not used set to nil context is an optional Call context which can be used. If not used set it to nil expectedObject is a reference to the expected response object bodyHandler is a BodyHandler that handles the body stream

func (*Communicator) Put

func (c *Communicator) Put(relativePath string, requestHeaders []communication.Header, requestParameters communication.ParamRequest, requestBody interface{}, context *CallContext, expectedObject interface{}) error

Put corresponds to the HTTP Put method

relativePath is the Path to call, relative to the base URI requestHeaders is an optimal list of request headers requestParameters is an optional set of request parameters. If not used set it to nil requestBody is the body of the request. If not used set to nil context is an optional Call context which can be used. If not used set it to nil expectedObject is a reference to the expected response object

func (*Communicator) PutWithHandler

func (c *Communicator) PutWithHandler(relativePath string, requestHeaders []communication.Header, requestParameters communication.ParamRequest, requestBody interface{}, context *CallContext, bodyHandler BodyHandler) error

PutWithHandler corresponds to the HTTP Put method

relativePath is the Path to call, relative to the base URI requestHeaders is an optimal list of request headers requestParameters is an optional set of request parameters. If not used set it to nil requestBody is the body of the request. If not used set to nil context is an optional Call context which can be used. If not used set it to nil expectedObject is a reference to the expected response object bodyHandler is a BodyHandler that handles the body stream

func (*Communicator) SetBodyObfuscator

func (c *Communicator) SetBodyObfuscator(bodyObfuscator obfuscation.BodyObfuscator)

SetBodyObfuscator sets the body obfuscator to use.

func (*Communicator) SetHeaderObfuscator

func (c *Communicator) SetHeaderObfuscator(headerObfuscator obfuscation.HeaderObfuscator)

SetHeaderObfuscator sets the header obfuscator to use.

type Connection

type Connection interface {

	// Get sends a GET request to the Worldline Global Collect platform and calls the given response handler with the response.
	Get(resourceURI url.URL, requestHeaders []communication.Header, handler communication.ResponseHandler) (interface{}, error)

	// Delete sends a DELETE request to the Worldline Global Collect platform and calls the given response handler with the response.
	Delete(resourceURI url.URL, requestHeaders []communication.Header, handler communication.ResponseHandler) (interface{}, error)

	// Post sends a POST request to the Worldline Global Collect platform and calls the given response handler with the response.
	Post(resourceURI url.URL, requestHeaders []communication.Header, body string, handler communication.ResponseHandler) (interface{}, error)

	// PostMultipart sends a multipart/form-data POST request to the Worldline Global Collect platform and calls the given response handler with the response.
	PostMultipart(resourceURI url.URL, requestHeaders []communication.Header, body *communication.MultipartFormDataObject, handler communication.ResponseHandler) (interface{}, error)

	// Put sends a PUT request to the Worldline Global Collect platform and calls the given response handler with the response.
	Put(resourceURI url.URL, requestHeaders []communication.Header, body string, handler communication.ResponseHandler) (interface{}, error)

	// PutMultipart sends a multipart/form-data PUT request to the Worldline Global Collect platform and calls the given response handler with the response.
	PutMultipart(resourceURI url.URL, requestHeaders []communication.Header, body *communication.MultipartFormDataObject, hHandler communication.ResponseHandler) (interface{}, error)

	// CloseIdleConnections closes all HTTP connections that have been idle for the specified time.
	// This should also include all expired HTTP connections.
	// timespan represents the time spent idle
	CloseIdleConnections(time time.Duration)

	// CloseExpiredConnections closes all expired HTTP connections.
	CloseExpiredConnections()

	// EnableLogging turns on logging using the given communicator logger.
	EnableLogging(communicatorLogger logging.CommunicatorLogger)

	// DisableLogging turns off logging.
	DisableLogging()

	// SetBodyObfuscator sets the body obfuscator to use.
	SetBodyObfuscator(bodyObfuscator obfuscation.BodyObfuscator)

	// SetHeaderObfuscator sets the header obfuscator to use.
	SetHeaderObfuscator(headerObfuscator obfuscation.HeaderObfuscator)

	// Close closes the connection of the Communicator
	Close() error
}

Connection represents a pooled connection to the Worldline Global Collect platform server. Instead of setting up a new HTTP connection for each request, this connection uses a pool of HTTP connections. Thread-safe

type DefaultConnection

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

DefaultConnection is the default implementation for the connection interface. Supports Pooling, and is thread safe.

func NewDefaultConnection

func NewDefaultConnection(socketTimeout, connectTimeout, keepAliveTimeout, idleTimeout time.Duration, maxConnections int, proxy *url.URL) (*DefaultConnection, error)

NewDefaultConnection creates a new object that implements Connection, and initializes it

func (*DefaultConnection) Close

func (c *DefaultConnection) Close() error

Close implements the io.Closer interface

func (*DefaultConnection) CloseExpiredConnections

func (c *DefaultConnection) CloseExpiredConnections()

CloseExpiredConnections closes all expired HTTP connections.

func (*DefaultConnection) CloseIdleConnections

func (c *DefaultConnection) CloseIdleConnections(t time.Duration)

CloseIdleConnections closes all HTTP connections that have been idle for the specified time. This should also include all expired HTTP connections. timespan represents the time spent idle Note: in the current implementation, it is only possible to close the connection after a predetermined time Therefore, this implementation ignores the parameter, and instead uses the preconfigured one

func (*DefaultConnection) Delete

func (c *DefaultConnection) Delete(uri url.URL, headerList []communication.Header, handler communication.ResponseHandler) (interface{}, error)

Delete sends a DELETE request to the Worldline Global Collect platform and calls the given response handler with the response.

func (*DefaultConnection) DisableLogging

func (c *DefaultConnection) DisableLogging()

DisableLogging implements the logging.Capable interface Disables logging

func (*DefaultConnection) EnableLogging

func (c *DefaultConnection) EnableLogging(logger logging.CommunicatorLogger)

EnableLogging implements the logging.Capable interface Enables logging to the given CommunicatorLogger

func (*DefaultConnection) Get

func (c *DefaultConnection) Get(uri url.URL, headerList []communication.Header, handler communication.ResponseHandler) (interface{}, error)

Get sends a GET request to the Worldline Global Collect platform and calls the given response handler with the response.

func (*DefaultConnection) Post

func (c *DefaultConnection) Post(uri url.URL, headerList []communication.Header, body string, handler communication.ResponseHandler) (interface{}, error)

Post sends a POST request to the Worldline Global Collect platform and calls the given response handler with the response.

func (*DefaultConnection) PostMultipart

func (c *DefaultConnection) PostMultipart(uri url.URL, headerList []communication.Header, body *communication.MultipartFormDataObject, handler communication.ResponseHandler) (interface{}, error)

PostMultipart sends a multipart/form-data POST request to the Worldline Global Collect platform and calls the given response handler with the response.

func (*DefaultConnection) Put

func (c *DefaultConnection) Put(uri url.URL, headerList []communication.Header, body string, handler communication.ResponseHandler) (interface{}, error)

Put sends a PUT request to the Worldline Global Collect platform and returns the response.

func (*DefaultConnection) PutMultipart

func (c *DefaultConnection) PutMultipart(uri url.URL, headerList []communication.Header, body *communication.MultipartFormDataObject, handler communication.ResponseHandler) (interface{}, error)

PutMultipart sends a multipart/form-data POST request to the Worldline Global Collect platform and calls the given response handler with the response.

func (*DefaultConnection) SetBodyObfuscator

func (c *DefaultConnection) SetBodyObfuscator(bodyObfuscator obfuscation.BodyObfuscator)

SetBodyObfuscator sets the body obfuscator to use.

func (*DefaultConnection) SetHeaderObfuscator

func (c *DefaultConnection) SetHeaderObfuscator(headerObfuscator obfuscation.HeaderObfuscator)

SetHeaderObfuscator sets the header obfuscator to use.

type MetadataProvider

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

MetadataProvider provides meta info about the server. Thread-safe.

func NewMetadataProvider

func NewMetadataProvider(integrator string) (*MetadataProvider, error)

NewMetadataProvider creates a MetadataProvider

func (MetadataProvider) MetadataHeaders

func (m MetadataProvider) MetadataHeaders() []communication.Header

MetadataHeaders returns the server related headers containing the metadata to be associated with the request (if any). This will always contain at least an automatically generated header X-GCS-ServerMetaInfo.

type MetadataProviderBuilder

type MetadataProviderBuilder struct {
	ShoppingCartExtension    *domain.ShoppingCartExtension
	AdditionalRequestHeaders []communication.Header
	// contains filtered or unexported fields
}

MetadataProviderBuilder represents a builder for a MetadataProvider object.

func NewMetadataProviderBuilder

func NewMetadataProviderBuilder(integrator string) (*MetadataProviderBuilder, error)

NewMetadataProviderBuilder creates a MetadataProviderBuilder with the given Integrator

func (MetadataProviderBuilder) Build

Build creates a fully initialized MetadataProvider

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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