Skip to content
Merged
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
5 changes: 1 addition & 4 deletions ballerina/Ballerina.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@
distribution = "2201.10.0"
org = "ballerinax"
name = "hubspot.crm.obj.schemas"
version = "1.0.0"
version = "2.0.0"
license = ["Apache-2.0"]
authors = ["Ballerina"]
keywords = ["schema", "hubspot", "object"]
repository = "https://github.com/ballerina-platform/module-ballerinax-hubspot.crm.object.schemas"

[build-options]
observabilityIncluded = true

[platform.java17]
graalvmCompatible = true
46 changes: 28 additions & 18 deletions ballerina/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@

[ballerina]
dependencies-toml-version = "2"
distribution-version = "2201.10.0"
distribution-version = "2201.12.2"

[[package]]
org = "ballerina"
name = "auth"
version = "2.12.0"
version = "2.14.0"
dependencies = [
{org = "ballerina", name = "crypto"},
{org = "ballerina", name = "jballerina.java"},
Expand All @@ -22,7 +22,7 @@ dependencies = [
[[package]]
org = "ballerina"
name = "cache"
version = "3.8.0"
version = "3.10.0"
dependencies = [
{org = "ballerina", name = "constraint"},
{org = "ballerina", name = "jballerina.java"},
Expand All @@ -33,24 +33,33 @@ dependencies = [
[[package]]
org = "ballerina"
name = "constraint"
version = "1.5.0"
version = "1.7.0"
dependencies = [
{org = "ballerina", name = "jballerina.java"}
]

[[package]]
org = "ballerina"
name = "crypto"
version = "2.7.2"
version = "2.9.0"
dependencies = [
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "time"}
]

[[package]]
org = "ballerina"
name = "data.jsondata"
version = "1.1.0"
dependencies = [
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "lang.object"}
]

[[package]]
org = "ballerina"
name = "file"
version = "1.10.0"
version = "1.12.0"
dependencies = [
{org = "ballerina", name = "io"},
{org = "ballerina", name = "jballerina.java"},
Expand All @@ -61,12 +70,13 @@ dependencies = [
[[package]]
org = "ballerina"
name = "http"
version = "2.12.4"
version = "2.14.0"
dependencies = [
{org = "ballerina", name = "auth"},
{org = "ballerina", name = "cache"},
{org = "ballerina", name = "constraint"},
{org = "ballerina", name = "crypto"},
{org = "ballerina", name = "data.jsondata"},
{org = "ballerina", name = "file"},
{org = "ballerina", name = "io"},
{org = "ballerina", name = "jballerina.java"},
Expand All @@ -93,7 +103,7 @@ modules = [
[[package]]
org = "ballerina"
name = "io"
version = "1.6.3"
version = "1.8.0"
dependencies = [
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "lang.value"}
Expand All @@ -110,7 +120,7 @@ version = "0.0.0"
[[package]]
org = "ballerina"
name = "jwt"
version = "2.13.0"
version = "2.15.0"
dependencies = [
{org = "ballerina", name = "cache"},
{org = "ballerina", name = "crypto"},
Expand Down Expand Up @@ -208,7 +218,7 @@ dependencies = [
[[package]]
org = "ballerina"
name = "log"
version = "2.10.0"
version = "2.12.0"
dependencies = [
{org = "ballerina", name = "io"},
{org = "ballerina", name = "jballerina.java"},
Expand All @@ -219,7 +229,7 @@ dependencies = [
[[package]]
org = "ballerina"
name = "mime"
version = "2.10.1"
version = "2.12.0"
dependencies = [
{org = "ballerina", name = "io"},
{org = "ballerina", name = "jballerina.java"},
Expand All @@ -230,7 +240,7 @@ dependencies = [
[[package]]
org = "ballerina"
name = "oauth2"
version = "2.12.0"
version = "2.14.0"
dependencies = [
{org = "ballerina", name = "cache"},
{org = "ballerina", name = "crypto"},
Expand All @@ -246,15 +256,15 @@ modules = [
[[package]]
org = "ballerina"
name = "observe"
version = "1.3.0"
version = "1.5.0"
dependencies = [
{org = "ballerina", name = "jballerina.java"}
]

[[package]]
org = "ballerina"
name = "os"
version = "1.8.0"
version = "1.10.0"
dependencies = [
{org = "ballerina", name = "io"},
{org = "ballerina", name = "jballerina.java"}
Expand All @@ -263,7 +273,7 @@ dependencies = [
[[package]]
org = "ballerina"
name = "task"
version = "2.5.0"
version = "2.7.0"
dependencies = [
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "time"}
Expand All @@ -286,15 +296,15 @@ modules = [
[[package]]
org = "ballerina"
name = "time"
version = "2.5.0"
version = "2.7.0"
dependencies = [
{org = "ballerina", name = "jballerina.java"}
]

[[package]]
org = "ballerina"
name = "url"
version = "2.4.0"
version = "2.6.0"
dependencies = [
{org = "ballerina", name = "jballerina.java"}
]
Expand All @@ -317,7 +327,7 @@ modules = [
[[package]]
org = "ballerinax"
name = "hubspot.crm.obj.schemas"
version = "1.0.0"
version = "2.0.0"
dependencies = [
{org = "ballerina", name = "http"},
{org = "ballerina", name = "io"},
Expand Down
95 changes: 36 additions & 59 deletions ballerina/client.bal
Original file line number Diff line number Diff line change
Expand Up @@ -29,118 +29,95 @@
# + 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? {

Check warning on line 32 in ballerina/client.bal

View check run for this annotation

Codecov / codecov/patch

ballerina/client.bal#L32

Added line #L32 was not covered by tests
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 .(map<string|string[]> headers = {}, *GetCrmObjectSchemasV3SchemasGetAllQueries queries) returns CollectionResponseObjectSchemaNoPaging|error {
string resourcePath = string `/`;
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 .(ObjectSchemaEgg payload, map<string|string[]> headers = {}) returns ObjectSchema|error {
string resourcePath = string `/`;
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 [string objectType](map<string|string[]> headers = {}) returns ObjectSchema|error {
string resourcePath = string `/${getEncodedUri(objectType)}`;

Check warning on line 68 in ballerina/client.bal

View check run for this annotation

Codecov / codecov/patch

ballerina/client.bal#L67-L68

Added lines #L67 - L68 were not covered by tests
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);

Check warning on line 73 in ballerina/client.bal

View check run for this annotation

Codecov / codecov/patch

ballerina/client.bal#L73

Added line #L73 was not covered by tests
return self.clientEp->get(resourcePath, httpHeaders);
}

resource isolated function get [string objectType](map<string|string[]> headers = {}) returns ObjectSchema|error {
resource isolated function delete [string objectType](map<string|string[]> headers = {}, *DeleteCrmObjectSchemasV3SchemasObjectTypeArchiveQueries queries) returns error? {
string resourcePath = string `/${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)}`;
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 [string objectType]/associations(AssociationDefinitionEgg payload, map<string|string[]> headers = {}) returns AssociationDefinition|error {
string resourcePath = string `/${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 [string objectType]/associations/[string associationIdentifier](map<string|string[]> headers = {}) returns error? {
string resourcePath = string `/${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);
}
}
8 changes: 4 additions & 4 deletions ballerina/tests/tests.bal
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ isolated function testDeleteSchema() returns error? {
string objId = "testid";

// Make DELETE request to delete the schema
http:Response response = check hpClient->/[objId].delete();
test:assertEquals(response.statusCode, 204);
error? response = check hpClient->/[objId].delete();
test:assertEquals(response, ());
}

// Test: Update Schema - Updates an existing schema by ID
Expand Down Expand Up @@ -174,6 +174,6 @@ isolated function testDeleteAssosiation() returns error? {
string assId = "testid";

// Make DELETE request to delete the schema
http:Response response = check hpClient->/[objId]/associations/[assId].delete();
test:assertEquals(response.statusCode, 204);
error? response = check hpClient->/[objId]/associations/[assId].delete();
test:assertEquals(response, ());
}
Loading
Loading