|
1 | 1 | from .service import Service
|
2 |
| - |
3 |
| -default_set_id = "default" |
4 |
| - |
| 2 | +from warnings import warn |
5 | 3 |
|
6 | 4 | class Preferences(Service):
|
7 | 5 | def get_all(self, user_id):
|
8 |
| - """ |
9 |
| - Get a users full set of preferences |
10 |
| -
|
11 |
| - Args: |
12 |
| - user_id: The users ID |
13 |
| -
|
14 |
| - Returns: |
15 |
| - dict: User response from Knock. |
16 |
| - """ |
17 |
| - endpoint = '/users/{}/preferences'.format(user_id) |
18 |
| - return self.client.request('get', endpoint) |
| 6 | + warn("This method is deprecated. Use users.get_all_preferences instead.", DeprecationWarning, stacklevel=2) |
| 7 | + return self.client.users.get_all_preferences(user_id) |
19 | 8 |
|
20 | 9 | def get(self, user_id, options={}):
|
21 |
| - """ |
22 |
| - Get a users preference set |
23 |
| -
|
24 |
| - Args: |
25 |
| - user_id (str): The users ID |
26 |
| - options (dict): |
27 |
| - preference_set (str): The preference set to retrieve (defaults to "default") |
28 |
| -
|
29 |
| - Returns: |
30 |
| - dict: User response from Knock. |
31 |
| - """ |
32 |
| - preference_set_id = options.get('preference_set', default_set_id) |
33 |
| - endpoint = '/users/{}/preferences/{}'.format( |
34 |
| - user_id, preference_set_id) |
35 |
| - |
36 |
| - return self.client.request('get', endpoint) |
| 10 | + warn("This method is deprecated. Use users.get_preferences instead.", DeprecationWarning, stacklevel=2) |
| 11 | + return self.client.users.get_preferences(user_id, options) |
37 | 12 |
|
38 | 13 | def update(self, user_id, channel_types=None, categories=None, workflows=None, options={}):
|
39 |
| - """ |
40 |
| - Sets the preference set for the user |
41 |
| -
|
42 |
| - Args: |
43 |
| - user_id (str): The users ID |
44 |
| - channel_types (dict): A dictionary of channel type preferences |
45 |
| - categories (dict): A dictionary of category preferences |
46 |
| - workflows (dict): A dictionary of workflow preferences |
47 |
| - options (dict): A dictionary of options |
48 |
| -
|
49 |
| - Returns: |
50 |
| - dict: User response from Knock. |
51 |
| - """ |
52 |
| - preference_set_id = options.get('preference_set', default_set_id) |
53 |
| - |
54 |
| - endpoint = '/users/{}/preferences/{}'.format( |
55 |
| - user_id, preference_set_id) |
56 |
| - |
57 |
| - params = { |
58 |
| - 'channel_types': channel_types, |
59 |
| - 'categories': categories, |
60 |
| - 'workflows': workflows |
61 |
| - } |
62 |
| - |
63 |
| - return self.client.request('put', endpoint, payload=params) |
| 14 | + warn("This method is deprecated. Use users.set_preferences instead.", DeprecationWarning, stacklevel=2) |
| 15 | + return self.client.users.set_preferences(user_id, channel_types=channel_types, categories=categories, workflows=workflows, options=options) |
64 | 16 |
|
65 | 17 | def set_channel_types(self, user_id, preferences, options={}):
|
66 |
| - """ |
67 |
| - Sets the channel type preferences for the user |
68 |
| -
|
69 |
| - Args: |
70 |
| - user_id (str): The users ID |
71 |
| - preferences (dict): A dictionary of channel type preferences |
72 |
| - options (dict): A dictionary of options |
73 |
| -
|
74 |
| - Returns: |
75 |
| - dict: User response from Knock. |
76 |
| - """ |
77 |
| - preference_set_id = options.get('preference_set', default_set_id) |
78 |
| - |
79 |
| - endpoint = '/users/{}/preferences/{}/channel_types'.format( |
80 |
| - user_id, preference_set_id) |
81 |
| - |
82 |
| - return self.client.request('put', endpoint, payload=preferences) |
| 18 | + warn("This method is deprecated. Use users.set_channel_types_preferences instead.", DeprecationWarning, stacklevel=2) |
| 19 | + return self.client.users.set_channel_types_preferences(user_id, preferences, options=options) |
83 | 20 |
|
84 | 21 | def set_channel_type(self, user_id, channel_type, setting, options={}):
|
85 |
| - """ |
86 |
| - Sets the channel type preference for the user |
87 |
| -
|
88 |
| - Args: |
89 |
| - user_id (str): The users ID |
90 |
| - channel_type (str): The channel_type to set |
91 |
| - setting (boolean): The preference setting |
92 |
| - options (dict): A dictionary of options |
93 |
| -
|
94 |
| - Returns: |
95 |
| - dict: User response from Knock. |
96 |
| - """ |
97 |
| - preference_set_id = options.get('preference_set', default_set_id) |
98 |
| - |
99 |
| - endpoint = '/users/{}/preferences/{}/channel_types/{}'.format( |
100 |
| - user_id, preference_set_id, channel_type) |
101 |
| - |
102 |
| - return self.client.request('put', endpoint, payload={'subscribed': setting}) |
| 22 | + warn("This method is deprecated. Use users.set_channel_type_preferences instead.", DeprecationWarning, stacklevel=2) |
| 23 | + return self.client.users.set_channel_types_preferences(user_id, channel_type, setting, options=options) |
103 | 24 |
|
104 | 25 | def set_workflows(self, user_id, preferences, options={}):
|
105 |
| - """ |
106 |
| - Sets the workflow preferences for the user |
107 |
| -
|
108 |
| - Args: |
109 |
| - user_id (str): The users ID |
110 |
| - preferences (dict): A dictionary of workflow preferences |
111 |
| - options (dict): A dictionary of options |
112 |
| -
|
113 |
| - Returns: |
114 |
| - dict: User response from Knock. |
115 |
| - """ |
116 |
| - preference_set_id = options.get('preference_set', default_set_id) |
117 |
| - |
118 |
| - endpoint = '/users/{}/preferences/{}/workflows'.format( |
119 |
| - user_id, preference_set_id) |
120 |
| - |
121 |
| - return self.client.request('put', endpoint, payload=preferences) |
| 26 | + warn("This method is deprecated. Use users.set_workflows_preferences instead.", DeprecationWarning, stacklevel=2) |
| 27 | + return self.client.users.set_workflows_preferences(user_id, preferences, options=options) |
122 | 28 |
|
123 | 29 | def set_workflow(self, user_id, key, setting, options={}):
|
124 |
| - """ |
125 |
| - Sets the workflow preferences for the user |
126 |
| -
|
127 |
| - Args: |
128 |
| - user_id (str): The users ID |
129 |
| - key (str): The workflow key |
130 |
| - setting (boolean or dict): The preference setting |
131 |
| - options (dict): A dictionary of options |
132 |
| -
|
133 |
| - Returns: |
134 |
| - dict: User response from Knock. |
135 |
| - """ |
136 |
| - preference_set_id = options.get('preference_set', default_set_id) |
137 |
| - |
138 |
| - endpoint = '/users/{}/preferences/{}/workflows/{}'.format( |
139 |
| - user_id, preference_set_id, key) |
140 |
| - |
141 |
| - params = setting if type(setting) is dict else {'subscribed': setting} |
142 |
| - |
143 |
| - return self.client.request('put', endpoint, payload=params) |
| 30 | + warn("This method is deprecated. Use users.set_workflow_preferences instead.", DeprecationWarning, stacklevel=2) |
| 31 | + return self.client.users.set_workflow_preferences(user_id, key, setting, setting, options=options) |
144 | 32 |
|
145 | 33 | def set_categories(self, user_id, preferences, options={}):
|
146 |
| - """ |
147 |
| - Sets the categories preferences for the user |
148 |
| -
|
149 |
| - Args: |
150 |
| - user_id (str): The users ID |
151 |
| - preferences (dict): A dictionary of category preferences |
152 |
| - options (dict): A dictionary of options |
153 |
| -
|
154 |
| - Returns: |
155 |
| - dict: User response from Knock. |
156 |
| - """ |
157 |
| - preference_set_id = options.get('preference_set', default_set_id) |
158 |
| - |
159 |
| - endpoint = '/users/{}/preferences/{}/categories'.format( |
160 |
| - user_id, preference_set_id) |
161 |
| - |
162 |
| - return self.client.request('put', endpoint, payload=preferences) |
163 |
| - |
| 34 | + warn("This method is deprecated. Use users.set_categories_preferences instead.", DeprecationWarning, stacklevel=2) |
| 35 | + return self.client.users.set_categories_preferences(user_id, preferences, options=options) |
| 36 | + |
164 | 37 | def set_category(self, user_id, key, setting, options={}):
|
165 |
| - """ |
166 |
| - Sets the category preferences for the user |
167 |
| -
|
168 |
| - Args: |
169 |
| - user_id (str): The users ID |
170 |
| - key (str): The category key |
171 |
| - setting (boolean or dict): The preference setting |
172 |
| - options (dict): A dictionary of options |
173 |
| -
|
174 |
| - Returns: |
175 |
| - dict: User response from Knock. |
176 |
| - """ |
177 |
| - preference_set_id = options.get('preference_set', default_set_id) |
178 |
| - |
179 |
| - endpoint = '/users/{}/preferences/{}/categories/{}'.format( |
180 |
| - user_id, preference_set_id, key) |
181 |
| - |
182 |
| - params = setting if type(setting) is dict else {'subscribed': setting} |
183 |
| - |
184 |
| - return self.client.request('put', endpoint, payload=params) |
| 38 | + warn("This method is deprecated. Use users.set_category_preferences instead.", DeprecationWarning, stacklevel=2) |
| 39 | + return self.client.users.set_category_preferences(user_id, key, setting, setting, options=options) |
0 commit comments