Skip to content

Commit

Permalink
feat: Write docs for Subscribers
Browse files Browse the repository at this point in the history
  • Loading branch information
mayorJAY committed Jun 18, 2024
1 parent b820e23 commit 032d78c
Showing 1 changed file with 93 additions and 0 deletions.
93 changes: 93 additions & 0 deletions src/main/kotlin/extensions/SubscriberExtensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<SubscriberResponse>? {
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<SubscriberResponse>? {
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<SubscriberResponse>? {
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,
Expand All @@ -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<SubscriberDeleteResponse>? {
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,
Expand All @@ -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,
Expand All @@ -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<List<SubscriberPreferenceResponse>>? {
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,
Expand All @@ -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<SubscriberNotificationResponse>? {
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<UnseenNotificationsCountResponse>? {
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,
Expand All @@ -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,
Expand Down

0 comments on commit 032d78c

Please sign in to comment.