From 9dd9343c6577ff8ce02bc1c89825ddd57a09995e Mon Sep 17 00:00:00 2001 From: ballerina-bot Date: Wed, 9 Apr 2025 07:44:07 +0000 Subject: [PATCH 1/2] [AUTOMATED] Update OpenAPI spec --- docs/spec/openapi.json | 76 +++++++++++++++++++++--------------------- 1 file changed, 38 insertions(+), 38 deletions(-) diff --git a/docs/spec/openapi.json b/docs/spec/openapi.json index 62c1967..8a4baab 100644 --- a/docs/spec/openapi.json +++ b/docs/spec/openapi.json @@ -74,7 +74,7 @@ "parameters" : [ { "name" : "subscriberIdString", "in" : "path", - "description" : "The contact's email address.", + "description" : "The contact's email address", "required" : true, "style" : "simple", "explode" : false, @@ -84,7 +84,7 @@ }, { "name" : "businessUnitId", "in" : "query", - "description" : "If you have the [business unit add-on](https://developers.hubspot.com/beta-docs/guides/api/settings/business-units-api), include this parameter to filter results by business unit ID. The default Account business unit will always use `0`.", + "description" : "If you have the [business unit add-on](https://developers.hubspot.com/beta-docs/guides/api/settings/business-units-api), include this parameter to filter results by business unit ID. The default Account business unit will always use `0`", "required" : false, "style" : "form", "explode" : true, @@ -95,7 +95,7 @@ }, { "name" : "verbose", "in" : "query", - "description" : "Set to `true` to include the details of the updated subscription statuses in the response. Not including this parameter will result in an empty response.", + "description" : "Set to `true` to include the details of the updated subscription statuses in the response. Not including this parameter will result in an empty response", "required" : false, "style" : "form", "explode" : true, @@ -106,7 +106,7 @@ }, { "name" : "channel", "in" : "query", - "description" : "The channel type for the subscription type. Currently, the only supported channel type is `EMAIL`.", + "description" : "The channel type for the subscription type. Currently, the only supported channel type is `EMAIL`", "required" : true, "style" : "form", "explode" : true, @@ -148,7 +148,7 @@ "parameters" : [ { "name" : "subscriberIdString", "in" : "path", - "description" : "The contact's email address.", + "description" : "The contact's email address", "required" : true, "style" : "simple", "explode" : false, @@ -158,7 +158,7 @@ }, { "name" : "businessUnitId", "in" : "query", - "description" : "If you have the [business unit add-on](https://developers.hubspot.com/beta-docs/guides/api/settings/business-units-api), include this parameter to filter results by business unit ID. The default Account business unit will always use `0`.", + "description" : "If you have the [business unit add-on](https://developers.hubspot.com/beta-docs/guides/api/settings/business-units-api), include this parameter to filter results by business unit ID. The default Account business unit will always use `0`", "required" : false, "style" : "form", "explode" : true, @@ -169,7 +169,7 @@ }, { "name" : "verbose", "in" : "query", - "description" : "Set to `true` to include the details of the updated subscription statuses in the response. Not including this parameter will result in an empty response.", + "description" : "Set to `true` to include the details of the updated subscription statuses in the response. Not including this parameter will result in an empty response", "required" : false, "style" : "form", "explode" : true, @@ -180,7 +180,7 @@ }, { "name" : "channel", "in" : "query", - "description" : "The channel type for the subscription type. Currently, the only supported channel type is `EMAIL`.", + "description" : "The channel type for the subscription type. Currently, the only supported channel type is `EMAIL`", "required" : true, "style" : "form", "explode" : true, @@ -224,7 +224,7 @@ "parameters" : [ { "name" : "businessUnitId", "in" : "query", - "description" : "If you have the [business unit add-on](https://developers.hubspot.com/beta-docs/guides/api/settings/business-units-api), include this parameter to filter results by business unit ID. The default Account business unit will always use `0`.", + "description" : "If you have the [business unit add-on](https://developers.hubspot.com/beta-docs/guides/api/settings/business-units-api), include this parameter to filter results by business unit ID. The default Account business unit will always use `0`", "required" : false, "style" : "form", "explode" : true, @@ -235,7 +235,7 @@ }, { "name" : "channel", "in" : "query", - "description" : "The channel type for the subscription type. Currently, the only supported channel type is `EMAIL`.", + "description" : "The channel type for the subscription type. Currently, the only supported channel type is `EMAIL`", "required" : true, "style" : "form", "explode" : true, @@ -295,7 +295,7 @@ "parameters" : [ { "name" : "businessUnitId", "in" : "query", - "description" : "If you have the [business unit add-on](https://developers.hubspot.com/beta-docs/guides/api/settings/business-units-api), include this parameter to filter results by business unit ID. The default Account business unit will always use `0`.", + "description" : "If you have the [business unit add-on](https://developers.hubspot.com/beta-docs/guides/api/settings/business-units-api), include this parameter to filter results by business unit ID. The default Account business unit will always use `0`", "required" : false, "style" : "form", "explode" : true, @@ -306,7 +306,7 @@ }, { "name" : "verbose", "in" : "query", - "description" : "Set to `true` to include the details of the updated subscription statuses in the response. Not including this parameter will result in an empty response.", + "description" : "Set to `true` to include the details of the updated subscription statuses in the response. Not including this parameter will result in an empty response", "required" : false, "style" : "form", "explode" : true, @@ -317,7 +317,7 @@ }, { "name" : "channel", "in" : "query", - "description" : "The channel type for the subscription type. Currently, the only supported channel type is `EMAIL`.", + "description" : "The channel type for the subscription type. Currently, the only supported channel type is `EMAIL`", "required" : true, "style" : "form", "explode" : true, @@ -358,7 +358,6 @@ } ] } }, - "/definitions" : { "get" : { "tags" : [ "Subscription definitions" ], @@ -368,7 +367,7 @@ "parameters" : [ { "name" : "businessUnitId", "in" : "query", - "description" : "If you have the [business unit add-on](https://developers.hubspot.com/beta-docs/guides/api/settings/business-units-api), include this parameter to filter results by business unit ID. The default Account business unit will always use `0`.", + "description" : "If you have the [business unit add-on](https://developers.hubspot.com/beta-docs/guides/api/settings/business-units-api), include this parameter to filter results by business unit ID. The default Account business unit will always use `0`", "required" : false, "style" : "form", "explode" : true, @@ -379,7 +378,7 @@ }, { "name" : "includeTranslations", "in" : "query", - "description" : "Set to `true` to return subscription translations associated with each definition.", + "description" : "Set to `true` to return subscription translations associated with each definition", "required" : false, "style" : "form", "explode" : true, @@ -422,7 +421,7 @@ "parameters" : [ { "name" : "businessUnitId", "in" : "query", - "description" : "If you have the [business unit add-on](https://developers.hubspot.com/beta-docs/guides/api/settings/business-units-api), include this parameter to filter results by business unit ID. The default Account business unit will always use `0`.", + "description" : "If you have the [business unit add-on](https://developers.hubspot.com/beta-docs/guides/api/settings/business-units-api), include this parameter to filter results by business unit ID. The default Account business unit will always use `0`", "required" : false, "style" : "form", "explode" : true, @@ -433,7 +432,7 @@ }, { "name" : "channel", "in" : "query", - "description" : "The channel type for the subscription type. Currently, the only supported channel type is `EMAIL`.", + "description" : "The channel type for the subscription type. Currently, the only supported channel type is `EMAIL`", "required" : true, "style" : "form", "explode" : true, @@ -493,7 +492,7 @@ "parameters" : [ { "name" : "subscriberIdString", "in" : "path", - "description" : "The contact's email address.", + "description" : "The contact's email address", "required" : true, "style" : "simple", "explode" : false, @@ -503,7 +502,7 @@ }, { "name" : "businessUnitId", "in" : "query", - "description" : "If you have the [business unit add-on](https://developers.hubspot.com/beta-docs/guides/api/settings/business-units-api), include this parameter to filter results by business unit ID. The default Account business unit will always use `0`.", + "description" : "If you have the [business unit add-on](https://developers.hubspot.com/beta-docs/guides/api/settings/business-units-api), include this parameter to filter results by business unit ID. The default Account business unit will always use `0`", "required" : false, "style" : "form", "explode" : true, @@ -514,7 +513,7 @@ }, { "name" : "channel", "in" : "query", - "description" : "The channel type for the subscription type. Currently, the only supported channel type is `EMAIL`.", + "description" : "The channel type for the subscription type. Currently, the only supported channel type is `EMAIL`", "required" : true, "style" : "form", "explode" : true, @@ -556,7 +555,7 @@ "parameters" : [ { "name" : "subscriberIdString", "in" : "path", - "description" : "The contact's email address.", + "description" : "The contact's email address", "required" : true, "style" : "simple", "explode" : false, @@ -785,13 +784,13 @@ }, "legalBasis" : { "type" : "string", - "enum" : [ "LEGITIMATE_INTEREST_PQL", "LEGITIMATE_INTEREST_CLIENT", "PERFORMANCE_OF_CONTRACT", "CONSENT_WITH_NOTICE", "NON_GDPR", "PROCESS_AND_STORE", "LEGITIMATE_INTEREST_OTHER" ], - "nullable": true + "nullable" : true, + "enum" : [ "LEGITIMATE_INTEREST_PQL", "LEGITIMATE_INTEREST_CLIENT", "PERFORMANCE_OF_CONTRACT", "CONSENT_WITH_NOTICE", "NON_GDPR", "PROCESS_AND_STORE", "LEGITIMATE_INTEREST_OTHER" ] }, "setStatusSuccessReason" : { "type" : "string", - "enum" : [ "RESUBSCRIBE_OCCURRED", "NO_STATUS_CHANGE", "UNSUBSCRIBE_FROM_ALL_OCCURRED", "REQUESTED_CHANGE_OCCURRED" ], - "nullable":true + "nullable" : true, + "enum" : [ "RESUBSCRIBE_OCCURRED", "NO_STATUS_CHANGE", "UNSUBSCRIBE_FROM_ALL_OCCURRED", "REQUESTED_CHANGE_OCCURRED" ] }, "source" : { "type" : "string" @@ -802,7 +801,7 @@ }, "legalBasisExplanation" : { "type" : "string", - "nullable":true + "nullable" : true }, "businessUnitId" : { "type" : "integer", @@ -973,31 +972,31 @@ "properties" : { "statusState" : { "type" : "string", - "description" : "The status of the contact's subscription.", + "description" : "The status of the contact's subscription", "enum" : [ "SUBSCRIBED", "UNSUBSCRIBED", "NOT_SPECIFIED" ] }, "channel" : { "type" : "string", - "description" : "The type of communication channel. Currently, only `EMAIL` is supported.", + "description" : "The type of communication channel. Currently, only `EMAIL` is supported", "enum" : [ "EMAIL", "WHATSAPP", "SMS" ] }, "subscriberIdString" : { "type" : "string", - "description" : "The contact's email address." + "description" : "The contact's email address" }, "legalBasis" : { "type" : "string", - "description" : "The legal basis for communication.", + "description" : "The legal basis for communication", "enum" : [ "LEGITIMATE_INTEREST_PQL", "LEGITIMATE_INTEREST_CLIENT", "PERFORMANCE_OF_CONTRACT", "CONSENT_WITH_NOTICE", "NON_GDPR", "PROCESS_AND_STORE", "LEGITIMATE_INTEREST_OTHER" ] }, "subscriptionId" : { "type" : "integer", - "description" : "The ID of the subscription to update.", + "description" : "The ID of the subscription to update", "format" : "int32" }, "legalBasisExplanation" : { "type" : "string", - "description" : "The explanation for the legal basis." + "description" : "The explanation for the legal basis" } } }, @@ -1142,7 +1141,7 @@ }, "in" : { "type" : "string", - "description" : "The name of the field or parameter in which the error was found." + "description" : "The name of the field or parameter in which the error was found" }, "context" : { "type" : "object", @@ -1443,14 +1442,15 @@ "private_apps_legacy" : { "type" : "apiKey", "name" : "private-app-legacy", - "in" : "header" + "in" : "header", + "x-ballerina-name" : "privateAppLegacy" }, "private_apps" : { "type" : "apiKey", "name" : "private-app", - "in" : "header" + "in" : "header", + "x-ballerina-name" : "privateApp" } } } -} - +} \ No newline at end of file From 24d8dd3ef20663ec84a79a1bc2ecf9c71b410e3f Mon Sep 17 00:00:00 2001 From: ballerina-bot Date: Wed, 9 Apr 2025 07:44:07 +0000 Subject: [PATCH 2/2] [AUTOMATED] Client Regeneration --- ballerina/client.bal | 150 ++++++++++++++++--------------------------- ballerina/types.bal | 130 +++++++++++++++++-------------------- ballerina/utils.bal | 25 ++------ gradle.properties | 2 +- 4 files changed, 119 insertions(+), 188 deletions(-) diff --git a/ballerina/client.bal b/ballerina/client.bal index 4acbbb6..e7fa8f9 100644 --- a/ballerina/client.bal +++ b/ballerina/client.bal @@ -28,87 +28,54 @@ 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 = (config.auth).cloneReadOnly(); } else { httpClientConfig.auth = 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 headers = {}, *GetCommunicationPreferencesV4DefinitionsQueries queries) returns ActionResponseWithResultsSubscriptionDefinition|error { - string resourcePath = string `/definitions`; + resource isolated function post statuses/batch/write(BatchInputPublicStatusRequest payload, map headers = {}) returns BatchResponsePublicStatus|error { + string resourcePath = string `/statuses/batch/write`; map 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 httpHeaders = getMapForHeaders(headerValues); - return self.clientEp->get(resourcePath, httpHeaders); + map 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 - # - # + 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 headers = {}, *GetCommunicationPreferencesV4StatusesSubscriberidstringQueries queries) returns ActionResponseWithResultsPublicStatus|error { - string resourcePath = string `/statuses/${getEncodedUri(subscriberIdString)}`; + resource isolated function get statuses/[string subscriberIdString]/unsubscribe\-all(map headers = {}, *GetCommunicationPreferencesV4StatusesSubscriberIdStringUnsubscribeAllQueries queries) returns ActionResponseWithResultsPublicWideStatus|error { + string resourcePath = string `/statuses/${getEncodedUri(subscriberIdString)}/unsubscribe-all`; map 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 httpHeaders = getMapForHeaders(headerValues); + map httpHeaders = http:getHeaderMap(headerValues); return self.clientEp->get(resourcePath, httpHeaders); } - # Retrieve a contact's unsubscribed status - # - # + 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 headers = {}, *GetCommunicationPreferencesV4StatusesSubscriberidstringUnsubscribeAllQueries queries) returns ActionResponseWithResultsPublicWideStatus|error { + resource isolated function post statuses/[string subscriberIdString]/unsubscribe\-all(map headers = {}, *PostCommunicationPreferencesV4StatusesSubscriberIdStringUnsubscribeAllQueries queries) returns ActionResponseWithResultsPublicStatus|error { string resourcePath = string `/statuses/${getEncodedUri(subscriberIdString)}/unsubscribe-all`; map 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 httpHeaders = getMapForHeaders(headerValues); - return self.clientEp->get(resourcePath, httpHeaders); + map httpHeaders = http:getHeaderMap(headerValues); + http:Request request = new; + return self.clientEp->post(resourcePath, request, httpHeaders); } # Batch retrieve subscription statuses @@ -116,108 +83,101 @@ public isolated client class Client { # + headers - Headers to be sent with the request # + queries - Queries to be sent with the request # + return - successful operation - remote isolated function postCommunicationPreferencesV4StatusesBatchRead(BatchInputString payload, map headers = {}, *PostCommunicationPreferencesV4StatusesBatchReadQueries queries) returns BatchResponsePublicStatusBulkResponse|BatchResponsePublicStatusBulkResponseWithErrors|error { + resource isolated function post statuses/batch/read(BatchInputString payload, map headers = {}, *PostCommunicationPreferencesV4StatusesBatchReadQueries queries) returns BatchResponsePublicStatusBulkResponse|BatchResponsePublicStatusBulkResponseWithErrors|error { string resourcePath = string `/statuses/batch/read`; map 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 httpHeaders = getMapForHeaders(headerValues); + map 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 unsubscribe contacts from all subscriptions - # - # + headers - Headers to be sent with the request - # + queries - Queries to be sent with the request - # + return - successful operation - remote isolated function postCommunicationPreferencesV4StatusesBatchUnsubscribeAll(BatchInputString payload, map headers = {}, *PostCommunicationPreferencesV4StatusesBatchUnsubscribeAllQueries queries) returns BatchResponsePublicBulkOptOutFromAllResponse|error { + resource isolated function post statuses/batch/unsubscribe\-all(BatchInputString payload, map headers = {}, *PostCommunicationPreferencesV4StatusesBatchUnsubscribeAllQueries queries) returns BatchResponsePublicBulkOptOutFromAllResponse|error { string resourcePath = string `/statuses/batch/unsubscribe-all`; map 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 httpHeaders = getMapForHeaders(headerValues); + map 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 headers = {}, *PostCommunicationPreferencesV4StatusesBatchUnsubscribeAllReadQueries queries) returns BatchResponsePublicWideStatusBulkResponse|BatchResponsePublicWideStatusBulkResponseWithErrors|error { - string resourcePath = string `/statuses/batch/unsubscribe-all/read`; + resource isolated function get definitions(map headers = {}, *GetCommunicationPreferencesV4DefinitionsQueries queries) returns ActionResponseWithResultsSubscriptionDefinition|error { + string resourcePath = string `/definitions`; map 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 httpHeaders = getMapForHeaders(headerValues); - http:Request request = new; - json jsonBody = payload.toJson(); - request.setPayload(jsonBody, "application/json"); - return self.clientEp->post(resourcePath, request, httpHeaders); + map 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 headers = {}) returns BatchResponsePublicStatus|error { - string resourcePath = string `/statuses/batch/write`; + resource isolated function post statuses/batch/unsubscribe\-all/read(BatchInputString payload, map headers = {}, *PostCommunicationPreferencesV4StatusesBatchUnsubscribeAllReadQueries queries) returns BatchResponsePublicWideStatusBulkResponse|BatchResponsePublicWideStatusBulkResponseWithErrors|error { + string resourcePath = string `/statuses/batch/unsubscribe-all/read`; map headerValues = {...headers}; if self.apiKeyConfig is ApiKeysConfig { - headerValues["private-app"] = self.apiKeyConfig?.private\-app; + headerValues["private-app"] = self.apiKeyConfig?.privateApp; } - map httpHeaders = getMapForHeaders(headerValues); + resourcePath = resourcePath + check getPathForQueryParam(queries); + map 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 headers = {}) returns ActionResponseWithResultsPublicStatus|error { + resource isolated function get statuses/[string subscriberIdString](map headers = {}, *GetCommunicationPreferencesV4StatusesSubscriberIdStringQueries queries) returns ActionResponseWithResultsPublicStatus|error { string resourcePath = string `/statuses/${getEncodedUri(subscriberIdString)}`; map headerValues = {...headers}; if self.apiKeyConfig is ApiKeysConfig { - headerValues["private-app-legacy"] = self.apiKeyConfig?.private\-app\-legacy; + headerValues["private-app-legacy"] = self.apiKeyConfig?.privateAppLegacy; } - map 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 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 headers = {}, *PostCommunicationPreferencesV4StatusesSubscriberidstringUnsubscribeAllQueries queries) returns ActionResponseWithResultsPublicStatus|error { - string resourcePath = string `/statuses/${getEncodedUri(subscriberIdString)}/unsubscribe-all`; + resource isolated function post statuses/[string subscriberIdString](PartialPublicStatusRequest payload, map headers = {}) returns ActionResponseWithResultsPublicStatus|error { + string resourcePath = string `/statuses/${getEncodedUri(subscriberIdString)}`; map 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 httpHeaders = getMapForHeaders(headerValues); + map httpHeaders = http:getHeaderMap(headerValues); http:Request request = new; + json jsonBody = payload.toJson(); + request.setPayload(jsonBody, "application/json"); return self.clientEp->post(resourcePath, request, httpHeaders); } } diff --git a/ballerina/types.bal b/ballerina/types.bal index f5983d1..28f3f17 100644 --- a/ballerina/types.bal +++ b/ballerina/types.bal @@ -84,7 +84,7 @@ public type ErrorDetail record { string subCategory?; # The status code associated with the error detail string code?; - # The name of the field or parameter in which the error was found. + # The name of the field or parameter in which the error was found string 'in?; # Context about the error condition record {|string[]...;|} context?; @@ -112,11 +112,11 @@ public type ActionResponseWithResultsSubscriptionDefinition record { "PENDING"|"PROCESSING"|"CANCELED"|"COMPLETE" status; }; -# Represents the Queries record for the operation: postCommunicationPreferencesV4StatusesBatchRead +# Represents the Queries record for the operation: post-/communication-preferences/v4/statuses/batch/read public type PostCommunicationPreferencesV4StatusesBatchReadQueries record { - # The channel type for the subscription type. Currently, the only supported channel type is `EMAIL`. + # The channel type for the subscription type. Currently, the only supported channel type is `EMAIL` "EMAIL"|"WHATSAPP"|"SMS" channel; - # If you have the [business unit add-on](https://developers.hubspot.com/beta-docs/guides/api/settings/business-units-api), include this parameter to filter results by business unit ID. The default Account business unit will always use `0`. + # If you have the [business unit add-on](https://developers.hubspot.com/beta-docs/guides/api/settings/business-units-api), include this parameter to filter results by business unit ID. The default Account business unit will always use `0` int businessUnitId?; }; @@ -127,13 +127,13 @@ public type OAuth2RefreshTokenGrantConfig record {| string refreshUrl = "https://api.hubapi.com/oauth/v1/token"; |}; -# Represents the Queries record for the operation: getCommunicationPreferencesV4StatusesSubscriberidstringUnsubscribeAll -public type GetCommunicationPreferencesV4StatusesSubscriberidstringUnsubscribeAllQueries record { - # The channel type for the subscription type. Currently, the only supported channel type is `EMAIL`. +# Represents the Queries record for the operation: post-/communication-preferences/v4/statuses/{subscriberIdString}/unsubscribe-all +public type PostCommunicationPreferencesV4StatusesSubscriberIdStringUnsubscribeAllQueries record { + # The channel type for the subscription type. Currently, the only supported channel type is `EMAIL` "EMAIL"|"WHATSAPP"|"SMS" channel; - # If you have the [business unit add-on](https://developers.hubspot.com/beta-docs/guides/api/settings/business-units-api), include this parameter to filter results by business unit ID. The default Account business unit will always use `0`. + # If you have the [business unit add-on](https://developers.hubspot.com/beta-docs/guides/api/settings/business-units-api), include this parameter to filter results by business unit ID. The default Account business unit will always use `0` int businessUnitId?; - # Set to `true` to include the details of the updated subscription statuses in the response. Not including this parameter will result in an empty response. + # Set to `true` to include the details of the updated subscription statuses in the response. Not including this parameter will result in an empty response boolean verbose = false; }; @@ -156,31 +156,40 @@ public type ConnectionConfig record {| # The HTTP version understood by the client http:HttpVersion httpVersion = http:HTTP_2_0; # Configurations related to HTTP/1.x protocol - ClientHttp1Settings http1Settings?; + http:ClientHttp1Settings http1Settings = {}; # Configurations related to HTTP/2 protocol - http:ClientHttp2Settings http2Settings?; + http:ClientHttp2Settings http2Settings = {}; # The maximum time to wait (in seconds) for a response before closing the connection - decimal timeout = 60; + decimal timeout = 30; # The choice of setting `forwarded`/`x-forwarded` header string forwarded = "disable"; + # Configurations associated with Redirection + http:FollowRedirects followRedirects?; # Configurations associated with request pooling http:PoolConfiguration poolConfig?; # HTTP caching related configurations - http:CacheConfig cache?; + http:CacheConfig cache = {}; # Specifies the way of handling compression (`accept-encoding`) header http:Compression compression = http:COMPRESSION_AUTO; # Configurations associated with the behaviour of the Circuit Breaker http:CircuitBreakerConfig circuitBreaker?; # Configurations associated with retrying http:RetryConfig retryConfig?; + # Configurations associated with cookies + http:CookieConfig cookieConfig?; # Configurations associated with inbound response size limits - http:ResponseLimitConfigs responseLimits?; + http:ResponseLimitConfigs responseLimits = {}; # SSL/TLS-related options http:ClientSecureSocket secureSocket?; # Proxy server related options http:ProxyConfig proxy?; + # Provides settings related to client socket configuration + http:ClientSocketConfig socketConfig = {}; # Enables the inbound payload validation functionality which provided by the constraint package. Enabled by default boolean validation = true; + # Enables relaxed data binding on the client side. When enabled, `nil` values are treated as optional, + # and absent fields are handled as `nilable` types. Enabled by default. + boolean laxDataBinding = true; |}; public type PublicStatusBulkResponse record { @@ -197,19 +206,11 @@ public type PublicSubscriptionTranslation record { int:Signed32 updatedAt; }; -# Represents the Queries record for the operation: getCommunicationPreferencesV4StatusesSubscriberidstring -public type GetCommunicationPreferencesV4StatusesSubscriberidstringQueries record { - # The channel type for the subscription type. Currently, the only supported channel type is `EMAIL`. - "EMAIL"|"WHATSAPP"|"SMS" channel; - # If you have the [business unit add-on](https://developers.hubspot.com/beta-docs/guides/api/settings/business-units-api), include this parameter to filter results by business unit ID. The default Account business unit will always use `0`. - int businessUnitId?; -}; - -# Represents the Queries record for the operation: getCommunicationPreferencesV4Definitions +# Represents the Queries record for the operation: get-/communication-preferences/v4/definitions public type GetCommunicationPreferencesV4DefinitionsQueries record { - # Set to `true` to return subscription translations associated with each definition. + # Set to `true` to return subscription translations associated with each definition boolean includeTranslations?; - # If you have the [business unit add-on](https://developers.hubspot.com/beta-docs/guides/api/settings/business-units-api), include this parameter to filter results by business unit ID. The default Account business unit will always use `0`. + # If you have the [business unit add-on](https://developers.hubspot.com/beta-docs/guides/api/settings/business-units-api), include this parameter to filter results by business unit ID. The default Account business unit will always use `0` int businessUnitId?; }; @@ -233,17 +234,17 @@ public type BatchResponsePublicStatus record { }; public type PublicStatusRequest record { - # The status of the contact's subscription. + # The status of the contact's subscription "SUBSCRIBED"|"UNSUBSCRIBED"|"NOT_SPECIFIED" statusState; - # The type of communication channel. Currently, only `EMAIL` is supported. + # The type of communication channel. Currently, only `EMAIL` is supported "EMAIL"|"WHATSAPP"|"SMS" channel; - # The contact's email address. + # The contact's email address string subscriberIdString; - # The legal basis for communication. + # The legal basis for communication "LEGITIMATE_INTEREST_PQL"|"LEGITIMATE_INTEREST_CLIENT"|"PERFORMANCE_OF_CONTRACT"|"CONSENT_WITH_NOTICE"|"NON_GDPR"|"PROCESS_AND_STORE"|"LEGITIMATE_INTEREST_OTHER" legalBasis?; - # The ID of the subscription to update. + # The ID of the subscription to update int:Signed32 subscriptionId; - # The explanation for the legal basis. + # The explanation for the legal basis string legalBasisExplanation?; }; @@ -252,19 +253,6 @@ public type PublicWideStatusBulkResponse record { string subscriberIdString; }; -# Proxy server configurations to be used with the HTTP client endpoint. -public type ProxyConfig record {| - # Host name of the proxy server - string host = ""; - # Proxy server port - int port = 0; - # Proxy server username - string userName = ""; - # Proxy server password - @display {label: "", kind: "password"} - string password = ""; -|}; - public type ActionResponseWithResultsPublicStatus record { string completedAt; int:Signed32 numErrors?; @@ -276,6 +264,14 @@ public type ActionResponseWithResultsPublicStatus record { "PENDING"|"PROCESSING"|"CANCELED"|"COMPLETE" status; }; +# Represents the Queries record for the operation: get-/communication-preferences/v4/statuses/{subscriberIdString} +public type GetCommunicationPreferencesV4StatusesSubscriberIdStringQueries record { + # The channel type for the subscription type. Currently, the only supported channel type is `EMAIL` + "EMAIL"|"WHATSAPP"|"SMS" channel; + # If you have the [business unit add-on](https://developers.hubspot.com/beta-docs/guides/api/settings/business-units-api), include this parameter to filter results by business unit ID. The default Account business unit will always use `0` + int businessUnitId?; +}; + public type BatchResponsePublicWideStatusBulkResponse record { string completedAt; string requestedAt?; @@ -285,11 +281,11 @@ public type BatchResponsePublicWideStatusBulkResponse record { "PENDING"|"PROCESSING"|"CANCELED"|"COMPLETE" status; }; -# Represents the Queries record for the operation: postCommunicationPreferencesV4StatusesBatchUnsubscribeAllRead +# Represents the Queries record for the operation: post-/communication-preferences/v4/statuses/batch/unsubscribe-all/read public type PostCommunicationPreferencesV4StatusesBatchUnsubscribeAllReadQueries record { - # The channel type for the subscription type. Currently, the only supported channel type is `EMAIL`. + # The channel type for the subscription type. Currently, the only supported channel type is `EMAIL` "EMAIL"|"WHATSAPP"|"SMS" channel; - # If you have the [business unit add-on](https://developers.hubspot.com/beta-docs/guides/api/settings/business-units-api), include this parameter to filter results by business unit ID. The default Account business unit will always use `0`. + # If you have the [business unit add-on](https://developers.hubspot.com/beta-docs/guides/api/settings/business-units-api), include this parameter to filter results by business unit ID. The default Account business unit will always use `0` int businessUnitId?; }; @@ -297,16 +293,6 @@ public type BatchInputPublicStatusRequest record { PublicStatusRequest[] inputs; }; -# Provides settings related to HTTP/1.x protocol. -public type ClientHttp1Settings record {| - # Specifies whether to reuse a connection for multiple requests - http:KeepAlive keepAlive = http:KEEPALIVE_AUTO; - # The chunking behaviour of the request - http:Chunking chunking = http:CHUNKING_AUTO; - # Proxy server related options - ProxyConfig proxy?; -|}; - public type SubscriptionDefinition record { boolean isInternal; string createdAt; @@ -333,29 +319,29 @@ public type BatchResponsePublicWideStatusBulkResponseWithErrors record { "PENDING"|"PROCESSING"|"CANCELED"|"COMPLETE" status; }; -# Represents the Queries record for the operation: postCommunicationPreferencesV4StatusesSubscriberidstringUnsubscribeAll -public type PostCommunicationPreferencesV4StatusesSubscriberidstringUnsubscribeAllQueries record { - # The channel type for the subscription type. Currently, the only supported channel type is `EMAIL`. +# Provides API key configurations needed when communicating with a remote HTTP endpoint. +public type ApiKeysConfig record {| + string privateAppLegacy; + string privateApp; +|}; + +# Represents the Queries record for the operation: get-/communication-preferences/v4/statuses/{subscriberIdString}/unsubscribe-all +public type GetCommunicationPreferencesV4StatusesSubscriberIdStringUnsubscribeAllQueries record { + # The channel type for the subscription type. Currently, the only supported channel type is `EMAIL` "EMAIL"|"WHATSAPP"|"SMS" channel; - # If you have the [business unit add-on](https://developers.hubspot.com/beta-docs/guides/api/settings/business-units-api), include this parameter to filter results by business unit ID. The default Account business unit will always use `0`. + # If you have the [business unit add-on](https://developers.hubspot.com/beta-docs/guides/api/settings/business-units-api), include this parameter to filter results by business unit ID. The default Account business unit will always use `0` int businessUnitId?; - # Set to `true` to include the details of the updated subscription statuses in the response. Not including this parameter will result in an empty response. + # Set to `true` to include the details of the updated subscription statuses in the response. Not including this parameter will result in an empty response boolean verbose = false; }; -# Provides API key configurations needed when communicating with a remote HTTP endpoint. -public type ApiKeysConfig record {| - string private\-app\-legacy; - string private\-app; -|}; - -# Represents the Queries record for the operation: postCommunicationPreferencesV4StatusesBatchUnsubscribeAll +# Represents the Queries record for the operation: post-/communication-preferences/v4/statuses/batch/unsubscribe-all public type PostCommunicationPreferencesV4StatusesBatchUnsubscribeAllQueries record { - # The channel type for the subscription type. Currently, the only supported channel type is `EMAIL`. + # The channel type for the subscription type. Currently, the only supported channel type is `EMAIL` "EMAIL"|"WHATSAPP"|"SMS" channel; - # If you have the [business unit add-on](https://developers.hubspot.com/beta-docs/guides/api/settings/business-units-api), include this parameter to filter results by business unit ID. The default Account business unit will always use `0`. + # If you have the [business unit add-on](https://developers.hubspot.com/beta-docs/guides/api/settings/business-units-api), include this parameter to filter results by business unit ID. The default Account business unit will always use `0` int businessUnitId?; - # Set to `true` to include the details of the updated subscription statuses in the response. Not including this parameter will result in an empty response. + # Set to `true` to include the details of the updated subscription statuses in the response. Not including this parameter will result in an empty response boolean verbose = false; }; diff --git a/ballerina/utils.bal b/ballerina/utils.bal index 13d33ab..3cbf6df 100644 --- a/ballerina/utils.bal +++ b/ballerina/utils.bal @@ -17,6 +17,7 @@ // specific language governing permissions and limitations // under the License. +import ballerina/http; import ballerina/url; type SimpleBasicType string|boolean|int|float|decimal; @@ -186,12 +187,13 @@ isolated function getEncodedUri(anydata value) returns string { # + encodingMap - Details on serialization mechanism # + return - Returns generated Path or error at failure of client initialization isolated function getPathForQueryParam(map queryParam, map encodingMap = {}) returns string|error { + map queriesMap = http:getQueryMap(queryParam); string[] param = []; - if queryParam.length() > 0 { + if queriesMap.length() > 0 { param.push("?"); - foreach var [key, value] in queryParam.entries() { + foreach var [key, value] in queriesMap.entries() { if value is () { - _ = queryParam.remove(key); + _ = queriesMap.remove(key); continue; } Encoding encodingData = encodingMap.hasKey(key) ? encodingMap.get(key) : defaultEncoding; @@ -215,20 +217,3 @@ isolated function getPathForQueryParam(map queryParam, map en string restOfPath = string:'join("", ...param); return restOfPath; } - -# Generate header map for given header values. -# -# + headerParam - Headers map -# + return - Returns generated map or error at failure of client initialization -isolated function getMapForHeaders(map headerParam) returns map { - map headerMap = {}; - foreach var [key, value] in headerParam.entries() { - if value is SimpleBasicType[] { - headerMap[key] = from SimpleBasicType data in value - select data.toString(); - } else { - headerMap[key] = value.toString(); - } - } - return headerMap; -} diff --git a/gradle.properties b/gradle.properties index 985fff3..0c24942 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,4 +4,4 @@ version=1.0.1-SNAPSHOT releasePluginVersion=2.8.0 ballerinaGradlePluginVersion=2.2.4 -ballerinaLangVersion=2201.10.0 +ballerinaLangVersion=2201.12.2