@@ -12,6 +12,20 @@ defmodule Knock.Objects do
1212 """
1313 @ type ref :: % { id: :string , collection: :string }
1414
15+ @ doc """
16+ Returns paginated list of objects for a collection
17+
18+ # Available optional parameters:
19+ #
20+ # - page_size: specify size of the page to be returned by the api. (max limit: 50)
21+ # - after: after cursor for pagination
22+ # - before: before cursor for pagination
23+ """
24+ @ spec list ( Client . t ( ) , String . t ( ) , Keyword . t ( ) ) :: Api . response ( )
25+ def list ( client , collection , options \\ [ ] ) do
26+ Api . get ( client , "/objects/#{ collection } " , query: options )
27+ end
28+
1529 @ doc """
1630 Builds an object reference, which can be used in workflow trigger calls.
1731 """
@@ -138,6 +152,67 @@ defmodule Knock.Objects do
138152 Api . get ( client , "/objects/#{ collection } /#{ id } /schedules" , query: options )
139153 end
140154
155+ ##
156+ # Subscriptions
157+ ##
158+
159+ @ doc """
160+ Returns paginated subscriptions for the given object
161+
162+ # Available optional parameters:
163+ #
164+ # - page_size: specify size of the page to be returned by the api. (max limit: 50)
165+ # - after: after cursor for pagination
166+ # - before: before cursor for pagination
167+ """
168+ @ spec list_subscriptions ( Client . t ( ) , String . t ( ) , String . t ( ) , Keyword . t ( ) ) :: Api . response ( )
169+ def list_subscriptions ( client , collection , id , options \\ [ ] ) do
170+ Api . get ( client , "/objects/#{ collection } /#{ id } /subscriptions" , query: options )
171+ end
172+
173+ @ doc """
174+ Returns paginated subscriptions for the given object as recipient
175+
176+ # Available optional parameters:
177+ #
178+ # - page_size: specify size of the page to be returned by the api. (max limit: 50)
179+ # - after: after cursor for pagination
180+ # - before: before cursor for pagination
181+ """
182+ @ spec get_subscriptions ( Client . t ( ) , String . t ( ) , String . t ( ) , Keyword . t ( ) ) :: Api . response ( )
183+ def get_subscriptions ( client , collection , id , options \\ [ ] ) do
184+ options = Keyword . put ( options , :mode , "recipient" )
185+ Api . get ( client , "/objects/#{ collection } /#{ id } /subscriptions" , query: options )
186+ end
187+
188+ @ doc """
189+ Adds subscriptions for all recipients passed as arguments
190+
191+ Expected properties:
192+ - recipients: list of recipients to create subscriptions for
193+ - properties: data to be stored at the subscription level for each recipient
194+ """
195+ @ spec add_subscriptions ( Client . t ( ) , String . t ( ) , String . t ( ) , map ( ) ) :: Api . response ( )
196+ def add_subscriptions ( client , collection , id , params ) do
197+ Api . post ( client , "/objects/#{ collection } /#{ id } /subscriptions" , params )
198+ end
199+
200+ @ doc """
201+ Delete subscriptions for recipients passed as arguments
202+
203+ Expected properties:
204+ - recipients: list of recipients to create subscriptions for
205+ """
206+ @ spec delete_subscriptions ( Client . t ( ) , String . t ( ) , String . t ( ) , [ String . t ( ) | map ( ) ] ) ::
207+ Api . response ( )
208+ def delete_subscriptions ( client , collection , id , params ) do
209+ recipients = Map . get ( params , :recipients )
210+
211+ Api . delete ( client , "/objects/#{ collection } /#{ id } /subscriptions" ,
212+ body: % { recipients: recipients }
213+ )
214+ end
215+
141216 ##
142217 # Preferences
143218 ##
0 commit comments