Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
137 changes: 57 additions & 80 deletions ballerina/client.bal
Original file line number Diff line number Diff line change
Expand Up @@ -28,87 +28,66 @@ public isolated client class Client {
# + serviceUrl - URL of the target service
# + return - An error if connector initialization failed
public isolated function init(ConnectionConfig config, string serviceUrl = "https://api.hubapi.com/communication-preferences/v4") returns error? {
http:ClientConfiguration httpClientConfig = {httpVersion: config.httpVersion, timeout: config.timeout, forwarded: config.forwarded, poolConfig: config.poolConfig, compression: config.compression, circuitBreaker: config.circuitBreaker, retryConfig: config.retryConfig, validation: config.validation};
do {
if config.http1Settings is ClientHttp1Settings {
ClientHttp1Settings settings = check config.http1Settings.ensureType(ClientHttp1Settings);
httpClientConfig.http1Settings = {...settings};
}
if config.http2Settings is http:ClientHttp2Settings {
httpClientConfig.http2Settings = check config.http2Settings.ensureType(http:ClientHttp2Settings);
}
if config.cache is http:CacheConfig {
httpClientConfig.cache = check config.cache.ensureType(http:CacheConfig);
}
if config.responseLimits is http:ResponseLimitConfigs {
httpClientConfig.responseLimits = check config.responseLimits.ensureType(http:ResponseLimitConfigs);
}
if config.secureSocket is http:ClientSecureSocket {
httpClientConfig.secureSocket = check config.secureSocket.ensureType(http:ClientSecureSocket);
}
if config.proxy is http:ProxyConfig {
httpClientConfig.proxy = check config.proxy.ensureType(http:ProxyConfig);
}
}
http:ClientConfiguration httpClientConfig = {httpVersion: config.httpVersion, http1Settings: config.http1Settings, http2Settings: config.http2Settings, timeout: config.timeout, forwarded: config.forwarded, followRedirects: config.followRedirects, poolConfig: config.poolConfig, cache: config.cache, compression: config.compression, circuitBreaker: config.circuitBreaker, retryConfig: config.retryConfig, cookieConfig: config.cookieConfig, responseLimits: config.responseLimits, secureSocket: config.secureSocket, proxy: config.proxy, socketConfig: config.socketConfig, validation: config.validation, laxDataBinding: config.laxDataBinding};
if config.auth is ApiKeysConfig {
self.apiKeyConfig = (<ApiKeysConfig>config.auth).cloneReadOnly();
} else {
httpClientConfig.auth = <http:BearerTokenConfig|OAuth2RefreshTokenGrantConfig>config.auth;
self.apiKeyConfig = ();
}
http:Client httpEp = check new (serviceUrl, httpClientConfig);
self.clientEp = httpEp;
return;
self.clientEp = check new (serviceUrl, httpClientConfig);
}

# Retrieve all subscription status definitions
# Batch update subscription status
#
# + headers - Headers to be sent with the request
# + queries - Queries to be sent with the request
# + return - successful operation
remote isolated function getCommunicationPreferencesV4Definitions(map<string|string[]> headers = {}, *GetCommunicationPreferencesV4DefinitionsQueries queries) returns ActionResponseWithResultsSubscriptionDefinition|error {
string resourcePath = string `/definitions`;
remote isolated function postCommunicationPreferencesV4StatusesBatchWrite(BatchInputPublicStatusRequest payload, map<string|string[]> headers = {}) returns BatchResponsePublicStatus|error {
string resourcePath = string `/statuses/batch/write`;
map<anydata> headerValues = {...headers};
if self.apiKeyConfig is ApiKeysConfig {
headerValues["private-app-legacy"] = self.apiKeyConfig?.private\-app\-legacy;
headerValues["private-app"] = self.apiKeyConfig?.privateApp;
}
resourcePath = resourcePath + check getPathForQueryParam(queries);
map<string|string[]> httpHeaders = getMapForHeaders(headerValues);
return self.clientEp->get(resourcePath, httpHeaders);
map<string|string[]> httpHeaders = http:getHeaderMap(headerValues);
http:Request request = new;
json jsonBody = payload.toJson();
request.setPayload(jsonBody, "application/json");
return self.clientEp->post(resourcePath, request, httpHeaders);
}

# Get subscription preferences for a specific contact
# Retrieve a contact's unsubscribed status
#
# + subscriberIdString - The contact's email address.
# + subscriberIdString - The contact's email address
# + headers - Headers to be sent with the request
# + queries - Queries to be sent with the request
# + return - successful operation
remote isolated function getCommunicationPreferencesV4StatusesSubscriberidstring(string subscriberIdString, map<string|string[]> headers = {}, *GetCommunicationPreferencesV4StatusesSubscriberidstringQueries queries) returns ActionResponseWithResultsPublicStatus|error {
string resourcePath = string `/statuses/${getEncodedUri(subscriberIdString)}`;
remote isolated function getCommunicationPreferencesV4StatusesSubscriberIdStringUnsubscribeAll(string subscriberIdString, map<string|string[]> headers = {}, *GetCommunicationPreferencesV4StatusesSubscriberIdStringUnsubscribeAllQueries queries) returns ActionResponseWithResultsPublicWideStatus|error {
string resourcePath = string `/statuses/${getEncodedUri(subscriberIdString)}/unsubscribe-all`;
map<anydata> headerValues = {...headers};
if self.apiKeyConfig is ApiKeysConfig {
headerValues["private-app-legacy"] = self.apiKeyConfig?.private\-app\-legacy;
headerValues["private-app-legacy"] = self.apiKeyConfig?.privateAppLegacy;
}
resourcePath = resourcePath + check getPathForQueryParam(queries);
map<string|string[]> httpHeaders = getMapForHeaders(headerValues);
map<string|string[]> httpHeaders = http:getHeaderMap(headerValues);
return self.clientEp->get(resourcePath, httpHeaders);
}

# Retrieve a contact's unsubscribed status
# Unsubscribe a contact from all subscriptions
#
# + subscriberIdString - The contact's email address.
# + subscriberIdString - The contact's email address
# + headers - Headers to be sent with the request
# + queries - Queries to be sent with the request
# + return - successful operation
remote isolated function getCommunicationPreferencesV4StatusesSubscriberidstringUnsubscribeAll(string subscriberIdString, map<string|string[]> headers = {}, *GetCommunicationPreferencesV4StatusesSubscriberidstringUnsubscribeAllQueries queries) returns ActionResponseWithResultsPublicWideStatus|error {
remote isolated function postCommunicationPreferencesV4StatusesSubscriberIdStringUnsubscribeAll(string subscriberIdString, map<string|string[]> headers = {}, *PostCommunicationPreferencesV4StatusesSubscriberIdStringUnsubscribeAllQueries queries) returns ActionResponseWithResultsPublicStatus|error {
string resourcePath = string `/statuses/${getEncodedUri(subscriberIdString)}/unsubscribe-all`;
map<anydata> headerValues = {...headers};
if self.apiKeyConfig is ApiKeysConfig {
headerValues["private-app-legacy"] = self.apiKeyConfig?.private\-app\-legacy;
headerValues["private-app-legacy"] = self.apiKeyConfig?.privateAppLegacy;
}
resourcePath = resourcePath + check getPathForQueryParam(queries);
map<string|string[]> httpHeaders = getMapForHeaders(headerValues);
return self.clientEp->get(resourcePath, httpHeaders);
map<string|string[]> httpHeaders = http:getHeaderMap(headerValues);
http:Request request = new;
return self.clientEp->post(resourcePath, request, httpHeaders);
}

# Batch retrieve subscription statuses
Expand All @@ -120,10 +99,10 @@ public isolated client class Client {
string resourcePath = string `/statuses/batch/read`;
map<anydata> headerValues = {...headers};
if self.apiKeyConfig is ApiKeysConfig {
headerValues["private-app"] = self.apiKeyConfig?.private\-app;
headerValues["private-app"] = self.apiKeyConfig?.privateApp;
}
resourcePath = resourcePath + check getPathForQueryParam(queries);
map<string|string[]> httpHeaders = getMapForHeaders(headerValues);
map<string|string[]> httpHeaders = http:getHeaderMap(headerValues);
http:Request request = new;
json jsonBody = payload.toJson();
request.setPayload(jsonBody, "application/json");
Expand All @@ -139,85 +118,83 @@ public isolated client class Client {
string resourcePath = string `/statuses/batch/unsubscribe-all`;
map<anydata> headerValues = {...headers};
if self.apiKeyConfig is ApiKeysConfig {
headerValues["private-app"] = self.apiKeyConfig?.private\-app;
headerValues["private-app"] = self.apiKeyConfig?.privateApp;
}
resourcePath = resourcePath + check getPathForQueryParam(queries);
map<string|string[]> httpHeaders = getMapForHeaders(headerValues);
map<string|string[]> httpHeaders = http:getHeaderMap(headerValues);
http:Request request = new;
json jsonBody = payload.toJson();
request.setPayload(jsonBody, "application/json");
return self.clientEp->post(resourcePath, request, httpHeaders);
}

# Batch retrieve contacts who have opted out of all communications
# Retrieve all subscription status definitions
#
# + headers - Headers to be sent with the request
# + queries - Queries to be sent with the request
# + return - successful operation
remote isolated function postCommunicationPreferencesV4StatusesBatchUnsubscribeAllRead(BatchInputString payload, map<string|string[]> headers = {}, *PostCommunicationPreferencesV4StatusesBatchUnsubscribeAllReadQueries queries) returns BatchResponsePublicWideStatusBulkResponse|BatchResponsePublicWideStatusBulkResponseWithErrors|error {
string resourcePath = string `/statuses/batch/unsubscribe-all/read`;
remote isolated function getCommunicationPreferencesV4Definitions(map<string|string[]> headers = {}, *GetCommunicationPreferencesV4DefinitionsQueries queries) returns ActionResponseWithResultsSubscriptionDefinition|error {
string resourcePath = string `/definitions`;
map<anydata> headerValues = {...headers};
if self.apiKeyConfig is ApiKeysConfig {
headerValues["private-app"] = self.apiKeyConfig?.private\-app;
headerValues["private-app-legacy"] = self.apiKeyConfig?.privateAppLegacy;
}
resourcePath = resourcePath + check getPathForQueryParam(queries);
map<string|string[]> httpHeaders = getMapForHeaders(headerValues);
http:Request request = new;
json jsonBody = payload.toJson();
request.setPayload(jsonBody, "application/json");
return self.clientEp->post(resourcePath, request, httpHeaders);
map<string|string[]> httpHeaders = http:getHeaderMap(headerValues);
return self.clientEp->get(resourcePath, httpHeaders);
}

# Batch update subscription status
# Batch retrieve contacts who have opted out of all communications
#
# + headers - Headers to be sent with the request
# + queries - Queries to be sent with the request
# + return - successful operation
remote isolated function postCommunicationPreferencesV4StatusesBatchWrite(BatchInputPublicStatusRequest payload, map<string|string[]> headers = {}) returns BatchResponsePublicStatus|error {
string resourcePath = string `/statuses/batch/write`;
remote isolated function postCommunicationPreferencesV4StatusesBatchUnsubscribeAllRead(BatchInputString payload, map<string|string[]> headers = {}, *PostCommunicationPreferencesV4StatusesBatchUnsubscribeAllReadQueries queries) returns BatchResponsePublicWideStatusBulkResponse|BatchResponsePublicWideStatusBulkResponseWithErrors|error {
string resourcePath = string `/statuses/batch/unsubscribe-all/read`;
map<anydata> headerValues = {...headers};
if self.apiKeyConfig is ApiKeysConfig {
headerValues["private-app"] = self.apiKeyConfig?.private\-app;
headerValues["private-app"] = self.apiKeyConfig?.privateApp;
}
map<string|string[]> httpHeaders = getMapForHeaders(headerValues);
resourcePath = resourcePath + check getPathForQueryParam(queries);
map<string|string[]> httpHeaders = http:getHeaderMap(headerValues);
http:Request request = new;
json jsonBody = payload.toJson();
request.setPayload(jsonBody, "application/json");
return self.clientEp->post(resourcePath, request, httpHeaders);
}

# Update a contact's subscription status
# Get subscription preferences for a specific contact
#
# + subscriberIdString - The contact's email address.
# + subscriberIdString - The contact's email address
# + headers - Headers to be sent with the request
# + queries - Queries to be sent with the request
# + return - successful operation
remote isolated function postCommunicationPreferencesV4StatusesSubscriberidstring(string subscriberIdString, PartialPublicStatusRequest payload, map<string|string[]> headers = {}) returns ActionResponseWithResultsPublicStatus|error {
remote isolated function getCommunicationPreferencesV4StatusesSubscriberIdString(string subscriberIdString, map<string|string[]> headers = {}, *GetCommunicationPreferencesV4StatusesSubscriberIdStringQueries queries) returns ActionResponseWithResultsPublicStatus|error {
string resourcePath = string `/statuses/${getEncodedUri(subscriberIdString)}`;
map<anydata> headerValues = {...headers};
if self.apiKeyConfig is ApiKeysConfig {
headerValues["private-app-legacy"] = self.apiKeyConfig?.private\-app\-legacy;
headerValues["private-app-legacy"] = self.apiKeyConfig?.privateAppLegacy;
}
map<string|string[]> httpHeaders = getMapForHeaders(headerValues);
http:Request request = new;
json jsonBody = payload.toJson();
request.setPayload(jsonBody, "application/json");
return self.clientEp->post(resourcePath, request, httpHeaders);
resourcePath = resourcePath + check getPathForQueryParam(queries);
map<string|string[]> httpHeaders = http:getHeaderMap(headerValues);
return self.clientEp->get(resourcePath, httpHeaders);
}

# Unsubscribe a contact from all subscriptions
# Update a contact's subscription status
#
# + subscriberIdString - The contact's email address.
# + subscriberIdString - The contact's email address
# + headers - Headers to be sent with the request
# + queries - Queries to be sent with the request
# + return - successful operation
remote isolated function postCommunicationPreferencesV4StatusesSubscriberidstringUnsubscribeAll(string subscriberIdString, map<string|string[]> headers = {}, *PostCommunicationPreferencesV4StatusesSubscriberidstringUnsubscribeAllQueries queries) returns ActionResponseWithResultsPublicStatus|error {
string resourcePath = string `/statuses/${getEncodedUri(subscriberIdString)}/unsubscribe-all`;
remote isolated function postCommunicationPreferencesV4StatusesSubscriberIdString(string subscriberIdString, PartialPublicStatusRequest payload, map<string|string[]> headers = {}) returns ActionResponseWithResultsPublicStatus|error {
string resourcePath = string `/statuses/${getEncodedUri(subscriberIdString)}`;
map<anydata> headerValues = {...headers};
if self.apiKeyConfig is ApiKeysConfig {
headerValues["private-app-legacy"] = self.apiKeyConfig?.private\-app\-legacy;
headerValues["private-app-legacy"] = self.apiKeyConfig?.privateAppLegacy;
}
resourcePath = resourcePath + check getPathForQueryParam(queries);
map<string|string[]> httpHeaders = getMapForHeaders(headerValues);
map<string|string[]> httpHeaders = http:getHeaderMap(headerValues);
http:Request request = new;
json jsonBody = payload.toJson();
request.setPayload(jsonBody, "application/json");
return self.clientEp->post(resourcePath, request, httpHeaders);
}
}
Loading
Loading