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
102 changes: 39 additions & 63 deletions ballerina/client.bal
Original file line number Diff line number Diff line change
Expand Up @@ -23,124 +23,100 @@ 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-object-schemas/v3/schemas") 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);
}
}
public isolated function init(ConnectionConfig config, string serviceUrl = "https://api.hubapi.com") returns error? {
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);
}

resource isolated function delete [string objectType](map<string|string[]> headers = {}, *DeleteCrmObjectSchemasV3SchemasObjecttype_archiveQueries queries) returns http:Response|error {
string resourcePath = string `/${getEncodedUri(objectType)}`;
resource isolated function get crm\-object\-schemas/v3/schemas(map<string|string[]> headers = {}, *GetCrmObjectSchemasV3SchemasGetAllQueries queries) returns CollectionResponseObjectSchemaNoPaging|error {
string resourcePath = string `/crm-object-schemas/v3/schemas`;
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->delete(resourcePath, headers = httpHeaders);
map<string|string[]> httpHeaders = http:getHeaderMap(headerValues);
return self.clientEp->get(resourcePath, httpHeaders);
}

resource isolated function delete [string objectType]/associations/[string associationIdentifier](map<string|string[]> headers = {}) returns http:Response|error {
string resourcePath = string `/${getEncodedUri(objectType)}/associations/${getEncodedUri(associationIdentifier)}`;
resource isolated function post crm\-object\-schemas/v3/schemas(ObjectSchemaEgg payload, map<string|string[]> headers = {}) returns ObjectSchema|error {
string resourcePath = string `/crm-object-schemas/v3/schemas`;
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);
return self.clientEp->delete(resourcePath, headers = 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);
}

resource isolated function get .(map<string|string[]> headers = {}, *GetCrmObjectSchemasV3Schemas_getallQueries queries) returns CollectionResponseObjectSchemaNoPaging|error {
string resourcePath = string ``;
resource isolated function get crm\-object\-schemas/v3/schemas/[string objectType](map<string|string[]> headers = {}) returns ObjectSchema|error {
string resourcePath = string `/crm-object-schemas/v3/schemas/${getEncodedUri(objectType)}`;
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);
}

resource isolated function get [string objectType](map<string|string[]> headers = {}) returns ObjectSchema|error {
string resourcePath = string `/${getEncodedUri(objectType)}`;
resource isolated function delete crm\-object\-schemas/v3/schemas/[string objectType](map<string|string[]> headers = {}, *DeleteCrmObjectSchemasV3SchemasObjectTypeArchiveQueries queries) returns error? {
string resourcePath = string `/crm-object-schemas/v3/schemas/${getEncodedUri(objectType)}`;
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);
return self.clientEp->get(resourcePath, httpHeaders);
resourcePath = resourcePath + check getPathForQueryParam(queries);
map<string|string[]> httpHeaders = http:getHeaderMap(headerValues);
return self.clientEp->delete(resourcePath, headers = httpHeaders);
}

resource isolated function patch [string objectType](ObjectTypeDefinitionPatch payload, map<string|string[]> headers = {}) returns ObjectTypeDefinition|error {
string resourcePath = string `/${getEncodedUri(objectType)}`;
resource isolated function patch crm\-object\-schemas/v3/schemas/[string objectType](ObjectTypeDefinitionPatch payload, map<string|string[]> headers = {}) returns ObjectTypeDefinition|error {
string resourcePath = string `/crm-object-schemas/v3/schemas/${getEncodedUri(objectType)}`;
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);
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);
}

resource isolated function post .(ObjectSchemaEgg payload, map<string|string[]> headers = {}) returns ObjectSchema|error {
string resourcePath = string ``;
resource isolated function post crm\-object\-schemas/v3/schemas/[string objectType]/associations(AssociationDefinitionEgg payload, map<string|string[]> headers = {}) returns AssociationDefinition|error {
string resourcePath = string `/crm-object-schemas/v3/schemas/${getEncodedUri(objectType)}/associations`;
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);
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);
}

resource isolated function post [string objectType]/associations(AssociationDefinitionEgg payload, map<string|string[]> headers = {}) returns AssociationDefinition|error {
string resourcePath = string `/${getEncodedUri(objectType)}/associations`;
resource isolated function delete crm\-object\-schemas/v3/schemas/[string objectType]/associations/[string associationIdentifier](map<string|string[]> headers = {}) returns error? {
string resourcePath = string `/crm-object-schemas/v3/schemas/${getEncodedUri(objectType)}/associations/${getEncodedUri(associationIdentifier)}`;
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);
map<string|string[]> httpHeaders = http:getHeaderMap(headerValues);
return self.clientEp->delete(resourcePath, headers = httpHeaders);
}
}
Loading
Loading