diff --git a/src/main/kotlin/Novu.kt b/src/main/kotlin/Novu.kt index aef6e0f..bd2210d 100644 --- a/src/main/kotlin/Novu.kt +++ b/src/main/kotlin/Novu.kt @@ -22,6 +22,12 @@ import co.novu.api.WorkflowsApi import co.novu.helpers.RetrofitHelper import okhttp3.logging.HttpLoggingInterceptor +/** + * A set of configurations used to construct Novu, these configurations ultimately control the way the SDK behaves. + * + * @author Shivam Shah link + * @author Joseph Olugbohunmi link + */ data class NovuConfig( var apiKey: String = "", var backendUrl: String = "https://api.novu.co/v1/", @@ -31,6 +37,27 @@ data class NovuConfig( var apiLogLevel: HttpLoggingInterceptor.Level = HttpLoggingInterceptor.Level.BASIC, ) +/** + * Main entry point for initialising and accessing the functionalities provided in the SDK. + * This class provides two constructors. It can be constructed either by providing an API key + * (gotten from [the web portal](https://web.novu.co/settings)) or by providing + * an instance of [NovuConfig]. + * + * For example: + * + * ``` + * // Using an API key only + * val novu = Novu("apiKey") + * + * + * // Using NovuConfig + * val novuConfig = NovuConfig("apiKey") + * val novu = Novu(novuConfig) + * ``` + * + * @author Shivam Shah link + * @author Joseph Olugbohunmi link + */ class Novu( val config: NovuConfig, ) { diff --git a/src/main/kotlin/dto/response/TriggerResponse.kt b/src/main/kotlin/dto/response/TriggerResponse.kt index 24cb6c9..ef8c7a0 100644 --- a/src/main/kotlin/dto/response/TriggerResponse.kt +++ b/src/main/kotlin/dto/response/TriggerResponse.kt @@ -4,5 +4,5 @@ data class TriggerResponse( var acknowledged: Boolean? = null, var status: String? = null, var transactionId: String? = null, - var error: List? = null, + var error: List? = null, ) diff --git a/src/main/kotlin/extensions/BlueprintsExtensions.kt b/src/main/kotlin/extensions/BlueprintsExtensions.kt index f8f1a5d..d766ae6 100644 --- a/src/main/kotlin/extensions/BlueprintsExtensions.kt +++ b/src/main/kotlin/extensions/BlueprintsExtensions.kt @@ -9,11 +9,22 @@ import mu.KotlinLogging private val logger = KotlinLogging.logger {} +/** + * Retrieve a list of Blueprints grouped by Category. + * @return [ResponseWrapper] with [BlueprintsResponse] as the response data + * @throws [Exception] if a problem occurred talking to the server or if there is a connection error + */ suspend fun Novu.getBlueprintsByCategory(): ResponseWrapper? { val response = blueprintsApi.getBlueprintsByCategory() return response.extractResponse(logger, config.enableLogging) } +/** + * Retrieve a Blueprint. + * @param templateId the ID of a Template + * @return [Blueprint] + * @throws [Exception] if a problem occurred talking to the server or if there is a connection error + */ suspend fun Novu.getBlueprint(templateId: String): Blueprint? { val response = blueprintsApi.getBlueprint(templateId) return response.extractResponse(logger, config.enableLogging) diff --git a/src/main/kotlin/extensions/ChangesExtentions.kt b/src/main/kotlin/extensions/ChangesExtentions.kt index 8abda47..51da726 100644 --- a/src/main/kotlin/extensions/ChangesExtentions.kt +++ b/src/main/kotlin/extensions/ChangesExtentions.kt @@ -11,6 +11,14 @@ import java.math.BigInteger private val logger = KotlinLogging.logger {} +/** + * Retrieve a list of Changes. This function supports pagination. + * @param page the page number to be retrieved + * @param limit the size of the page to be retrieved + * @param promoted the state of the Changes to be retrieved + * @return [PaginatedResponseWrapper] with a list of [ChangesResponse] as the response data + * @throws [Exception] if a problem occurred talking to the server or if there is a connection error + */ suspend fun Novu.changes( page: BigInteger? = null, limit: BigInteger? = null, @@ -20,16 +28,33 @@ suspend fun Novu.changes( return response.extractResponse(logger, config.enableLogging) } +/** + * Retrieve the count of all available Changes. + * @return [ResponseWrapper] with [BigInteger] as the response data + * @throws [Exception] if a problem occurred talking to the server or if there is a connection error + */ suspend fun Novu.changesCount(): ResponseWrapper? { val response = changesApi.getChangesCount() return response.extractResponse(logger, config.enableLogging) } +/** + * Apply a list of Changes. + * @param request an instance of [ChangesRequest] + * @return [ResponseWrapper] with a list of [ChangesResponse] as the response data + * @throws [Exception] if a problem occurred talking to the server or if there is a connection error + */ suspend fun Novu.applyBulkChanges(request: ChangesRequest): ResponseWrapper>? { val response = changesApi.applyBulkChanges(request) return response.extractResponse(logger, config.enableLogging) } +/** + * Apply a particular Change. + * @param changeId the ID of the Change to be applied + * @return [ResponseWrapper] with a list of [ChangesResponse] as the response data + * @throws [Exception] if a problem occurred talking to the server or if there is a connection error + */ suspend fun Novu.applyChange(changeId: String): ResponseWrapper>? { val response = changesApi.applyChange(changedId = changeId) return response.extractResponse(logger, config.enableLogging) diff --git a/src/main/kotlin/extensions/EnvironmentsExtentions.kt b/src/main/kotlin/extensions/EnvironmentsExtentions.kt index 5d81aec..3ac0cb5 100644 --- a/src/main/kotlin/extensions/EnvironmentsExtentions.kt +++ b/src/main/kotlin/extensions/EnvironmentsExtentions.kt @@ -12,21 +12,44 @@ import mu.KotlinLogging private val logger = KotlinLogging.logger {} +/** + * Retrieve the data of the current Environment. + * @return [ResponseWrapper] with [GetEnvironmentResponse] as the response data + * @throws [Exception] if a problem occurred talking to the server or if there is a connection error + */ suspend fun Novu.currentEnvironment(): ResponseWrapper? { val response = environmentsApi.getCurrentEnvironment() return response.extractResponse(logger, config.enableLogging) } +/** + * Create an Environment. + * @param request an instance of [CreateEnvironmentRequest] + * @return [ResponseWrapper] with [GetEnvironmentResponse] as the response data + * @throws [Exception] if a problem occurred talking to the server or if there is a connection error + */ suspend fun Novu.createEnvironment(request: CreateEnvironmentRequest): ResponseWrapper? { val response = environmentsApi.createEnvironment(request) return response.extractResponse(logger, config.enableLogging) } +/** + * Retrieve a list of Environments. + * @return [ResponseWrapper] with a list of [GetEnvironmentResponse] as the response data + * @throws [Exception] if a problem occurred talking to the server or if there is a connection error + */ suspend fun Novu.environments(): ResponseWrapper>? { val response = environmentsApi.getEnvironments() return response.extractResponse(logger, config.enableLogging) } +/** + * Update an Environment. + * @param environmentId the ID of the Environment to be updated + * @param request an instance of [UpdateEnvironmentRequest] + * @return [ResponseWrapper] with [GetEnvironmentResponse] as the response data + * @throws [Exception] if a problem occurred talking to the server or if there is a connection error + */ suspend fun Novu.updateEnvironment( environmentId: String, request: UpdateEnvironmentRequest, @@ -35,11 +58,21 @@ suspend fun Novu.updateEnvironment( return response.extractResponse(logger, config.enableLogging) } +/** + * Retrieve a list of API Keys. + * @return [ResponseWrapper] with a list of [ApiKeys] as the response data + * @throws [Exception] if a problem occurred talking to the server or if there is a connection error + */ suspend fun Novu.apiKeys(): ResponseWrapper>? { val response = environmentsApi.getApiKeys() return response.extractResponse(logger, config.enableLogging) } +/** + * Regenerate API Keys. + * @return [ResponseWrapper] with a list of [ApiKeys] as the response data + * @throws [Exception] if a problem occurred talking to the server or if there is a connection error + */ suspend fun Novu.regenrateApiKey(): ResponseWrapper>? { val response = environmentsApi.regenerateApiKey() return response.extractResponse(logger, config.enableLogging) diff --git a/src/main/kotlin/extensions/EventsExtensions.kt b/src/main/kotlin/extensions/EventsExtensions.kt index 78f45b3..8220b84 100644 --- a/src/main/kotlin/extensions/EventsExtensions.kt +++ b/src/main/kotlin/extensions/EventsExtensions.kt @@ -11,21 +11,45 @@ import mu.KotlinLogging private val logger = KotlinLogging.logger {} +/** + * Trigger an event such as sending notification to subscribers. + * @param body an instance of [TriggerEventRequest] + * @return [ResponseWrapper] with [TriggerResponse] as the response data + * @throws [Exception] if a problem occurred talking to the server or if there is a connection error + */ suspend fun Novu.trigger(body: TriggerEventRequest): ResponseWrapper? { val response = eventsApi.triggerEvent(body) return response.extractResponse(logger, config.enableLogging) } +/** + * Trigger multiple events in a single transaction. + * @param body an instance of [BulkTriggerEventRequest] + * @return [ResponseWrapper] with a list of [TriggerResponse] as the response data + * @throws [Exception] if a problem occurred talking to the server or if there is a connection error + */ suspend fun Novu.bulkTrigger(body: BulkTriggerEventRequest): ResponseWrapper>? { val response = eventsApi.bulkTriggerEvent(body) return response.extractResponse(logger, config.enableLogging) } +/** + * Broadcast an event to all existing subscribers. + * @param body an instance of [BroadcastEventRequest] + * @return [ResponseWrapper] with [TriggerResponse] as the response data + * @throws [Exception] if a problem occurred talking to the server or if there is a connection error + */ suspend fun Novu.broadcast(body: BroadcastEventRequest): ResponseWrapper? { val response = eventsApi.broadcastEvent(body) return response.extractResponse(logger, config.enableLogging) } +/** + * Cancel a running event. + * @param transactionId the transaction ID of the running event + * @return [ResponseWrapper] with [Boolean] as the response data + * @throws [Exception] if a problem occurred talking to the server or if there is a connection error + */ suspend fun Novu.cancelTriggerEvent(transactionId: String): ResponseWrapper? { val response = eventsApi.cancelTriggerEvent(transactionId) return response.extractResponse(logger, config.enableLogging) diff --git a/src/main/kotlin/extensions/ExecutionDetailsExtentions.kt b/src/main/kotlin/extensions/ExecutionDetailsExtentions.kt index d5f05e9..dde427d 100644 --- a/src/main/kotlin/extensions/ExecutionDetailsExtentions.kt +++ b/src/main/kotlin/extensions/ExecutionDetailsExtentions.kt @@ -8,6 +8,13 @@ import mu.KotlinLogging private val logger = KotlinLogging.logger {} +/** + * Retrieve a list of Execution Details. + * @param notificationId the ID of a Notification + * @param subscriberId the ID of a Subscriber + * @return [ResponseWrapper] with a list of [ExecutionDetails] as the response data + * @throws [Exception] if a problem occurred talking to the server or if there is a connection error + */ suspend fun Novu.executionDetails( notificationId: String, subscriberId: String, diff --git a/src/main/kotlin/extensions/FeedsExtentions.kt b/src/main/kotlin/extensions/FeedsExtentions.kt index db95963..9437332 100644 --- a/src/main/kotlin/extensions/FeedsExtentions.kt +++ b/src/main/kotlin/extensions/FeedsExtentions.kt @@ -9,16 +9,33 @@ import mu.KotlinLogging private val logger = KotlinLogging.logger {} +/** + * Create a Feed. + * @param body an instance of [CreateByNameRequest] + * @return [ResponseWrapper] with [FeedResponse] as the response data + * @throws [Exception] if a problem occurred talking to the server or if there is a connection error + */ suspend fun Novu.createFeed(body: CreateByNameRequest): ResponseWrapper? { val response = feedsApi.createFeed(body) return response.extractResponse(logger, config.enableLogging) } +/** + * Retrieve a list of Feeds. + * @return [ResponseWrapper] with a list of [FeedResponse] as the response data + * @throws [Exception] if a problem occurred talking to the server or if there is a connection error + */ suspend fun Novu.feeds(): ResponseWrapper>? { val response = feedsApi.getFeeds() return response.extractResponse(logger, config.enableLogging) } +/** + * Delete a Feed. + * @param feedId the ID of the Feed to be deleted + * @return [ResponseWrapper] with [FeedResponse] as the response data + * @throws [Exception] if a problem occurred talking to the server or if there is a connection error + */ suspend fun Novu.deleteFeed(feedId: String): ResponseWrapper? { val response = feedsApi.deleteFeed(feedId) return response.extractResponse(logger, config.enableLogging) diff --git a/src/main/kotlin/extensions/InboundParseExtentions.kt b/src/main/kotlin/extensions/InboundParseExtentions.kt index 38905ac..a9e0e32 100644 --- a/src/main/kotlin/extensions/InboundParseExtentions.kt +++ b/src/main/kotlin/extensions/InboundParseExtentions.kt @@ -7,6 +7,11 @@ import mu.KotlinLogging private val logger = KotlinLogging.logger {} +/** + * Validate the mx record setup for the inbound parse functionality. + * @return [ValidateMxRecordSetupForInboundParseResponse] + * @throws [Exception] if a problem occurred talking to the server or if there is a connection error + */ suspend fun Novu.validateMxRecordSetupForInboundParse(): ValidateMxRecordSetupForInboundParseResponse? { val response = inboundParseApi.validateMxRecordSetupForInboundParse() return response.extractResponse(logger, config.enableLogging) diff --git a/src/main/kotlin/extensions/IntegrationsExtentions.kt b/src/main/kotlin/extensions/IntegrationsExtentions.kt index ec15eeb..d6d994f 100644 --- a/src/main/kotlin/extensions/IntegrationsExtentions.kt +++ b/src/main/kotlin/extensions/IntegrationsExtentions.kt @@ -9,26 +9,55 @@ import mu.KotlinLogging private val logger = KotlinLogging.logger {} +/** + * Retrieve a list of Integrations associated with the API key provided. + * @return [ResponseWrapper] with a list of [IntegrationResponse] as the response data + * @throws [Exception] if a problem occurred talking to the server or if there is a connection error + */ suspend fun Novu.integrations(): ResponseWrapper>? { val response = integrationsApi.getIntegrations() return response.extractResponse(logger, config.enableLogging) } +/** + * Create an Integration. + * @param request an instance of [IntegrationRequest] + * @return [ResponseWrapper] with [IntegrationResponse] as the response data + * @throws [Exception] if a problem occurred talking to the server or if there is a connection error + */ suspend fun Novu.createIntegration(request: IntegrationRequest): ResponseWrapper? { val response = integrationsApi.createIntegration(request) return response.extractResponse(logger, config.enableLogging) } +/** + * Retrieve a list of active Integrations associated with the API key provided. + * @return [ResponseWrapper] with a list of [IntegrationResponse] as the response data + * @throws [Exception] if a problem occurred talking to the server or if there is a connection error + */ suspend fun Novu.activeIntegrations(): ResponseWrapper>? { val response = integrationsApi.getActiveIntegrations() return response.extractResponse(logger, config.enableLogging) } +/** + * Retrieve the status of a Provider's Webhook. + * @param providerId the ID of the Provider whose status is to be retrieved + * @return [ResponseWrapper] with a list of [IntegrationResponse] as the response data + * @throws [Exception] if a problem occurred talking to the server or if there is a connection error + */ suspend fun Novu.providerWebhook(providerId: String): ResponseWrapper? { val response = integrationsApi.getProviderWebhook(providerId) return response.extractResponse(logger, config.enableLogging) } +/** + * Update an Integration. + * @param integrationId the ID of the Integration to be updated + * @param request an instance of [IntegrationRequest] + * @return [ResponseWrapper] with [IntegrationResponse] as the response data + * @throws [Exception] if a problem occurred talking to the server or if there is a connection error + */ suspend fun Novu.updateIntegration( integrationId: String, request: IntegrationRequest, @@ -37,11 +66,23 @@ suspend fun Novu.updateIntegration( return response.extractResponse(logger, config.enableLogging) } +/** + * Delete an Integration. + * @param integrationId the ID of the Integration to be deleted + * @return [ResponseWrapper] with a list of [IntegrationResponse] as the response data + * @throws [Exception] if a problem occurred talking to the server or if there is a connection error + */ suspend fun Novu.deleteIntegration(integrationId: String): ResponseWrapper>? { val response = integrationsApi.deleteIntegration(integrationId) return response.extractResponse(logger, config.enableLogging) } +/** + * Set a particular Integration as the primary Integration. + * @param integrationId the ID of the Integration to be set as primary + * @return [ResponseWrapper] with a list of [IntegrationResponse] as the response data + * @throws [Exception] if a problem occurred talking to the server or if there is a connection error + */ suspend fun Novu.setIntegrationAsPrimary(integrationId: String): ResponseWrapper? { val response = integrationsApi.setPrimaryIntegration(integrationId) return response.extractResponse(logger, config.enableLogging) diff --git a/src/main/kotlin/extensions/LayoutsExtentions.kt b/src/main/kotlin/extensions/LayoutsExtentions.kt index 0502413..6f7f8e5 100644 --- a/src/main/kotlin/extensions/LayoutsExtentions.kt +++ b/src/main/kotlin/extensions/LayoutsExtentions.kt @@ -14,6 +14,15 @@ import java.math.BigInteger private val logger = KotlinLogging.logger {} +/** + * Retrieve a list of Layouts. This function supports pagination. + * @param page the page number to be retrieved + * @param pageSize the size of the page to be retrieved + * @param orderBy direction of the sorting query param. Either ascending (1) or descending (-1) + * @param sortBy sort field. Currently only supports **createdAt** + * @return [PaginatedResponseWrapper] with a list of [GetLayoutsResponse] as the response data + * @throws [Exception] if a problem occurred talking to the server or if there is a connection error + */ suspend fun Novu.filterLayouts( page: BigInteger, pageSize: BigInteger, @@ -24,21 +33,46 @@ suspend fun Novu.filterLayouts( return response.extractResponse(logger, config.enableLogging) } +/** + * Create a Layout. + * @param request an instance of [CreateLayoutRequest] + * @return [ResponseWrapper] with [CreateLayoutResponse] as the response data + * @throws [Exception] if a problem occurred talking to the server or if there is a connection error + */ suspend fun Novu.createLayout(request: CreateLayoutRequest): ResponseWrapper? { val response = layoutsApi.createLayout(request) return response.extractResponse(logger, config.enableLogging) } +/** + * Retrieve a Layout. + * @param layoutId the ID of the Layout to be retrieved + * @return [ResponseWrapper] with [GetLayoutsResponse] as the response data + * @throws [Exception] if a problem occurred talking to the server or if there is a connection error + */ suspend fun Novu.layout(layoutId: String): ResponseWrapper? { val response = layoutsApi.getLayout(layoutId) return response.extractResponse(logger, config.enableLogging) } +/** + * Delete a Layout. + * @param layoutId the ID of the Layout to be deleted + * @return [DeleteLayoutResponse] + * @throws [Exception] if a problem occurred talking to the server or if there is a connection error + */ suspend fun Novu.deleteLayout(layoutId: String): DeleteLayoutResponse { val response = layoutsApi.deleteLayout(layoutId) return response.extractResponse(logger, config.enableLogging, DeleteLayoutResponse()) } +/** + * Update a Layout. + * @param layoutId the ID of the Layout to be updated + * @param request an instance of [CreateLayoutRequest] + * @return [ResponseWrapper] with [GetLayoutsResponse] as the response data + * @throws [Exception] if a problem occurred talking to the server or if there is a connection error + */ suspend fun Novu.updateLayout( layoutId: String, request: CreateLayoutRequest, @@ -47,6 +81,12 @@ suspend fun Novu.updateLayout( return response.extractResponse(logger, config.enableLogging) } +/** + * Set a Layout as the default Layout. + * @param layoutId the ID of the Layout to be set as default + * @return [SetDefaultLayoutResponse] + * @throws [Exception] if a problem occurred talking to the server or if there is a connection error + */ suspend fun Novu.setDefaultLayout(layoutId: String): SetDefaultLayoutResponse { val response = layoutsApi.setDefaultLayout(layoutId) return response.extractResponse(logger, config.enableLogging, SetDefaultLayoutResponse()) diff --git a/src/main/kotlin/extensions/MessagesExtentions.kt b/src/main/kotlin/extensions/MessagesExtentions.kt index 422daba..a312091 100644 --- a/src/main/kotlin/extensions/MessagesExtentions.kt +++ b/src/main/kotlin/extensions/MessagesExtentions.kt @@ -11,6 +11,16 @@ import java.math.BigInteger private val logger = KotlinLogging.logger {} +/** + * Retrieve a list of Messages. This function supports pagination. + * @param channel the channel of the Messages to be retrieved + * @param subscriberId the ID of the Subscriber who owns the Messages + * @param limit the size of the page to be retrieved + * @param page the page number to be retrieved + * @param transactionId the transaction ID of the Messages to be retrieved + * @return [PaginatedResponseWrapper] with a list of [Message] as the response data + * @throws [Exception] if a problem occurred talking to the server or if there is a connection error + */ suspend fun Novu.messages( channel: String? = null, subscriberId: String? = null, @@ -22,6 +32,12 @@ suspend fun Novu.messages( return response.extractResponse(logger, config.enableLogging) } +/** + * Delete a Message. + * @param messageId the ID of the Message to be deleted + * @return [ResponseWrapper] with [TriggerResponse] as the response data + * @throws [Exception] if a problem occurred talking to the server or if there is a connection error + */ suspend fun Novu.deleteMessage(messageId: String): ResponseWrapper? { val response = messagesApi.deleteMessage(messageId) return response.extractResponse(logger, config.enableLogging) diff --git a/src/main/kotlin/extensions/NotificationGroupsExtentions.kt b/src/main/kotlin/extensions/NotificationGroupsExtentions.kt index e95ad33..96de810 100644 --- a/src/main/kotlin/extensions/NotificationGroupsExtentions.kt +++ b/src/main/kotlin/extensions/NotificationGroupsExtentions.kt @@ -10,21 +10,45 @@ import mu.KotlinLogging private val logger = KotlinLogging.logger {} +/** + * Retrieve a list of NotificationGroups. + * @return [ResponseWrapper] with a list of [NotificationGroupsResponse] as the response data + * @throws [Exception] if a problem occurred talking to the server or if there is a connection error + */ suspend fun Novu.getWorkflowGroups(): ResponseWrapper>? { val response = notificationGroupsApi.getNotificationGroups() return response.extractResponse(logger, config.enableLogging) } +/** + * Create a NotificationGroup. + * @param request an instance of [CreateByNameRequest] + * @return [ResponseWrapper] with [NotificationGroupsResponse] as the response data + * @throws [Exception] if a problem occurred talking to the server or if there is a connection error + */ suspend fun Novu.createWorkflowGroup(request: CreateByNameRequest): ResponseWrapper? { val response = notificationGroupsApi.createNotificationGroup(request) return response.extractResponse(logger, config.enableLogging) } +/** + * Retrieve a NotificationGroup. + * @param id the ID of the NotificationGroup to be retrieved + * @return [ResponseWrapper] with [NotificationGroupsResponse] as the response data + * @throws [Exception] if a problem occurred talking to the server or if there is a connection error + */ suspend fun Novu.getWorkflowGroup(id: String): ResponseWrapper? { val response = notificationGroupsApi.getWorkflowGroup(id) return response.extractResponse(logger, config.enableLogging) } +/** + * Update a NotificationGroup. + * @param id the ID of the NotificationGroup to be updated + * @param request an instance of [CreateByNameRequest] + * @return [ResponseWrapper] with [NotificationGroupsResponse] as the response data + * @throws [Exception] if a problem occurred talking to the server or if there is a connection error + */ suspend fun Novu.updateWorkflowGroup( id: String, request: CreateByNameRequest, @@ -33,6 +57,12 @@ suspend fun Novu.updateWorkflowGroup( return response.extractResponse(logger, config.enableLogging) } +/** + * Delete a NotificationGroup. + * @param id the ID of the NotificationGroup to be deleted + * @return [ResponseWrapper] with [DeleteWorkflowGroupResponse] as the response data + * @throws [Exception] if a problem occurred talking to the server or if there is a connection error + */ suspend fun Novu.deleteWorkflowGroup(id: String): ResponseWrapper? { val response = notificationGroupsApi.deleteWorkflowGroup(id) return response.extractResponse(logger, config.enableLogging) diff --git a/src/main/kotlin/extensions/NotificationsExtentions.kt b/src/main/kotlin/extensions/NotificationsExtentions.kt index 5914b41..874096f 100644 --- a/src/main/kotlin/extensions/NotificationsExtentions.kt +++ b/src/main/kotlin/extensions/NotificationsExtentions.kt @@ -12,6 +12,12 @@ import mu.KotlinLogging private val logger = KotlinLogging.logger {} +/** + * Retrieve all Notifications ever sent with the API key provided. This function supports pagination. + * @param notificationRequest an instance of [NotificationRequest] + * @return [PaginatedResponseWrapper] with a list of [Notification] as the response data + * @throws [Exception] if a problem occurred talking to the server or if there is a connection error + */ suspend fun Novu.notifications(notificationRequest: NotificationRequest): PaginatedResponseWrapper? { val response = notificationsApi.getNotifications( @@ -25,16 +31,32 @@ suspend fun Novu.notifications(notificationRequest: NotificationRequest): Pagina return response.extractResponse(logger, config.enableLogging) } +/** + * Retrieve the statistics of all Notifications ever sent with the API key provided. + * @return [ResponseWrapper] with [NotificationStatsResponse] as the response data + * @throws [Exception] if a problem occurred talking to the server or if there is a connection error + */ suspend fun Novu.notificationsStats(): ResponseWrapper? { val response = notificationsApi.getNotificationsStats() return response.extractResponse(logger, config.enableLogging) } +/** + * Retrieve the statistics of Notifications graph associated with the API key provided. + * @return [ResponseWrapper] with a list of [NotificationGraphStatsResponse] as the response data + * @throws [Exception] if a problem occurred talking to the server or if there is a connection error + */ suspend fun Novu.notificationGraphStats(): ResponseWrapper>? { val response = notificationsApi.getNotificationGraphStats() return response.extractResponse(logger, config.enableLogging) } +/** + * Retrieve a Notification. + * @param notificationId the ID of the Notification to be retrieved + * @return [ResponseWrapper] with [Notification] as the response data + * @throws [Exception] if a problem occurred talking to the server or if there is a connection error + */ suspend fun Novu.notification(notificationId: String): ResponseWrapper? { val response = notificationsApi.getNotification(notificationId) return response.extractResponse(logger, config.enableLogging) diff --git a/src/main/kotlin/extensions/OrganizationsExtensions.kt b/src/main/kotlin/extensions/OrganizationsExtensions.kt index 649f4bb..188e2ba 100644 --- a/src/main/kotlin/extensions/OrganizationsExtensions.kt +++ b/src/main/kotlin/extensions/OrganizationsExtensions.kt @@ -15,31 +15,66 @@ import mu.KotlinLogging private val logger = KotlinLogging.logger {} +/** + * Create an Organization. + * @param request an instance of [CreateOrganizationRequest] + * @return [ResponseWrapper] with [OrganizationResponse] as the response data + * @throws [Exception] if a problem occurred talking to the server or if there is a connection error + */ suspend fun Novu.createOrganization(request: CreateOrganizationRequest): ResponseWrapper? { val response = organizationsApi.createOrganization(request) return response.extractResponse(logger, config.enableLogging) } +/** + * Retrieve a list of all Organizations. + * @return [ResponseWrapper] with a list of [OrganizationResponse] as the response data + * @throws [Exception] if a problem occurred talking to the server or if there is a connection error + */ suspend fun Novu.fetchAllOrganizations(): ResponseWrapper>? { val response = organizationsApi.fetchAllOrganizations() return response.extractResponse(logger, config.enableLogging) } +/** + * Update the name of an Organization. + * @param request an instance of [UpdateOrganizationNameRequest] + * @return [ResponseWrapper] with [UpdateOrganizationNameResponse] as the response data + * @throws [Exception] if a problem occurred talking to the server or if there is a connection error + */ suspend fun Novu.updateOrganizationName(request: UpdateOrganizationNameRequest): ResponseWrapper? { val response = organizationsApi.updateOrganizationName(request) return response.extractResponse(logger, config.enableLogging) } +/** + * Retrieve the data of the current Organization. + * @return [ResponseWrapper] with [OrganizationResponse] as the response data + * @throws [Exception] if a problem occurred talking to the server or if there is a connection error + */ suspend fun Novu.fetchCurrentOrganization(): ResponseWrapper? { val response = organizationsApi.fetchCurrentOrganization() return response.extractResponse(logger, config.enableLogging) } +/** + * Remove a Member from the current Organization. + * @param memberId the ID of the Member to be removed + * @return [ResponseWrapper] with [MemberResponse] as the response data + * @throws [Exception] if a problem occurred talking to the server or if there is a connection error + */ suspend fun Novu.removeMemberWithId(memberId: String): ResponseWrapper? { val response = organizationsApi.removeMemberWithId(memberId) return response.extractResponse(logger, config.enableLogging) } +/** + * Update a Member's role in the current Organization. + * @param memberId the ID of the Member to be updated + * @param request an instance of [UpdateMemberRoleRequest] + * @return [ResponseWrapper] with [MemberResponse] as the response data + * @throws [Exception] if a problem occurred talking to the server or if there is a connection error + */ suspend fun Novu.updateMemberRole( memberId: String, request: UpdateMemberRoleRequest, @@ -48,11 +83,22 @@ suspend fun Novu.updateMemberRole( return response.extractResponse(logger, config.enableLogging) } +/** + * Retrieve a list of all Members in the current Organizations. + * @return [ResponseWrapper] with a list of [MemberResponse] as the response data + * @throws [Exception] if a problem occurred talking to the server or if there is a connection error + */ suspend fun Novu.fetchMembersOfOrganization(): ResponseWrapper>? { val response = organizationsApi.fetchMembersOfOrganization() return response.extractResponse(logger, config.enableLogging) } +/** + * Update the brand of the current Organization. + * @param request an instance of [UpdateOrganizationBrandRequest] + * @return [ResponseWrapper] with [Branding] as the response data + * @throws [Exception] if a problem occurred talking to the server or if there is a connection error + */ suspend fun Novu.updateOrganizationBrand(request: UpdateOrganizationBrandRequest): ResponseWrapper? { val response = organizationsApi.updateOrganizationBrand(request) return response.extractResponse(logger, config.enableLogging) diff --git a/src/main/kotlin/extensions/SubscriberExtensions.kt b/src/main/kotlin/extensions/SubscriberExtensions.kt index 5c9b041..44be246 100644 --- a/src/main/kotlin/extensions/SubscriberExtensions.kt +++ b/src/main/kotlin/extensions/SubscriberExtensions.kt @@ -23,26 +23,57 @@ import java.math.BigInteger private val logger = KotlinLogging.logger {} +/** + * Retrieve all Subscribers associated with the API key provided. This function supports pagination. + * @param page the page number to be retrieved + * @return [PaginatedResponseWrapper] with a list of [SubscriberResponse] as the response data + * @throws [Exception] if a problem occurred talking to the server or if there is a connection error + */ suspend fun Novu.subscribers(page: BigInteger? = null): PaginatedResponseWrapper? { val response = subscribersApi.getSubscribers(page) return response.extractResponse(logger, config.enableLogging) } +/** + * Create a Subscriber. + * @param subscriberRequest an instance of [SubscriberRequest] + * @return [ResponseWrapper] with [SubscriberResponse] as the response data + * @throws [Exception] if a problem occurred talking to the server or if there is a connection error + */ suspend fun Novu.createSubscriber(subscriberRequest: SubscriberRequest): ResponseWrapper? { val response = subscribersApi.createSubscriber(subscriberRequest) return response.extractResponse(logger, config.enableLogging) } +/** + * Create multiple Subscribers in a single transaction. + * @param request an instance of [BulkSubscriberRequest] + * @return [CreateBulkSubscriberResponse] + * @throws [Exception] if a problem occurred talking to the server or if there is a connection error + */ suspend fun Novu.createSubscriberBulk(request: BulkSubscriberRequest): CreateBulkSubscriberResponse? { val response = subscribersApi.createSubscriberBulk(request) return response.extractResponse(logger, config.enableLogging) } +/** + * Retrieve a Subscriber. + * @param subscriberId the ID of the Subscriber to be retrieved + * @return [ResponseWrapper] with [SubscriberResponse] as the response data + * @throws [Exception] if a problem occurred talking to the server or if there is a connection error + */ suspend fun Novu.subscriber(subscriberId: String): ResponseWrapper? { val response = subscribersApi.getSubscriber(subscriberId) return response.extractResponse(logger, config.enableLogging) } +/** + * Update a Subscriber. + * @param subscriberId the ID of the Subscriber to be updated + * @param request an instance of [UpdateSubscriberRequest] + * @return [ResponseWrapper] with [SubscriberResponse] as the response data + * @throws [Exception] if a problem occurred talking to the server or if there is a connection error + */ suspend fun Novu.updateSubscriber( subscriberId: String, request: UpdateSubscriberRequest, @@ -51,11 +82,24 @@ suspend fun Novu.updateSubscriber( return response.extractResponse(logger, config.enableLogging) } +/** + * Delete a Subscriber. + * @param subscriberId the ID of the Subscriber to be deleted + * @return [ResponseWrapper] with [SubscriberDeleteResponse] as the response data + * @throws [Exception] if a problem occurred talking to the server or if there is a connection error + */ suspend fun Novu.deleteSubscriber(subscriberId: String): ResponseWrapper? { val response = subscribersApi.deleteSubscriber(subscriberId) return response.extractResponse(logger, config.enableLogging) } +/** + * Update a Subscriber's credentials. + * @param subscriberId the ID of the Subscriber to be updated + * @param request an instance of [UpdateSubscriberCredentialsRequest] + * @return [ResponseWrapper] with [SubscriberResponse] as the response data + * @throws [Exception] if a problem occurred talking to the server or if there is a connection error + */ suspend fun Novu.updateSubscriberCredentials( subscriberId: String, request: UpdateSubscriberCredentialsRequest, @@ -64,6 +108,13 @@ suspend fun Novu.updateSubscriberCredentials( return response.extractResponse(logger, config.enableLogging) } +/** + * Update a Subscriber's online status. + * @param subscriberId the ID of the Subscriber to be updated + * @param isOnline the online status of the Subscriber + * @return [ResponseWrapper] with [SubscriberResponse] as the response data + * @throws [Exception] if a problem occurred talking to the server or if there is a connection error + */ suspend fun Novu.updateSubscriberOnlineStatus( subscriberId: String, isOnline: Boolean, @@ -72,11 +123,25 @@ suspend fun Novu.updateSubscriberOnlineStatus( return response.extractResponse(logger, config.enableLogging) } +/** + * Retrieve a Subscriber's preferences. + * @param subscriberId the ID of the Subscriber whose preference is to be retrieved + * @return [ResponseWrapper] with a list of [SubscriberPreferenceResponse] as the response data + * @throws [Exception] if a problem occurred talking to the server or if there is a connection error + */ suspend fun Novu.subscriberPreferences(subscriberId: String): ResponseWrapper>? { val response = subscribersApi.getSubscriberPreferences(subscriberId) return response.extractResponse(logger, config.enableLogging) } +/** + * Update a Subscriber's preferences. + * @param subscriberId the ID of the Subscriber to be updated + * @param templateId the ID of the Template linked to the Subscriber + * @param body an instance of [UpdateSubscriberPreferencesRequest] + * @return [ResponseWrapper] with [SubscriberPreferenceResponse] as the response data + * @throws [Exception] if a problem occurred talking to the server or if there is a connection error + */ suspend fun Novu.updateSubscriberPreferences( subscriberId: String, templateId: String, @@ -86,16 +151,35 @@ suspend fun Novu.updateSubscriberPreferences( return response.extractResponse(logger, config.enableLogging) } +/** + * Retrieve all Notifications feed associated with a Subscriber. This function supports pagination. + * @param subscriberId the ID of the Subscriber whose Notifications feed is to be retrieved + * @return [PaginatedResponseWrapper] with a list of [SubscriberNotificationResponse] as the response data + * @throws [Exception] if a problem occurred talking to the server or if there is a connection error + */ suspend fun Novu.subscriberNotificationsFeed(subscriberId: String): PaginatedResponseWrapper? { val response = subscribersApi.getSubscriberNotificationsFeed(subscriberId) return response.extractResponse(logger, config.enableLogging) } +/** + * Retrieve a Subscriber's unseen Notifications count. + * @param subscriberId the ID of the Subscriber whose count is to be retrieved + * @return [ResponseWrapper] with [UnseenNotificationsCountResponse] as the response data + * @throws [Exception] if a problem occurred talking to the server or if there is a connection error + */ suspend fun Novu.subscriberUnseenNotificationsCount(subscriberId: String): ResponseWrapper? { val response = subscribersApi.getSubscriberUnseenNotificationsCount(subscriberId) return response.extractResponse(logger, config.enableLogging) } +/** + * Update a particular Subscriber's Message feed (either read or seen). + * @param subscriberId the ID of the Subscriber whose Message feed is to be updated + * @param request an instance of [MarkSubscriberFeedAsRequest] + * @return [ResponseWrapper] with a list of [SubscriberNotificationResponse] as the response data + * @throws [Exception] if a problem occurred talking to the server or if there is a connection error + */ suspend fun Novu.markSubscriberFeed( subscriberId: String, request: MarkSubscriberFeedAsRequest, @@ -104,6 +188,15 @@ suspend fun Novu.markSubscriberFeed( return response.extractResponse(logger, config.enableLogging) } +/** + * Update the action of a Message associated to a Subscriber. + * @param subscriberId the ID of the Subscriber whose Message feed is to be updated + * @param messageId the ID of the Message to be updated + * @param type the type of action to be performed + * @param request an instance of [MarkMessageActionAsSeenRequest] + * @return [ResponseWrapper] with [SubscriberNotificationResponse] as the response data + * @throws [Exception] if a problem occurred talking to the server or if there is a connection error + */ suspend fun Novu.markMessageActionSeen( subscriberId: String, messageId: String, diff --git a/src/main/kotlin/extensions/TenantsExtensions.kt b/src/main/kotlin/extensions/TenantsExtensions.kt index 3271d5f..c5f11c1 100644 --- a/src/main/kotlin/extensions/TenantsExtensions.kt +++ b/src/main/kotlin/extensions/TenantsExtensions.kt @@ -11,6 +11,13 @@ import mu.KotlinLogging private val logger = KotlinLogging.logger {} +/** + * Retrieve a list of Tenants. This function supports pagination. + * @param page the page number to be retrieved + * @param limit the size of the page to be retrieved + * @return [PaginatedResponseWrapper] with a list of [Tenant] as the response data + * @throws [Exception] if a problem occurred talking to the server or if there is a connection error + */ suspend fun Novu.getTenants( page: Int? = null, limit: Int? = null, @@ -19,16 +26,35 @@ suspend fun Novu.getTenants( return response.extractResponse(logger, config.enableLogging) } +/** + * Create a Tenant. + * @param request an instance of [TenantRequest] + * @return [ResponseWrapper] with [Tenant] as the response data + * @throws [Exception] if a problem occurred talking to the server or if there is a connection error + */ suspend fun Novu.createTenant(request: TenantRequest): ResponseWrapper? { val response = tenantsApi.createTenant(request) return response.extractResponse(logger, config.enableLogging) } +/** + * Retrieve a Tenant. + * @param identifier the ID of the Tenant to be retrieved + * @return [ResponseWrapper] with [Tenant] as the response data + * @throws [Exception] if a problem occurred talking to the server or if there is a connection error + */ suspend fun Novu.getTenant(identifier: String): ResponseWrapper? { val response = tenantsApi.getTenant(identifier) return response.extractResponse(logger, config.enableLogging) } +/** + * Update a Tenant. + * @param identifier the ID of the Tenant to be updated + * @param request an instance of [TenantRequest] + * @return [ResponseWrapper] with [Tenant] as the response data + * @throws [Exception] if a problem occurred talking to the server or if there is a connection error + */ suspend fun Novu.updateTenant( identifier: String, request: TenantRequest, @@ -37,6 +63,12 @@ suspend fun Novu.updateTenant( return response.extractResponse(logger, config.enableLogging) } +/** + * Delete a Tenant. + * @param identifier the ID of the Tenant to be deleted + * @return [DeleteTenantResponse] + * @throws [Exception] if a problem occurred talking to the server or if there is a connection error + */ suspend fun Novu.deleteTenant(identifier: String): DeleteTenantResponse { val response = tenantsApi.deleteTenant(identifier) return response.extractResponse(logger, config.enableLogging, DeleteTenantResponse()) diff --git a/src/main/kotlin/extensions/TopicsExtentions.kt b/src/main/kotlin/extensions/TopicsExtentions.kt index 3ab6f27..3d20f34 100644 --- a/src/main/kotlin/extensions/TopicsExtentions.kt +++ b/src/main/kotlin/extensions/TopicsExtentions.kt @@ -18,6 +18,14 @@ import java.math.BigInteger private val logger = KotlinLogging.logger {} +/** + * Retrieve a list of Topics filtered by a Topic key. This function supports pagination. + * @param page the page number to be retrieved + * @param pageSize the size of the page to be retrieved + * @param key the key of the Topics to be retrieved + * @return [PaginatedResponseWrapper] with a list of [TopicResponse] as the response data + * @throws [Exception] if a problem occurred talking to the server or if there is a connection error + */ suspend fun Novu.filterTopics( page: BigInteger? = null, pageSize: BigInteger? = null, @@ -27,11 +35,24 @@ suspend fun Novu.filterTopics( return response.extractResponse(logger, config.enableLogging) } +/** + * Create a Topic. + * @param request an instance of [CreateTopicRequest] + * @return [ResponseWrapper] with [CreateTopicResponse] as the response data + * @throws [Exception] if a problem occurred talking to the server or if there is a connection error + */ suspend fun Novu.createTopic(request: CreateTopicRequest): ResponseWrapper? { val response = topicsApi.createTopic(request) return response.extractResponse(logger, config.enableLogging) } +/** + * Add Subscribers to a Topic. + * @param topicKey the key of the Topic which the Subscriber should be added to + * @param request an instance of [SubscriberList] + * @return [ResponseWrapper] with [AddSubscribersResponse] as the response data + * @throws [Exception] if a problem occurred talking to the server or if there is a connection error + */ suspend fun Novu.addSubscribers( topicKey: String, request: SubscriberList, @@ -40,6 +61,13 @@ suspend fun Novu.addSubscribers( return response.extractResponse(logger, config.enableLogging) } +/** + * Remove Subscribers from a Topic. + * @param topicKey the key of the Topic which the Subscriber should be removed from + * @param request an instance of [SubscriberList] + * @return [RemoveSubscriberResponse] + * @throws [Exception] if a problem occurred talking to the server or if there is a connection error + */ suspend fun Novu.removeSubscriber( topicKey: String, request: SubscriberList, @@ -48,6 +76,13 @@ suspend fun Novu.removeSubscriber( return response.extractResponse(logger, config.enableLogging, RemoveSubscriberResponse()) } +/** + * Check if a Subscriber belongs to a Topic. + * @param topicKey the key of the Topic to be checked + * @param externalSubscriberId the ID of the Subscriber + * @return [CheckTopicSubscriberResponse] + * @throws [Exception] if a problem occurred talking to the server or if there is a connection error + */ suspend fun Novu.checkSubscriber( topicKey: String, externalSubscriberId: String, @@ -56,11 +91,24 @@ suspend fun Novu.checkSubscriber( return response.extractResponse(logger, config.enableLogging) } +/** + * Retrieve a Topic. + * @param topicKey the key of the Topic to be retrieved + * @return [ResponseWrapper] with [TopicResponse] as the response data + * @throws [Exception] if a problem occurred talking to the server or if there is a connection error + */ suspend fun Novu.topic(topicKey: String): ResponseWrapper? { val response = topicsApi.getTopic(topicKey) return response.extractResponse(logger, config.enableLogging) } +/** + * Rename a Topic. + * @param topicKey the key of the Topic to be renamed + * @param request an instance of [CreateByNameRequest] + * @return [ResponseWrapper] with [TopicResponse] as the response data + * @throws [Exception] if a problem occurred talking to the server or if there is a connection error + */ suspend fun Novu.renameTopic( topicKey: String, request: CreateByNameRequest, @@ -69,6 +117,12 @@ suspend fun Novu.renameTopic( return response.extractResponse(logger, config.enableLogging) } +/** + * Delete a Topic. + * @param topicKey the key of the Topic to be deleted + * @return [DeleteTopicResponse] + * @throws [Exception] if a problem occurred talking to the server or if there is a connection error + */ suspend fun Novu.deleteTopic(topicKey: String): DeleteTopicResponse { val response = topicsApi.deleteTopic(topicKey) return response.extractResponse(logger, config.enableLogging, DeleteTopicResponse()) diff --git a/src/main/kotlin/extensions/WorkflowOverrideExtensions.kt b/src/main/kotlin/extensions/WorkflowOverrideExtensions.kt index 141fecb..2cb09bb 100644 --- a/src/main/kotlin/extensions/WorkflowOverrideExtensions.kt +++ b/src/main/kotlin/extensions/WorkflowOverrideExtensions.kt @@ -12,11 +12,23 @@ import mu.KotlinLogging private val logger = KotlinLogging.logger {} +/** + * Create a Workflow override. + * @param request an instance of [CreateWorkflowOverrideRequest] + * @return [ResponseWrapper] with [WorkflowOverride] as the response data + * @throws [Exception] if a problem occurred talking to the server or if there is a connection error + */ suspend fun Novu.createWorkflowOverride(request: CreateWorkflowOverrideRequest): ResponseWrapper? { val response = workflowOverrideApi.createWorkflowOverride(request) return response.extractResponse(logger, config.enableLogging) } +/** + * Retrieve a list of Workflow override. This function supports pagination. + * @param request an instance of [GetWorkflowOverrideRequest] + * @return [PaginatedResponseWrapper] with a list of [WorkflowOverride] as the response data + * @throws [Exception] if a problem occurred talking to the server or if there is a connection error + */ suspend fun Novu.getWorkflowOverrides(request: GetWorkflowOverrideRequest): PaginatedResponseWrapper? { val params: MutableMap = HashMap() request.page?.let { params["page"] = it } @@ -25,6 +37,13 @@ suspend fun Novu.getWorkflowOverrides(request: GetWorkflowOverrideRequest): Pagi return response.extractResponse(logger, config.enableLogging) } +/** + * Retrieve a Workflow override associated with a Tenant. + * @param workflowId the ID of the Workflow override to be retrieved + * @param tenantId the ID of the Tenant + * @return [ResponseWrapper] with [WorkflowOverride] as the response data + * @throws [Exception] if a problem occurred talking to the server or if there is a connection error + */ suspend fun Novu.getWorkflowOverride( workflowId: String, tenantId: String, @@ -33,11 +52,24 @@ suspend fun Novu.getWorkflowOverride( return response.extractResponse(logger, config.enableLogging) } +/** + * Retrieve a Workflow override. + * @param overrideId the ID of the Workflow override to be retrieved + * @return [ResponseWrapper] with [WorkflowOverride] as the response data + * @throws [Exception] if a problem occurred talking to the server or if there is a connection error + */ suspend fun Novu.getWorkflowOverrideById(overrideId: String): ResponseWrapper? { val response = workflowOverrideApi.getWorkflowOverrideById(overrideId) return response.extractResponse(logger, config.enableLogging) } +/** + * Update a Workflow override. + * @param overrideId the ID of the Workflow override to be updated + * @param request an instance of [UpdateWorkflowOverrideRequest] + * @return [ResponseWrapper] with [WorkflowOverride] as the response data + * @throws [Exception] if a problem occurred talking to the server or if there is a connection error + */ suspend fun Novu.updateWorkflowOverrideById( overrideId: String, request: UpdateWorkflowOverrideRequest, @@ -46,6 +78,14 @@ suspend fun Novu.updateWorkflowOverrideById( return response.extractResponse(logger, config.enableLogging) } +/** + * Update a Workflow override associated with a Tenant. + * @param workflowId the ID of the Workflow override to be updated + * @param tenantId the ID of the Tenant + * @param request an instance of [UpdateWorkflowOverrideRequest] + * @return [ResponseWrapper] with [WorkflowOverride] as the response data + * @throws [Exception] if a problem occurred talking to the server or if there is a connection error + */ suspend fun Novu.updateWorkflowOverride( workflowId: String, tenantId: String, @@ -55,6 +95,12 @@ suspend fun Novu.updateWorkflowOverride( return response.extractResponse(logger, config.enableLogging) } +/** + * Delete a Workflow override. + * @param overrideId the ID of the Workflow override to be deleted + * @return [ResponseWrapper] with [Boolean] as the response data + * @throws [Exception] if a problem occurred talking to the server or if there is a connection error + */ suspend fun Novu.deleteWorkflowOverride(overrideId: String): ResponseWrapper? { val response = workflowOverrideApi.deleteWorkflowOverride(overrideId) return response.extractResponse(logger, config.enableLogging) diff --git a/src/main/kotlin/extensions/WorkflowsExtensions.kt b/src/main/kotlin/extensions/WorkflowsExtensions.kt index 2a69a50..ed0ba62 100644 --- a/src/main/kotlin/extensions/WorkflowsExtensions.kt +++ b/src/main/kotlin/extensions/WorkflowsExtensions.kt @@ -12,6 +12,13 @@ import mu.KotlinLogging private val logger = KotlinLogging.logger {} +/** + * Retrieve a list of Workflows. This function supports pagination. + * @param page the page number to be retrieved + * @param limit the size of the page to be retrieved + * @return [PaginatedResponseWrapper] with a list of [WorkflowResponse] as the response data + * @throws [Exception] if a problem occurred talking to the server or if there is a connection error + */ suspend fun Novu.getWorkflows( page: Int?, limit: Int?, @@ -20,11 +27,24 @@ suspend fun Novu.getWorkflows( return response.extractResponse(logger, config.enableLogging) } +/** + * Create a Workflow. + * @param request an instance of [WorkflowRequest] + * @return [ResponseWrapper] with [WorkflowResponse] as the response data + * @throws [Exception] if a problem occurred talking to the server or if there is a connection error + */ suspend fun Novu.createWorkflow(request: WorkflowRequest): ResponseWrapper? { val response = workflowsApi.createWorkflow(request) return response.extractResponse(logger, config.enableLogging) } +/** + * Update a Workflow. + * @param workflowId the ID of the Workflow to be updated + * @param request an instance of [UpdateWorkflowRequest] + * @return [ResponseWrapper] with [WorkflowResponse] as the response data + * @throws [Exception] if a problem occurred talking to the server or if there is a connection error + */ suspend fun Novu.updateWorkflow( workflowId: String, request: UpdateWorkflowRequest, @@ -33,16 +53,35 @@ suspend fun Novu.updateWorkflow( return response.extractResponse(logger, config.enableLogging) } +/** + * Delete a Workflow. + * @param workflowId the ID of the Workflow to be deleted + * @return [ResponseWrapper] with [WorkflowResponse] as the response data + * @throws [Exception] if a problem occurred talking to the server or if there is a connection error + */ suspend fun Novu.deleteWorkflow(workflowId: String): ResponseWrapper? { val response = workflowsApi.deleteWorkflow(workflowId) return response.extractResponse(logger, config.enableLogging) } +/** + * Retrieve a Workflow. + * @param workflowId the ID of the Workflow to be retrieved + * @return [ResponseWrapper] with [WorkflowResponse] as the response data + * @throws [Exception] if a problem occurred talking to the server or if there is a connection error + */ suspend fun Novu.getWorkflow(workflowId: String): ResponseWrapper? { val response = workflowsApi.getWorkflow(workflowId) return response.extractResponse(logger, config.enableLogging) } +/** + * Update a Workflow status. + * @param workflowId the ID of the Workflow to be updated + * @param request an instance of [UpdateWorkflowStatusRequest] + * @return [ResponseWrapper] with [WorkflowResponse] as the response data + * @throws [Exception] if a problem occurred talking to the server or if there is a connection error + */ suspend fun Novu.updateWorkflowStatus( workflowId: String, request: UpdateWorkflowStatusRequest,