Skip to content

Commit 16b7b41

Browse files
committed
feat(messages): add new message endpoints support
1 parent 4386d00 commit 16b7b41

File tree

5 files changed

+103
-4
lines changed

5 files changed

+103
-4
lines changed

knockapi/client.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ def bulk_operations(self):
6969
from .resources import BulkOperations
7070
return BulkOperations(self)
7171

72+
@property
73+
def messages(self):
74+
from .resources import Messages
75+
return Messages(self)
76+
7277
# Defined at the top level here for convienience
7378
def notify(self, key, actor, recipients, data={}, cancellation_key=None, tenant=None):
7479
"""

knockapi/resources/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
from .workflows import Workflows
33
from .preferences import Preferences
44
from .objects import Objects
5-
from .bulk_operations import BulkOperations
5+
from .bulk_operations import BulkOperations
6+
from .messages import Messages

knockapi/resources/messages.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
from .service import Service
2+
3+
default_set_id = "default"
4+
5+
class Messages(Service):
6+
def get(self, id):
7+
"""
8+
Get a message by its id
9+
10+
Args:
11+
id: The message ID
12+
13+
Returns:
14+
dict: Message response from Knock.
15+
"""
16+
endpoint = '/messages/{}'.format(id)
17+
return self.client.request('get', endpoint)
18+
19+
def get_content(self, id):
20+
"""
21+
Get a message's content by its id
22+
23+
Args:
24+
id: The message ID
25+
26+
Returns:
27+
dict: MessageContent response from Knock.
28+
"""
29+
endpoint = '/messages/{}/content'.format(id)
30+
return self.client.request('get', endpoint)
31+
32+
def get_activities(self, id, options=None):
33+
"""
34+
Get a message's activities by its id
35+
36+
Args:
37+
id: The message ID
38+
39+
Returns:
40+
dict: paginated Activity response from Knock.
41+
"""
42+
endpoint = '/messages/{}/activities'.format(id)
43+
return self.client.request('get', endpoint, options)
44+
45+
def get_events(self, id, options=None):
46+
"""
47+
Get a message's events by its id
48+
49+
Args:
50+
id: The message ID
51+
52+
Returns:
53+
dict: paginated Event response from Knock.
54+
"""
55+
endpoint = '/messages/{}/events'.format(id)
56+
return self.client.request('get', endpoint, options)

knockapi/resources/objects.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def bulk_delete(self, collection, object_ids):
8484

8585
def get_channel_data(self, collection, id, channel_id):
8686
"""
87-
Get user's channel data for the given channel id.
87+
Get object's channel data for the given channel id.
8888
8989
Args:
9090
collection (str): The collection the object belongs to
@@ -99,7 +99,7 @@ def get_channel_data(self, collection, id, channel_id):
9999

100100
def set_channel_data(self, collection, id, channel_id, channel_data):
101101
"""
102-
Upserts user's channel data for the given channel id.
102+
Upserts object's channel data for the given channel id.
103103
104104
Args:
105105
collection (str): The collection the object belongs to
@@ -111,4 +111,23 @@ def set_channel_data(self, collection, id, channel_id, channel_data):
111111
dict: Channel data from Knock.
112112
"""
113113
endpoint = '/objects/{}/{}/channel_data/{}'.format(collection, id, channel_id)
114-
return self.client.request('put', endpoint, payload={'data': channel_data})
114+
return self.client.request('put', endpoint, payload={'data': channel_data})
115+
116+
##
117+
# Messages
118+
##
119+
120+
def get_messages(self, collection, id, options=None):
121+
"""
122+
Get object's messages
123+
124+
Args:
125+
collection (str): The collection the object belongs to
126+
id (str): The id of the object in the collection
127+
options (dict): An optional set of filtering options to pass to the query
128+
129+
Returns:
130+
dict: Paginated Message response.
131+
"""
132+
endpoint = '/objects/{}/{}/messages'.format(collection, id)
133+
return self.client.request('get', endpoint, payload=options)

knockapi/resources/users.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,3 +349,21 @@ def set_category_preferences(self, user_id, key, setting, options={}):
349349
params = setting if type(setting) is dict else {'subscribed': setting}
350350

351351
return self.client.request('put', endpoint, payload=params)
352+
353+
##
354+
# Messages
355+
##
356+
357+
def get_messages(self, id, options=None):
358+
"""
359+
Get user's messages
360+
361+
Args:
362+
id (str): The user ID
363+
options (dict): An optional set of filtering options to pass to the query
364+
365+
Returns:
366+
dict: Paginated Message response.
367+
"""
368+
endpoint = '/users/{}/messages'.format(id)
369+
return self.client.request('get', endpoint, payload=options)

0 commit comments

Comments
 (0)