@@ -19,7 +19,7 @@ def get(self, collection, id):
19
19
return self .client .request ('get' , endpoint )
20
20
21
21
# NOTE: This is `set_object` as `set` is a reserved keyword
22
- def set_object (self , collection , id , data = {}):
22
+ def set_object (self , collection , id , data = {}):
23
23
"""
24
24
Returns an object in a collection with the id given.
25
25
@@ -32,7 +32,7 @@ def set_object(self, collection, id, data = {}):
32
32
dict: A Knock Object
33
33
"""
34
34
endpoint = '/objects/{}/{}' .format (collection , id )
35
- return self .client .request ('put' , endpoint , payload = data )
35
+ return self .client .request ('put' , endpoint , payload = data )
36
36
37
37
def bulk_set (self , collection , objects ):
38
38
"""
@@ -45,7 +45,7 @@ def bulk_set(self, collection, objects):
45
45
Returns:
46
46
dict: BulkOperation from Knock
47
47
"""
48
- data = { 'objects' : objects }
48
+ data = {'objects' : objects }
49
49
endpoint = '/objects/{}/bulk/set' .format (collection )
50
50
return self .client .request ('post' , endpoint , payload = data )
51
51
@@ -74,7 +74,7 @@ def bulk_delete(self, collection, object_ids):
74
74
Returns:
75
75
dict: BulkOperation from Knock
76
76
"""
77
- data = { 'object_ids' : object_ids }
77
+ data = {'object_ids' : object_ids }
78
78
endpoint = '/objects/{}/bulk/delete' .format (collection )
79
79
return self .client .request ('post' , endpoint , payload = data )
80
80
@@ -94,7 +94,8 @@ def get_channel_data(self, collection, id, channel_id):
94
94
Returns:
95
95
dict: Channel data from Knock.
96
96
"""
97
- endpoint = '/objects/{}/{}/channel_data/{}' .format (collection , id , channel_id )
97
+ endpoint = '/objects/{}/{}/channel_data/{}' .format (
98
+ collection , id , channel_id )
98
99
return self .client .request ('get' , endpoint )
99
100
100
101
def set_channel_data (self , collection , id , channel_id , channel_data ):
@@ -110,9 +111,26 @@ def set_channel_data(self, collection, id, channel_id, channel_data):
110
111
Returns:
111
112
dict: Channel data from Knock.
112
113
"""
113
- endpoint = '/objects/{}/{}/channel_data/{}' .format (collection , id , channel_id )
114
+ endpoint = '/objects/{}/{}/channel_data/{}' .format (
115
+ collection , id , channel_id )
114
116
return self .client .request ('put' , endpoint , payload = {'data' : channel_data })
115
117
118
+ def unset_channel_data (self , collection , id , channel_id ):
119
+ """
120
+ Unsets the object's channel data for the given channel id.
121
+
122
+ Args:
123
+ collection (str): The collection the object belongs to
124
+ id (str): The id of the object in the collection
125
+ channel_id (str): Target channel ID
126
+
127
+ Returns:
128
+ None: No response
129
+ """
130
+ endpoint = '/objects/{}/{}/channel_data/{}' .format (
131
+ collection , id , channel_id )
132
+ return self .client .request ('delete' , endpoint )
133
+
116
134
##
117
135
# Messages
118
136
##
@@ -131,3 +149,195 @@ def get_messages(self, collection, id, options=None):
131
149
"""
132
150
endpoint = '/objects/{}/{}/messages' .format (collection , id )
133
151
return self .client .request ('get' , endpoint , payload = options )
152
+
153
+ ##
154
+ # Preferences
155
+ ##
156
+
157
+ def get_all_preferences (self , collection , id ):
158
+ """
159
+ Get an objects full set of preferences
160
+
161
+ Args:
162
+ collection (str): The collection the object belongs to
163
+ id (str): The id of the object in the collection
164
+
165
+ Returns:
166
+ dict: PreferenceSet response from Knock.
167
+ """
168
+ endpoint = '/objects/{}/{}/preferences' .format (collection , id )
169
+ return self .client .request ('get' , endpoint )
170
+
171
+ def get_preferences (self , collection , id , options = {}):
172
+ """
173
+ Get a preference set
174
+
175
+ Args:
176
+ collection (str): The collection the object belongs to
177
+ id (str): The id of the object in the collection
178
+ options (dict):
179
+ preference_set (str): The preference set to retrieve (defaults to "default")
180
+
181
+ Returns:
182
+ dict: PreferenceSet response from Knock.
183
+ """
184
+ preference_set_id = options .get ('preference_set' , default_set_id )
185
+ endpoint = '/objects/{}/{}/preferences/{}' .format (
186
+ collection , id , preference_set_id )
187
+
188
+ return self .client .request ('get' , endpoint )
189
+
190
+ def set_preferences (self , collection , id , channel_types = None , categories = None , workflows = None , options = {}):
191
+ """
192
+ Sets the preference set
193
+
194
+ Args:
195
+ collection (str): The collection the object belongs to
196
+ id (str): The id of the object in the collection
197
+ channel_types (dict): A dictionary of channel type preferences
198
+ categories (dict): A dictionary of category preferences
199
+ workflows (dict): A dictionary of workflow preferences
200
+ options (dict): A dictionary of options
201
+
202
+ Returns:
203
+ dict: PreferenceSet response from Knock.
204
+ """
205
+ preference_set_id = options .get ('preference_set' , default_set_id )
206
+
207
+ endpoint = '/objects/{}/{}/preferences/{}' .format (
208
+ collection , id , preference_set_id )
209
+
210
+ params = {
211
+ 'channel_types' : channel_types ,
212
+ 'categories' : categories ,
213
+ 'workflows' : workflows
214
+ }
215
+
216
+ return self .client .request ('put' , endpoint , payload = params )
217
+
218
+ def set_channel_types_preferences (self , collection , id , preferences , options = {}):
219
+ """
220
+ Sets the channel type preferences
221
+
222
+ Args:
223
+ collection (str): The collection the object belongs to
224
+ id (str): The id of the object in the collection
225
+ preferences (dict): A dictionary of channel type preferences
226
+ options (dict): A dictionary of options
227
+
228
+ Returns:
229
+ dict: PreferenceSet response from Knock.
230
+ """
231
+ preference_set_id = options .get ('preference_set' , default_set_id )
232
+
233
+ endpoint = '/objects/{}/{}/preferences/{}/channel_types' .format (
234
+ collection , id , preference_set_id )
235
+
236
+ return self .client .request ('put' , endpoint , payload = preferences )
237
+
238
+ def set_channel_type_preferences (self , collection , id , channel_type , setting , options = {}):
239
+ """
240
+ Sets the channel type preference
241
+
242
+ Args:
243
+ collection (str): The collection the object belongs to
244
+ id (str): The id of the object in the collection
245
+ channel_type (str): The channel_type to set
246
+ setting (boolean): The preference setting
247
+ options (dict): A dictionary of options
248
+
249
+ Returns:
250
+ dict: PreferenceSet response from Knock.
251
+ """
252
+ preference_set_id = options .get ('preference_set' , default_set_id )
253
+
254
+ endpoint = '/objects/{}/{}/preferences/{}/channel_types/{}' .format (
255
+ collection , id , preference_set_id , channel_type )
256
+
257
+ return self .client .request ('put' , endpoint , payload = {'subscribed' : setting })
258
+
259
+ def set_workflows_preferences (self , collection , id , preferences , options = {}):
260
+ """
261
+ Sets the workflow preferences
262
+
263
+ Args:
264
+ collection (str): The collection the object belongs to
265
+ id (str): The id of the object in the collection
266
+ preferences (dict): A dictionary of workflow preferences
267
+ options (dict): A dictionary of options
268
+
269
+ Returns:
270
+ dict: PreferenceSet response from Knock.
271
+ """
272
+ preference_set_id = options .get ('preference_set' , default_set_id )
273
+
274
+ endpoint = '/objects/{}/{}/preferences/{}/workflows' .format (
275
+ collection , id , preference_set_id )
276
+
277
+ return self .client .request ('put' , endpoint , payload = preferences )
278
+
279
+ def set_workflow_preferences (self , collection , id , key , setting , options = {}):
280
+ """
281
+ Sets the workflow preferences
282
+
283
+ Args:
284
+ collection (str): The collection the object belongs to
285
+ id (str): The id of the object in the collection
286
+ key (str): The workflow key
287
+ setting (boolean or dict): The preference setting
288
+ options (dict): A dictionary of options
289
+
290
+ Returns:
291
+ dict: PreferenceSet response from Knock.
292
+ """
293
+ preference_set_id = options .get ('preference_set' , default_set_id )
294
+
295
+ endpoint = '/objects/{}/{}/preferences/{}/workflows/{}' .format (
296
+ collection , id , preference_set_id , key )
297
+
298
+ params = setting if type (setting ) is dict else {'subscribed' : setting }
299
+
300
+ return self .client .request ('put' , endpoint , payload = params )
301
+
302
+ def set_categories_preferences (self , collection , id , preferences , options = {}):
303
+ """
304
+ Sets the categories preferences
305
+
306
+ Args:
307
+ collection (str): The collection the object belongs to
308
+ id (str): The id of the object in the collection
309
+ preferences (dict): A dictionary of category preferences
310
+ options (dict): A dictionary of options
311
+
312
+ Returns:
313
+ dict: PreferenceSet response from Knock.
314
+ """
315
+ preference_set_id = options .get ('preference_set' , default_set_id )
316
+
317
+ endpoint = '/objects/{}/{}/preferences/{}/categories' .format (
318
+ collection , id , preference_set_id )
319
+
320
+ return self .client .request ('put' , endpoint , payload = preferences )
321
+
322
+ def set_category_preferences (self , collection , id , key , setting , options = {}):
323
+ """
324
+ Sets the category preferences
325
+
326
+ Args:
327
+ collection (str): The collection the object belongs to
328
+ id (str): The id of the object in the collection
329
+ key (str): The category key
330
+ setting (boolean or dict): The preference setting
331
+ options (dict): A dictionary of options
332
+
333
+ Returns:
334
+ dict: PreferenceSet response from Knock.
335
+ """
336
+ preference_set_id = options .get ('preference_set' , default_set_id )
337
+
338
+ endpoint = '/objects/{}/{}/preferences/{}/categories/{}' .format (
339
+ collection , id , preference_set_id , key )
340
+
341
+ params = setting if type (setting ) is dict else {'subscribed' : setting }
342
+
343
+ return self .client .request ('put' , endpoint , payload = params )
0 commit comments