Module: Novu::Api::Subscribers

Included in:
Client
Defined in:
lib/novu/api/subscribers.rb

Overview

Module Novu::Api::Subscribers provides an API for managing subscribers in the Novu application.

This module includes methods for creating, retrieving, updating, and deleting subscribers. It also includes methods for updating subscriber credentials, online status, preferences etc.

For more information on the Novu API(api.novu.co/api#/Subscribers), see docs.novu.co/api/get-subscribers/.

Instance Method Summary collapse

Instance Method Details

#bulk_create_subscribers(body) ⇒ number

Returns status - The status code. Returns 201 if the subscribers were created successfully.

Returns:

  • (number)

    status - The status code. Returns 201 if the subscribers were created successfully.



246
247
248
# File 'lib/novu/api/subscribers.rb', line 246

def bulk_create_subscribers(body)
     post("/subscribers/bulk", body: body.to_json, headers: {'Content-Type': 'application/json'})
end

#chat_oauth(subscriberId, providerId, query = {}) ⇒ number

Handle chat OAUTH

@pathparams: @queryparams:

Parameters:

  • `subscriberId` (String)
  • `providerId` (String)
  • `hmacHash` (String)
  • `environmentId` (String)
  • `integrationIdentifier` (String)

Returns:

  • (number)

    status

    • Returns 200 if successful



296
297
298
# File 'lib/novu/api/subscribers.rb', line 296

def chat_oauth(subscriberId, providerId, query = {})
  get("/subscribers/#{subscriberId}/credentials/#{providerId}/oauth", query: query)
end

#create_subscriber(body) ⇒ Hash, number

Creates a subscriber entity, in the Novu platform. The subscriber will be later used to receive notifications, and access notification feeds. Communication credentials such as email, phone number, and 3 rd party credentials i.e slack tokens could be later associated to this entity.

@bodyparams:

Parameters:

  • `subscriberId` (String)

    The internal identifier you used to create this subscriber, usually correlates to the id the user in your systems.

  • `email` (String(optional))
  • `firstName` (String(optional))
  • `lastName` (String(optional))
  • `phone` (String(optional))
  • `avatar` (String(optional))

    An http url to the profile image of your subscriber

  • `locale` (String(optional))
  • `data` (Hash(optional))

Returns:

  • (Hash)

    The hash of subscriber data is successfully returned.

  • (number)

    status - The status code. Returns 201 if the susbscriber has been successfully created.



41
42
43
# File 'lib/novu/api/subscribers.rb', line 41

def create_subscriber(body)
  post("/subscribers", body: body)
end

#delete_subscriber(subscriber_id) ⇒ Hash, number

Deletes a subscriber entity from the Novu platform

@pathparams:

Parameters:

  • `subscriber_id` (String)

    The ID of the subscriber to delete.

Returns:

  • (Hash)

    Hash of acknowledged and status.

  • (number)

    status

    • Returns 200 if the subscriber has been deleted correctly.



86
87
88
# File 'lib/novu/api/subscribers.rb', line 86

def delete_subscriber(subscriber_id)
  delete("/subscribers/#{subscriber_id}")
end

#delete_subscriber_credentials(subscriberId, providerId) ⇒ number

Delete subscriber credentials by providerId Delete subscriber credentials such as slack and expo tokens.

@pathParams:

Parameters:

  • `subscriberId` (String)

    The ID of the subscriber to update credentials.

  • `providerId` (String)

    The provider identifier for the credentials

Returns:

  • (number)

    status

    • Returns 204 if the subscriber credentials has been deleted successfully.



115
116
117
# File 'lib/novu/api/subscribers.rb', line 115

def delete_subscriber_credentials(subscriberId, providerId)
  delete("/subscribers/#{subscriberId}/credentials/#{providerId}")
end

#mark_all_subscriber_messages(subscriber_id, body) ⇒ number

Marks all the subscriber messages as read, unread, seen or unseen.

@bodyParams:

Parameters:

  • `subscriber_id` (String)
  • `markAs` (String)

    The type of action to perform either read, unread, seen or unseen.

  • `feedIdentifier` (String|Array(Optional))

    The feed id (or array) to mark messages of a particular feed.

Returns:

  • (number)

    status

    • Returns 201 if successful



260
261
262
# File 'lib/novu/api/subscribers.rb', line 260

def mark_all_subscriber_messages(subscriber_id, body)
  post("/subscribers/#{subscriber_id}/messages/mark-all", body: body)
end

#mark_message_action_seen(subscriber_id, message_id, type) ⇒ Hash, number

Mark message action as seen

Parameters:

  • `message_id` (String)
  • `type` (String)
  • `subscriber_id` (String)

Returns:

  • (Hash)

    the unseen notification count

  • (number)

    status

    • Returns 201 if successful



221
222
223
# File 'lib/novu/api/subscribers.rb', line 221

def mark_message_action_seen(subscriber_id, message_id, type)
  post("/subscribers/#{subscriber_id}/messages/#{message_id}/actions/#{type}")
end

#mark_subscriber_feed_seen(subscriber_id, body) ⇒ Hash, number

Mark a subscriber feed message as seen

@bodyparams:

Parameters:

  • `subscriber_id` (String)
  • `messageId` (Hash)
  • `mark` (Hash)

Returns:

  • (Hash)

    the unseen notification count

  • (number)

    status

    • Returns 201 if successful



207
208
209
# File 'lib/novu/api/subscribers.rb', line 207

def mark_subscriber_feed_seen(subscriber_id, body)
  post("/subscribers/#{subscriber_id}/messages/markAs", body: body)
end

#provider_oauth_redirect(subscriberId, providerId, query = {}) ⇒ Hash, number

Handle providers OAUTH redirect

@pathparams: @queryparams:

Parameters:

  • `subscriberId` (String)
  • `providerId` (String)
  • `code` (String)
  • `hmacHash` (String)
  • `environmentId` (String)
  • `integrationIdentifier` (String)

Returns:

  • (Hash)

    The list of changes that match the criteria of the query params are successfully returned.

  • (number)

    status

    • Returns 200 if successful



279
280
281
# File 'lib/novu/api/subscribers.rb', line 279

def provider_oauth_redirect(subscriberId, providerId, query = {})
  get("/subscribers/#{subscriberId}/credentials/#{providerId}/oauth/callback", query: query)
end

#subscriber(subscriber_id) ⇒ Hash, number

Retrieves the subscriber with the given ID.

Parameters:

  • `subscriber_id` (String)

    The ID of the subscriber to retrieve.

Returns:

  • (Hash)

    The retrieved subscriber.

  • (number)

    status

    • Returns 200 if the subscriber with the subscriber_id provided exists in the database.



53
54
55
# File 'lib/novu/api/subscribers.rb', line 53

def subscriber(subscriber_id)
  get("/subscribers/#{subscriber_id}")
end

#subscriber_notification_feed(subscriber_id, query = {}) ⇒ Hash, number

Returns a notification feed for a particular subscriber

@queryparams:

Parameters:

  • `subscriber_id` (String)
  • `page` (Integer(optional))

    Number of page for the pagination.

  • `feedIdentifier` (String)
  • `seen` (Boolean(optional))

Returns:

  • (Hash)

    List of notification feed of a subscriber that match the criteria of the query params are successfully returned.

  • (number)

    status

    • Returns 200 if successful



176
177
178
# File 'lib/novu/api/subscribers.rb', line 176

def subscriber_notification_feed(subscriber_id, query = {})
  get("/subscribers/#{subscriber_id}/notifications/feed", query: query)
end

#subscriber_preferences(subscriber_id) ⇒ Hash, number

Used to get the subscriber preference

@pathparams:

Parameters:

  • `subscriber_id` (String)

    The ID of the subscriber.

Returns:

  • (Hash)

    Hash of template and preference.

  • (number)

    status

    • Returns 200 if the subscriber preference has been retrieved successfully.



142
143
144
# File 'lib/novu/api/subscribers.rb', line 142

def subscriber_preferences(subscriber_id)
  get("/subscribers/#{subscriber_id}/preferences")
end

#subscriber_unseen_notification_count(subscriber_id, query = {}) ⇒ Hash, number

Returns the unseen notification count for subscribers feed

@queryparams:

Parameters:

  • `subscriber_id` (String)
  • `seen` (Boolean)

Returns:

  • (Hash)

    the unseen notification count

  • (number)

    status

    • Returns 200 if successful



191
192
193
# File 'lib/novu/api/subscribers.rb', line 191

def subscriber_unseen_notification_count(subscriber_id, query = {})
  get("/subscribers/#{subscriber_id}/notifications/unseen", query: query)
end

#subscribers(query = {}) ⇒ Hash, number

Returns a list of subscribers, could paginated using the ‘page` query parameter

@queryparams:

Parameters:

  • `page` (Integer(optional))

    Number of page for the pagination. The page to fetch, defaults to 0.

Returns:

  • (Hash)

    The list of subscribers that match the criteria of the query params are successfully returned.

  • (number)

    status

    • Returns 200 if successful



20
21
22
# File 'lib/novu/api/subscribers.rb', line 20

def subscribers(query = {})
  get("/subscribers", query: query)
end

#update_subscriber(subscriber_id, body) ⇒ Hash, number

Used to update the subscriber entity with new information

@pathparams:

Parameters:

  • `subscriber_id` (String)

    The ID of the subscriber to update.

  • `email` (String(optional))
  • `firstName` (String(optional))
  • `lastName` (String(optional))
  • `phone` (String(optional))
  • `avatar` (String(optional))
  • `locale` (String(optional))
  • `data` (String(optional))

Returns:

  • (Hash)

    The updated subscriber entity.

  • (number)

    status

    • Returns 200 if the subscriber with the subscriber_id provided has been updated correctly.



74
75
76
# File 'lib/novu/api/subscribers.rb', line 74

def update_subscriber(subscriber_id, body)
  put("/subscribers/#{subscriber_id}", body: body)
end

#update_subscriber_credentials(subscriber_id, body) ⇒ Hash, number

Update subscriber credentials from the Novu platform. Subscriber credentials associated to the delivery methods such as slack and push tokens.

@pathparams: @bodyparams:

Parameters:

  • `subscriber_id` (String)

    The ID of the subscriber to update credentials.

  • `providerId` (String)

    The provider identifier for the credentials

  • `credentials` (Hash)

    Credentials payload for the specified provider

Returns:

  • (Hash)

    Hash of updated subscriber credentials entity

  • (number)

    status

    • Returns 200 if the subscriber credentials has been updated correctly.



102
103
104
# File 'lib/novu/api/subscribers.rb', line 102

def update_subscriber_credentials(subscriber_id, body)
  put("/subscribers/#{subscriber_id}/credentials", body: body)
end

#update_subscriber_online_status(subscriber_id, body) ⇒ Hash, number

Used to update the subscriber isOnline flag.

@pathparams: @bodyparams:

Parameters:

  • `subscriber_id` (String)

    The ID of the subscriber to update online status.

  • `isOnline` (Boolean)

Returns:

  • (Hash)

    The updated subscriber entity.

  • (number)

    status

    • Returns 200 if the subscriber online status has been updated correctly.



130
131
132
# File 'lib/novu/api/subscribers.rb', line 130

def update_subscriber_online_status(subscriber_id, body)
  patch("/subscribers/#{subscriber_id}/online-status", body: body)
end

#update_subscriber_preference(subscriber_id, template_id, body) ⇒ Hash, number

Used to update the subscriber preference

@pathparams: @bodyparams:

Parameters:

  • `subscriber_id` (String)

    The ID of the subscriber to update preference.

  • `template_id` (String)

    The ID of the template to update preference.

  • `channel` (Hash(optional))

    The subscriber preferences for every ChannelTypeEnum for the notification template assigned.

  • `enabled` (Boolean(optional))

    Sets if the notification template is fully enabled for all channels or not for the subscriber.

Returns:

  • (Hash)

    Hash of template and preference.

  • (number)

    status

    • Returns 200 if the subscriber preference has been updated correctly.



159
160
161
# File 'lib/novu/api/subscribers.rb', line 159

def update_subscriber_preference(subscriber_id, template_id, body)
  patch("/subscribers/#{subscriber_id}/preferences/#{template_id}", body: body)
end