Skip to content

Commit 50858dd

Browse files
authored
feat(kno-4299): bulk add subscriptions API support (#24)
1 parent 58484e3 commit 50858dd

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

lib/knock/resources/objects.ex

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,23 @@ defmodule Knock.Objects do
7676
Api.post(client, "/objects/#{collection}/bulk/delete", %{object_ids: object_ids})
7777
end
7878

79+
@doc """
80+
Creates a bulk operation to create subscriptions for a set of recipients to a
81+
set of objects within the given collection.
82+
83+
Each entry in the provided subscriptions list should have the properties:
84+
85+
- id: the id of an object for subscribing
86+
- recipients: a list of recipients to subscribe to the object
87+
- properties (optional): a map of properties to apply to each recipient subscription
88+
"""
89+
@spec bulk_add_subscriptions(Client.t(), String.t(), [map()]) :: Api.response()
90+
def bulk_add_subscriptions(client, collection, subscriptions) do
91+
Api.post(client, "/objects/#{collection}/bulk/subscriptions/add", %{
92+
subscriptions: subscriptions
93+
})
94+
end
95+
7996
##
8097
# Channel data
8198
##
@@ -203,8 +220,12 @@ defmodule Knock.Objects do
203220
Expected properties:
204221
- recipients: list of recipients to create subscriptions for
205222
"""
206-
@spec delete_subscriptions(Client.t(), String.t(), String.t(), [String.t() | map()]) ::
207-
Api.response()
223+
@spec delete_subscriptions(
224+
Client.t(),
225+
String.t(),
226+
String.t(),
227+
%{recipients: [String.t() | map()]}
228+
) :: Api.response()
208229
def delete_subscriptions(client, collection, id, params) do
209230
recipients = Map.get(params, :recipients)
210231

0 commit comments

Comments
 (0)