Class Communicator
Used to communicate with the Worldline Global Collect platform web services.
Inherited Members
Namespace: Worldline.Connect.Sdk
Assembly: Worldline.Connect.Sdk.dll
Syntax
public class Communicator : IDisposable, ILoggingCapable, IObfuscationCapable
Remarks
It contains all the logic to transform a request object to a HTTP request and a HTTP response to a response object. It is also thread safe.
Constructors
Communicator(Uri, IConnection, IAuthenticator, MetadataProvider, IMarshaller)
Declaration
public Communicator(Uri apiEndpoint, IConnection connection, IAuthenticator authenticator, MetadataProvider metadataProvider, IMarshaller marshaller)
Parameters
Type | Name | Description |
---|---|---|
Uri | apiEndpoint | |
IConnection | connection | |
IAuthenticator | authenticator | |
MetadataProvider | metadataProvider | |
IMarshaller | marshaller |
Properties
BodyObfuscator
The current non-null body obfuscator to use.
Declaration
public BodyObfuscator BodyObfuscator { set; }
Property Value
Type | Description |
---|---|
BodyObfuscator |
HeaderObfuscator
The current non-null header obfuscator to use.
Declaration
public HeaderObfuscator HeaderObfuscator { set; }
Property Value
Type | Description |
---|---|
HeaderObfuscator |
Marshaller
Gets the IMarshaller object associated with this communicator. Never null
.
Declaration
public IMarshaller Marshaller { get; }
Property Value
Type | Description |
---|---|
IMarshaller |
Methods
AddGenericHeaders(HttpMethod, Uri, IEnumerable<IRequestHeader>, CallContext)
Adds the necessary headers to the given list of headers. This includes the authorization header,
which uses other headers, so when you need to override this method,
make sure to call base.AddGenericHeaders
at the end of your overridden method.
Declaration
protected Task<IEnumerable<IRequestHeader>> AddGenericHeaders(HttpMethod httpMethod, Uri uri, IEnumerable<IRequestHeader> requestHeaders, CallContext context)
Parameters
Type | Name | Description |
---|---|---|
HttpMethod | httpMethod | |
Uri | uri | |
IEnumerable<IRequestHeader> | requestHeaders | |
CallContext | context |
Returns
Type | Description |
---|---|
Task<IEnumerable<IRequestHeader>> |
CloseExpiredConnections()
Utility method that delegates the call to this communicator's connection if that's an instance of IPooledConnection. If not this method does nothing. CloseExpiredConnections()
Declaration
public void CloseExpiredConnections()
CloseIdleConnections(TimeSpan)
Utility method that delegates the call to this communicator's connection if that's an instance of IPooledConnection.
Declaration
public void CloseIdleConnections(TimeSpan timespan)
Parameters
Type | Name | Description |
---|---|---|
TimeSpan | timespan | Idle time. |
Delete(string, IEnumerable<IRequestHeader>, AbstractParamRequest, Action<Stream, IEnumerable<IResponseHeader>>, CallContext)
Corresponds to the HTTP DELETE method.
Declaration
public Task Delete(string relativePath, IEnumerable<IRequestHeader> requestHeaders, AbstractParamRequest requestParameters, Action<Stream, IEnumerable<IResponseHeader>> bodyHandler, CallContext context)
Parameters
Type | Name | Description |
---|---|---|
string | relativePath | The path to call, relative to the base URI. |
IEnumerable<IRequestHeader> | requestHeaders | An optional list of request headers. |
AbstractParamRequest | requestParameters | The optional set of request parameters. |
Action<Stream, IEnumerable<IResponseHeader>> | bodyHandler | A callback that receives the contents of the body as a stream |
CallContext | context | The optional call context to use |
Returns
Type | Description |
---|---|
Task |
Exceptions
Type | Condition |
---|---|
CommunicationException | when an exception occurred communicating with the Worldline Global Collect platform |
ResponseException | when an error response was received from the Worldline Global Collect platform |
BodyHandlerException | when the BodyHandler throws an exception |
Delete<T>(string, IEnumerable<IRequestHeader>, AbstractParamRequest, CallContext)
Corresponds to the HTTP DELETE method.
Declaration
public Task<T> Delete<T>(string relativePath, IEnumerable<IRequestHeader> requestHeaders, AbstractParamRequest requestParameters, CallContext context)
Parameters
Type | Name | Description |
---|---|---|
string | relativePath | The path to call, relative to the base URI. |
IEnumerable<IRequestHeader> | requestHeaders | An optional list of request headers. |
AbstractParamRequest | requestParameters | The optional set of request parameters. |
CallContext | context | The optional call context to use |
Returns
Type | Description |
---|---|
Task<T> |
Type Parameters
Name | Description |
---|---|
T | Type of the response. |
Exceptions
Type | Condition |
---|---|
CommunicationException | when an exception occurred communicating with the Worldline Global Collect platform |
ResponseException | when an error response was received from the Worldline Global Collect platform |
DisableLogging()
Turns off logging.
Declaration
public void DisableLogging()
Dispose()
Releases all resource used by the Communicator object.
Declaration
public void Dispose()
Remarks
Call Dispose() when you are finished using the Communicator. The Dispose() method leaves the Communicator in an unusable state. After calling Dispose(), you must release all references to the Communicator so the garbage collector can reclaim the memory that the Communicator was occupying.
EnableLogging(ICommunicatorLogger)
Turns on logging using the given communicator logger.
Declaration
public void EnableLogging(ICommunicatorLogger communicatorLogger)
Parameters
Type | Name | Description |
---|---|---|
ICommunicatorLogger | communicatorLogger | The given communicator logger. |
Exceptions
Type | Condition |
---|---|
ArgumentException | If the given communicator logger is |
Get(string, IEnumerable<IRequestHeader>, AbstractParamRequest, Action<Stream, IEnumerable<IResponseHeader>>, CallContext)
Corresponds to the HTTP Get method.
Declaration
public Task Get(string relativePath, IEnumerable<IRequestHeader> requestHeaders, AbstractParamRequest requestParameters, Action<Stream, IEnumerable<IResponseHeader>> bodyHandler, CallContext context)
Parameters
Type | Name | Description |
---|---|---|
string | relativePath | The path to call, relative to the base URI. |
IEnumerable<IRequestHeader> | requestHeaders | An optional list of request headers. |
AbstractParamRequest | requestParameters | The optional set of request parameters. |
Action<Stream, IEnumerable<IResponseHeader>> | bodyHandler | A callback that receives the contents of the body as a stream |
CallContext | context | The optional call context to use |
Returns
Type | Description |
---|---|
Task |
Exceptions
Type | Condition |
---|---|
CommunicationException | when an exception occurred communicating with the Worldline Global Collect platform |
ResponseException | when an error response was received from the Worldline Global Collect platform |
BodyHandlerException | when the BodyHandler throws an exception |
Get<T>(string, IEnumerable<IRequestHeader>, AbstractParamRequest, CallContext)
Corresponds to the HTTP Get method.
Declaration
public Task<T> Get<T>(string relativePath, IEnumerable<IRequestHeader> requestHeaders, AbstractParamRequest requestParameters, CallContext context)
Parameters
Type | Name | Description |
---|---|---|
string | relativePath | The path to call, relative to the base URI. |
IEnumerable<IRequestHeader> | requestHeaders | An optional list of request headers. |
AbstractParamRequest | requestParameters | The optional set of request parameters. |
CallContext | context | The optional call context to use |
Returns
Type | Description |
---|---|
Task<T> |
Type Parameters
Name | Description |
---|---|
T | Type of the response. |
Exceptions
Type | Condition |
---|---|
CommunicationException | when an exception occurred communicating with the Worldline Global Collect platform |
ResponseException | when an error response was received from the Worldline Global Collect platform |
GetHeaderDateString()
Gets the date in the preferred format for the HTTP date header (RFC1123).
Declaration
protected static string GetHeaderDateString()
Returns
Type | Description |
---|---|
string | The header date string. |
GetIdempotenceTimestamp(IEnumerable<IResponseHeader>)
Declaration
protected static long? GetIdempotenceTimestamp(IEnumerable<IResponseHeader> headers)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<IResponseHeader> | headers |
Returns
Type | Description |
---|---|
long? |
Post(string, IEnumerable<IRequestHeader>, AbstractParamRequest, object, Action<Stream, IEnumerable<IResponseHeader>>, CallContext)
Corresponds to the HTTP POST method.
Declaration
public Task Post(string relativePath, IEnumerable<IRequestHeader> requestHeaders, AbstractParamRequest requestParameters, object requestBody, Action<Stream, IEnumerable<IResponseHeader>> bodyHandler, CallContext context)
Parameters
Type | Name | Description |
---|---|---|
string | relativePath | The path to call, relative to the base URI. |
IEnumerable<IRequestHeader> | requestHeaders | An optional list of request headers. |
AbstractParamRequest | requestParameters | The optional set of request parameters. |
object | requestBody | The optional request body to send. |
Action<Stream, IEnumerable<IResponseHeader>> | bodyHandler | A callback that receives the contents of the body as a stream |
CallContext | context | The optional call context to use |
Returns
Type | Description |
---|---|
Task |
Exceptions
Type | Condition |
---|---|
CommunicationException | when an exception occurred communicating with the Worldline Global Collect platform |
ResponseException | when an error response was received from the Worldline Global Collect platform |
BodyHandlerException | when the BodyHandler throws an exception |
Post<T>(string, IEnumerable<IRequestHeader>, AbstractParamRequest, object, CallContext)
Corresponds to the HTTP POST method.
Declaration
public Task<T> Post<T>(string relativePath, IEnumerable<IRequestHeader> requestHeaders, AbstractParamRequest requestParameters, object requestBody, CallContext context)
Parameters
Type | Name | Description |
---|---|---|
string | relativePath | The path to call, relative to the base URI. |
IEnumerable<IRequestHeader> | requestHeaders | An optional list of request headers. |
AbstractParamRequest | requestParameters | The optional set of request parameters. |
object | requestBody | The optional request body to send. |
CallContext | context | The optional call context to use |
Returns
Type | Description |
---|---|
Task<T> |
Type Parameters
Name | Description |
---|---|
T | Type of the response. |
Exceptions
Type | Condition |
---|---|
CommunicationException | when an exception occurred communicating with the Worldline Global Collect platform |
ResponseException | when an error response was received from the Worldline Global Collect platform |
ProcessResponse<T>(HttpStatusCode, Stream, IEnumerable<IResponseHeader>, string, CallContext, Action<Stream, IEnumerable<IResponseHeader>>)
Declaration
protected T ProcessResponse<T>(HttpStatusCode statusCode, Stream stream, IEnumerable<IResponseHeader> headers, string requestPath, CallContext context, Action<Stream, IEnumerable<IResponseHeader>> bodyHandler = null)
Parameters
Type | Name | Description |
---|---|---|
HttpStatusCode | statusCode | |
Stream | stream | |
IEnumerable<IResponseHeader> | headers | |
string | requestPath | |
CallContext | context | |
Action<Stream, IEnumerable<IResponseHeader>> | bodyHandler |
Returns
Type | Description |
---|---|
T |
Type Parameters
Name | Description |
---|---|
T |
Put(string, IEnumerable<IRequestHeader>, AbstractParamRequest, object, Action<Stream, IEnumerable<IResponseHeader>>, CallContext)
Corresponds to the HTTP PUT method.
Declaration
public Task Put(string relativePath, IEnumerable<IRequestHeader> requestHeaders, AbstractParamRequest requestParameters, object requestBody, Action<Stream, IEnumerable<IResponseHeader>> bodyHandler, CallContext context)
Parameters
Type | Name | Description |
---|---|---|
string | relativePath | The path to call, relative to the base URI. |
IEnumerable<IRequestHeader> | requestHeaders | An optional list of request headers. |
AbstractParamRequest | requestParameters | The optional set of request parameters. |
object | requestBody | The optional request body to send. |
Action<Stream, IEnumerable<IResponseHeader>> | bodyHandler | A callback that receives the contents of the body as a stream |
CallContext | context | The optional call context to use |
Returns
Type | Description |
---|---|
Task |
Exceptions
Type | Condition |
---|---|
CommunicationException | when an exception occurred communicating with the Worldline Global Collect platform |
ResponseException | when an error response was received from the Worldline Global Collect platform |
BodyHandlerException | when the BodyHandler throws an exception |
Put<T>(string, IEnumerable<IRequestHeader>, AbstractParamRequest, object, CallContext)
Corresponds to the HTTP PUT method.
Declaration
public Task<T> Put<T>(string relativePath, IEnumerable<IRequestHeader> requestHeaders, AbstractParamRequest requestParameters, object requestBody, CallContext context)
Parameters
Type | Name | Description |
---|---|---|
string | relativePath | The path to call, relative to the base URI. |
IEnumerable<IRequestHeader> | requestHeaders | An optional list of request headers. |
AbstractParamRequest | requestParameters | The optional set of request parameters. |
object | requestBody | The optional request body to send. |
CallContext | context | The optional call context to use |
Returns
Type | Description |
---|---|
Task<T> |
Type Parameters
Name | Description |
---|---|
T | Type of the response. |
Exceptions
Type | Condition |
---|---|
CommunicationException | when an exception occurred communicating with the Worldline Global Collect platform |
ResponseException | when an error response was received from the Worldline Global Collect platform |
ThrowExceptionIfNecessary(HttpStatusCode, Stream, IEnumerable<IResponseHeader>, string)
Checks the response for errors and throws an exception if necessary.
Declaration
protected static void ThrowExceptionIfNecessary(HttpStatusCode statusCode, Stream stream, IEnumerable<IResponseHeader> headers, string requestPath)
Parameters
Type | Name | Description |
---|---|---|
HttpStatusCode | statusCode | |
Stream | stream | |
IEnumerable<IResponseHeader> | headers | |
string | requestPath |