Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
148 changes: 62 additions & 86 deletions ballerina/client.bal
Original file line number Diff line number Diff line change
Expand Up @@ -22,194 +22,170 @@ import ballerina/http;
public isolated client class Client {
final http:Client clientEp;
final readonly & ApiKeysConfig? apiKeyConfig;

# Gets invoked to initialize the `connector`.
#
# + config - The configurations to be used when initializing the `connector`
# + 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/crm/v3/objects/leads") 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);
}

# Archive
# Read a batch of leads by internal ID, or unique property values
#
# + headers - Headers to be sent with the request
# + return - No content
resource isolated function delete [string leadsId](map<string|string[]> headers = {}) returns http:Response|error {
string resourcePath = string `/${getEncodedUri(leadsId)}`;
# + queries - Queries to be sent with the request
# + return - successful operation
resource isolated function post batch/read(BatchReadInputSimplePublicObjectId payload, map<string|string[]> headers = {}, *PostCrmV3ObjectsLeadsBatchReadReadQueries queries) returns BatchResponseSimplePublicObject|BatchResponseSimplePublicObjectWithErrors|error {
string resourcePath = string `/batch/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);
return self.clientEp->delete(resourcePath, headers = httpHeaders);
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);
}

# List
# Read
#
# + headers - Headers to be sent with the request
# + queries - Queries to be sent with the request
# + return - successful operation
resource isolated function get .(map<string|string[]> headers = {}, *GetCrmV3ObjectsLeads_getpageQueries queries) returns CollectionResponseSimplePublicObjectWithAssociationsForwardPaging|error {
string resourcePath = string `/`;
resource isolated function get [string leadsId](map<string|string[]> headers = {}, *GetCrmV3ObjectsLeadsLeadsIdGetByIdQueries queries) returns SimplePublicObjectWithAssociations|error {
string resourcePath = string `/${getEncodedUri(leadsId)}`;
map<anydata> headerValues = {...headers};
if self.apiKeyConfig is ApiKeysConfig {
headerValues["private-app"] = self.apiKeyConfig?.private\-app;
headerValues["private-app"] = self.apiKeyConfig?.privateApp;
}
map<Encoding> queryParamEncoding = {"properties": {style: FORM, explode: true}, "propertiesWithHistory": {style: FORM, explode: true}, "associations": {style: FORM, explode: true}};
resourcePath = resourcePath + check getPathForQueryParam(queries, queryParamEncoding);
map<string|string[]> httpHeaders = getMapForHeaders(headerValues);
map<string|string[]> httpHeaders = http:getHeaderMap(headerValues);
return self.clientEp->get(resourcePath, httpHeaders);
}

# Read
# Archive
#
# + headers - Headers to be sent with the request
# + queries - Queries to be sent with the request
# + return - successful operation
resource isolated function get [string leadsId](map<string|string[]> headers = {}, *GetCrmV3ObjectsLeadsLeadsid_getbyidQueries queries) returns SimplePublicObjectWithAssociations|error {
# + return - No content
resource isolated function delete [string leadsId](map<string|string[]> headers = {}) returns error? {
string resourcePath = string `/${getEncodedUri(leadsId)}`;
map<anydata> headerValues = {...headers};
if self.apiKeyConfig is ApiKeysConfig {
headerValues["private-app"] = self.apiKeyConfig?.private\-app;
headerValues["private-app"] = self.apiKeyConfig?.privateApp;
}
map<Encoding> queryParamEncoding = {"properties": {style: FORM, explode: true}, "propertiesWithHistory": {style: FORM, explode: true}, "associations": {style: FORM, explode: true}};
resourcePath = resourcePath + check getPathForQueryParam(queries, queryParamEncoding);
map<string|string[]> httpHeaders = getMapForHeaders(headerValues);
return self.clientEp->get(resourcePath, httpHeaders);
map<string|string[]> httpHeaders = http:getHeaderMap(headerValues);
return self.clientEp->delete(resourcePath, headers = httpHeaders);
}

# Update
#
# + headers - Headers to be sent with the request
# + queries - Queries to be sent with the request
# + return - successful operation
resource isolated function patch [string leadsId](SimplePublicObjectInput payload, map<string|string[]> headers = {}, *PatchCrmV3ObjectsLeadsLeadsid_updateQueries queries) returns SimplePublicObject|error {
resource isolated function patch [string leadsId](SimplePublicObjectInput payload, map<string|string[]> headers = {}, *PatchCrmV3ObjectsLeadsLeadsIdUpdateQueries queries) returns SimplePublicObject|error {
string resourcePath = string `/${getEncodedUri(leadsId)}`;
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->patch(resourcePath, request, httpHeaders);
}

# Create
# Archive a batch of leads by ID
#
# + headers - Headers to be sent with the request
# + return - successful operation
resource isolated function post .(SimplePublicObjectInputForCreate payload, map<string|string[]> headers = {}) returns SimplePublicObject|error {
string resourcePath = string `/`;
# + return - No content
resource isolated function post batch/archive(BatchInputSimplePublicObjectId payload, map<string|string[]> headers = {}) returns error? {
string resourcePath = string `/batch/archive`;
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);
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);
}

# Archive a batch of leads by ID
# Create a batch of leads
#
# + headers - Headers to be sent with the request
# + return - No content
resource isolated function post batch/archive(BatchInputSimplePublicObjectId payload, map<string|string[]> headers = {}) returns http:Response|error {
string resourcePath = string `/batch/archive`;
# + return - successful operation
resource isolated function post batch/create(BatchInputSimplePublicObjectInputForCreate payload, map<string|string[]> headers = {}) returns BatchResponseSimplePublicObject|BatchResponseSimplePublicObjectWithErrors|error {
string resourcePath = string `/batch/create`;
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);
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);
}

# Create a batch of leads
# Update a batch of leads by internal ID, or unique property values
#
# + headers - Headers to be sent with the request
# + return - successful operation
resource isolated function post batch/create(BatchInputSimplePublicObjectInputForCreate payload, map<string|string[]> headers = {}) returns BatchResponseSimplePublicObject|BatchResponseSimplePublicObjectWithErrors|error {
string resourcePath = string `/batch/create`;
resource isolated function post batch/update(BatchInputSimplePublicObjectBatchInput payload, map<string|string[]> headers = {}) returns BatchResponseSimplePublicObject|BatchResponseSimplePublicObjectWithErrors|error {
string resourcePath = string `/batch/update`;
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);
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);
}

# Read a batch of leads by internal ID, or unique property values
# List
#
# + headers - Headers to be sent with the request
# + queries - Queries to be sent with the request
# + return - successful operation
resource isolated function post batch/read(BatchReadInputSimplePublicObjectId payload, map<string|string[]> headers = {}, *PostCrmV3ObjectsLeadsBatchRead_readQueries queries) returns BatchResponseSimplePublicObject|BatchResponseSimplePublicObjectWithErrors|error {
string resourcePath = string `/batch/read`;
resource isolated function get .(map<string|string[]> headers = {}, *GetCrmV3ObjectsLeadsGetPageQueries queries) returns CollectionResponseSimplePublicObjectWithAssociationsForwardPaging|error {
string resourcePath = string `/`;
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);
http:Request request = new;
json jsonBody = payload.toJson();
request.setPayload(jsonBody, "application/json");
return self.clientEp->post(resourcePath, request, httpHeaders);
map<Encoding> queryParamEncoding = {"properties": {style: FORM, explode: true}, "propertiesWithHistory": {style: FORM, explode: true}, "associations": {style: FORM, explode: true}};
resourcePath = resourcePath + check getPathForQueryParam(queries, queryParamEncoding);
map<string|string[]> httpHeaders = http:getHeaderMap(headerValues);
return self.clientEp->get(resourcePath, httpHeaders);
}

# Update a batch of leads by internal ID, or unique property values
# Create
#
# + headers - Headers to be sent with the request
# + return - successful operation
resource isolated function post batch/update(BatchInputSimplePublicObjectBatchInput payload, map<string|string[]> headers = {}) returns BatchResponseSimplePublicObject|BatchResponseSimplePublicObjectWithErrors|error {
string resourcePath = string `/batch/update`;
resource isolated function post .(SimplePublicObjectInputForCreate payload, map<string|string[]> headers = {}) returns SimplePublicObject|error {
string resourcePath = string `/`;
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);
map<string|string[]> httpHeaders = http:getHeaderMap(headerValues);
http:Request request = new;
json jsonBody = payload.toJson();
request.setPayload(jsonBody, "application/json");
Expand All @@ -224,9 +200,9 @@ public isolated client class Client {
string resourcePath = string `/batch/upsert`;
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);
map<string|string[]> httpHeaders = http:getHeaderMap(headerValues);
http:Request request = new;
json jsonBody = payload.toJson();
request.setPayload(jsonBody, "application/json");
Expand All @@ -239,9 +215,9 @@ public isolated client class Client {
string resourcePath = string `/search`;
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);
map<string|string[]> httpHeaders = http:getHeaderMap(headerValues);
http:Request request = new;
json jsonBody = payload.toJson();
request.setPayload(jsonBody, "application/json");
Expand Down
Loading
Loading