Skip to content

Commit 4cebdca

Browse files
authored
feat: add new users API for managing channel data (#4)
* Add new users API for managing channel data * Update README documentation about new API
1 parent 4219807 commit 4cebdca

File tree

4 files changed

+53
-5
lines changed

4 files changed

+53
-5
lines changed

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,25 @@ client.notify(
6666
"priority": 1
6767
}
6868
)
69+
70+
```
71+
### Getting and setting channel data
72+
73+
```python
74+
from knockapi import Knock
75+
client = Knock(api_key="sk_12345")
76+
77+
# Set channel data for an APNS
78+
client.users.set_channel_data(
79+
id="jhammond",
80+
channel_id=KNOCK_APNS_CHANNEL_ID,
81+
channel_data={
82+
"tokens": [apns_token]
83+
}
84+
)
85+
86+
# Get channel data for the APNS channel
87+
client.users.get_channel_data(id="jhammond", channel_id=KNOCK_APNS_CHANNEL_ID)
6988
```
7089

7190
### Canceling notifies

knockapi/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import requests
22

3-
__version__ = '0.2.2'
3+
__version__ = '0.3.0'
44

55

66
class Connection(object):

knockapi/resources/users.py

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ def get_user(self, id):
77
Get a user by their id
88
99
Args:
10-
id: The users ID
10+
id: The user ID
1111
1212
Returns:
1313
dict: User response from Knock.
@@ -20,7 +20,7 @@ def identify(self, id, data={}):
2020
Identify a user, upserting them
2121
2222
Args:
23-
id (str): The users ID
23+
id (str): The user ID
2424
data (dict): Other properties to put on the user
2525
2626
Returns:
@@ -34,10 +34,39 @@ def delete(self, id):
3434
Delets the given user.
3535
3636
Args:
37-
id (str): The users ID
37+
id (str): The user ID
3838
3939
Returns:
4040
dict: User response from Knock.
4141
"""
4242
endpoint = '/users/{}'.format(id)
4343
return self.client.request('delete', endpoint)
44+
45+
def get_channel_data(self, id, channel_id):
46+
"""
47+
Get user's channel data for the given channel id.
48+
49+
Args:
50+
id (str): The user ID
51+
channel_id (str): Target channel ID
52+
53+
Returns:
54+
dict: Channel data from Knock.
55+
"""
56+
endpoint = '/users/{}/channel_data/{}'.format(id, channel_id)
57+
return self.client.request('get', endpoint)
58+
59+
def set_channel_data(self, id, channel_id, channel_data):
60+
"""
61+
Upserts user's channel data for the given channel id.
62+
63+
Args:
64+
id (str): The user ID
65+
channel_id (str): Target channel ID
66+
channel_data (dict): Channel data
67+
68+
Returns:
69+
dict: Channel data from Knock.
70+
"""
71+
endpoint = '/users/{}/channel_data/{}'.format(id, channel_id)
72+
return self.client.request('put', endpoint, payload={'data': channel_data})

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from setuptools.command.install import install
66

7-
version = '0.2.2'
7+
version = '0.3.0'
88

99
with open("README.md", "r") as f:
1010
long_description = f.read()

0 commit comments

Comments
 (0)