knockapi 0.4.2 → 0.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/knock/client.rb +3 -1
- data/lib/knock/objects.rb +159 -1
- data/lib/knock/users.rb +17 -1
- data/lib/knock/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1bb4aabec2c7c629eb81d5471e1c1be91af2183336a751e212cf536299b2fd7e
|
4
|
+
data.tar.gz: 50f6206a65e9ffa3c7d2cf99692ad5acb6fd3d7c337304b6f4a814fa2ba756f6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 72a821d5baf5e43d50054f44193052e3eab317f59506a675085b481fec8490bec453ea2eaa01ff6b2a16df4aa7955f5f46544d93d193771e448915c520186b16
|
7
|
+
data.tar.gz: 94df91c57a491f60a2dd5a122b4b6d3cf37cda6a3f63e639b489b8d182c60dab4ed138dc9a48e8fab1be21a0ff10ab06b5bbd8edad393e8c297793bc1275770c
|
data/Gemfile.lock
CHANGED
data/lib/knock/client.rb
CHANGED
@@ -18,7 +18,9 @@ module Knock
|
|
18
18
|
http_status = response.code.to_i
|
19
19
|
handle_error_response(response: response) if http_status >= 400
|
20
20
|
|
21
|
-
|
21
|
+
if response.body and response.body != "" do
|
22
|
+
JSON.parse(response.body)
|
23
|
+
end
|
22
24
|
end
|
23
25
|
|
24
26
|
def get_request(path:, auth: false, params: {}, access_token: nil)
|
data/lib/knock/objects.rb
CHANGED
@@ -8,6 +8,8 @@ module Knock
|
|
8
8
|
include Base
|
9
9
|
include Client
|
10
10
|
|
11
|
+
DEFAULT_PREFERENCE_SET_ID = "default"
|
12
|
+
|
11
13
|
# Retrieves an Object in a collection
|
12
14
|
#
|
13
15
|
# @param [String] collection The collection the object is in
|
@@ -111,7 +113,7 @@ module Knock
|
|
111
113
|
# @param [Hash] channel_data channel data
|
112
114
|
#
|
113
115
|
# @return [Hash] channel data
|
114
|
-
def set_channel_data(id:, channel_id:, channel_data:)
|
116
|
+
def set_channel_data(collection:, id:, channel_id:, channel_data:)
|
115
117
|
request = put_request(
|
116
118
|
auth: true,
|
117
119
|
path: "/v1/objects/#{collection}/#{id}/channel_data/#{channel_id}",
|
@@ -121,6 +123,22 @@ module Knock
|
|
121
123
|
execute_request(request: request)
|
122
124
|
end
|
123
125
|
|
126
|
+
# Unsets object channel data for the given channel id
|
127
|
+
#
|
128
|
+
# @param [String] collection The collection the object is in
|
129
|
+
# @param [String] id The object id
|
130
|
+
# @param [String] channel_id target channel ID
|
131
|
+
#
|
132
|
+
# @return [Hash] channel data
|
133
|
+
def unset_channel_data(collection:, id:, channel_id:)
|
134
|
+
request = delete_request(
|
135
|
+
auth: true,
|
136
|
+
path: "/v1/objects/#{collection}/#{id}/channel_data/#{channel_id}"
|
137
|
+
)
|
138
|
+
|
139
|
+
execute_request(request: request)
|
140
|
+
end
|
141
|
+
|
124
142
|
# Get object's messages
|
125
143
|
#
|
126
144
|
# @param [String] collection The collection the object is in
|
@@ -137,6 +155,146 @@ module Knock
|
|
137
155
|
|
138
156
|
execute_request(request: request)
|
139
157
|
end
|
158
|
+
|
159
|
+
##
|
160
|
+
# Preferences
|
161
|
+
##
|
162
|
+
|
163
|
+
# Returns all preference sets for the object
|
164
|
+
#
|
165
|
+
# @param [String] collection The collection the object is in
|
166
|
+
# @param [String] id The object id
|
167
|
+
#
|
168
|
+
# @return [Array] The preference sets
|
169
|
+
def get_all_preferences(collection:, id:)
|
170
|
+
endpoint = "/v1/objects/#{collection}/#{id}/preferences"
|
171
|
+
|
172
|
+
request = get_request(
|
173
|
+
auth: true,
|
174
|
+
path: endpoint
|
175
|
+
)
|
176
|
+
|
177
|
+
execute_request(request: request)
|
178
|
+
end
|
179
|
+
|
180
|
+
# Gets a single preference set, defaults to the 'default' set
|
181
|
+
# for the object given.
|
182
|
+
#
|
183
|
+
# @param [String] collection The collection the object is in
|
184
|
+
# @param [String] id The object id
|
185
|
+
# @param [String] preference_set The preference set ID (defaults to `default`)
|
186
|
+
#
|
187
|
+
# @return [Hash] The preference set (if it exists)
|
188
|
+
def get_preferences(collection:, id:, preference_set: DEFAULT_PREFERENCE_SET_ID)
|
189
|
+
endpoint = "/v1/objects/#{collection}/#{id}/preferences/#{preference_set}"
|
190
|
+
|
191
|
+
request = get_request(
|
192
|
+
auth: true,
|
193
|
+
path: endpoint
|
194
|
+
)
|
195
|
+
|
196
|
+
execute_request(request: request)
|
197
|
+
end
|
198
|
+
|
199
|
+
# Sets multiple preferences at once for the preference set.
|
200
|
+
#
|
201
|
+
# @param [String] collection The collection the object is in
|
202
|
+
# @param [String] id The object id
|
203
|
+
# @param [String] preference_set The preference set ID (defaults to `default`)
|
204
|
+
# @param [Hash] channel_types The channel_types hash to set
|
205
|
+
# @param [Hash] workflows The workflows hash to set
|
206
|
+
# @param [Hash] categories The categories hash to set
|
207
|
+
#
|
208
|
+
# @return [Hash] The preference set
|
209
|
+
def set_preferences(
|
210
|
+
collection:,
|
211
|
+
id:,
|
212
|
+
channel_types: nil,
|
213
|
+
workflows: nil,
|
214
|
+
categories: nil,
|
215
|
+
preference_set: DEFAULT_PREFERENCE_SET_ID
|
216
|
+
)
|
217
|
+
endpoint = "/v1/objects/#{collection}/#{id}/preferences/#{preference_set}"
|
218
|
+
|
219
|
+
request = put_request(
|
220
|
+
auth: true,
|
221
|
+
path: endpoint,
|
222
|
+
body: {
|
223
|
+
channel_types: channel_types,
|
224
|
+
workflows: workflows,
|
225
|
+
categories: categories
|
226
|
+
}
|
227
|
+
)
|
228
|
+
|
229
|
+
execute_request(request: request)
|
230
|
+
end
|
231
|
+
|
232
|
+
# Sets preferences for the given channel type
|
233
|
+
#
|
234
|
+
# @param [String] collection The collection the object is in
|
235
|
+
# @param [String] id The object id
|
236
|
+
# @param [String] preference_set The preference set ID (defaults to `default`)
|
237
|
+
# @param [String] channel_type The channel type to set
|
238
|
+
# @param [Bool] setting Whether the channel type is enabled or not
|
239
|
+
#
|
240
|
+
# @return [Hash] The preference set
|
241
|
+
def set_channel_type_preferences(collection:, id:, channel_type:, setting:, preference_set: DEFAULT_PREFERENCE_SET_ID)
|
242
|
+
endpoint = "/v1/objects/#{collection}/#{id}/preferences/#{preference_set}/channel_types/#{channel_type}"
|
243
|
+
|
244
|
+
request = put_request(
|
245
|
+
auth: true,
|
246
|
+
path: endpoint,
|
247
|
+
body: {subscribed: setting}
|
248
|
+
)
|
249
|
+
|
250
|
+
execute_request(request: request)
|
251
|
+
end
|
252
|
+
|
253
|
+
# Sets preferences for the given workflow
|
254
|
+
#
|
255
|
+
# @param [String] collection The collection the object is in
|
256
|
+
# @param [String] id The object id
|
257
|
+
# @param [String] preference_set The preference set ID (defaults to `default`)
|
258
|
+
# @param [String] workflow The workflow to set preferences for
|
259
|
+
# @param [Bool | Hash] setting Either a boolean to indicate if the type is enabled
|
260
|
+
# or a hash containing channel types and settings
|
261
|
+
#
|
262
|
+
# @return [Hash] The preference set
|
263
|
+
def set_workflow_preferences(collection:, id:, workflow:, setting:, preference_set: DEFAULT_PREFERENCE_SET_ID)
|
264
|
+
params = setting.is_a?(Hash) ? setting : {subscribed: setting}
|
265
|
+
endpoint = "/v1/objects/#{collection}/#{id}/preferences/#{preference_set}/workflows/#{workflow}"
|
266
|
+
|
267
|
+
request = put_request(
|
268
|
+
auth: true,
|
269
|
+
path: endpoint,
|
270
|
+
body: params
|
271
|
+
)
|
272
|
+
|
273
|
+
execute_request(request: request)
|
274
|
+
end
|
275
|
+
|
276
|
+
# Sets preferences for the given category
|
277
|
+
#
|
278
|
+
# @param [String] collection The collection the object is in
|
279
|
+
# @param [String] id The object id
|
280
|
+
# @param [String] preference_set The preference set ID (defaults to `default`)
|
281
|
+
# @param [String] category The category to set preferences for
|
282
|
+
# @param [Bool | Hash] setting Either a boolean to indicate if the type is enabled
|
283
|
+
# or a hash containing channel types and settings
|
284
|
+
#
|
285
|
+
# @return [Hash] The preference set
|
286
|
+
def set_category_preferences(collection:, id:, category:, setting:, preference_set: DEFAULT_PREFERENCE_SET_ID)
|
287
|
+
params = setting.is_a?(Hash) ? setting : {subscribed: setting}
|
288
|
+
endpoint = "/v1/objects/#{collection}/#{id}/preferences/#{preference_set}/categories/#{category}"
|
289
|
+
|
290
|
+
request = put_request(
|
291
|
+
auth: true,
|
292
|
+
path: endpoint,
|
293
|
+
body: params
|
294
|
+
)
|
295
|
+
|
296
|
+
execute_request(request: request)
|
297
|
+
end
|
140
298
|
end
|
141
299
|
end
|
142
300
|
end
|
data/lib/knock/users.rb
CHANGED
@@ -111,7 +111,7 @@ module Knock
|
|
111
111
|
request = post_request(
|
112
112
|
auth: true,
|
113
113
|
path: "/v1/users/#{id}/merge",
|
114
|
-
body: {
|
114
|
+
body: {from_user_id: from_user_id}
|
115
115
|
)
|
116
116
|
|
117
117
|
execute_request(request: request)
|
@@ -317,6 +317,22 @@ module Knock
|
|
317
317
|
execute_request(request: request)
|
318
318
|
end
|
319
319
|
|
320
|
+
# Unsets user's channel data for the given channel id
|
321
|
+
#
|
322
|
+
# @param [String] id the user ID
|
323
|
+
# @param [String] channel_id target channel ID
|
324
|
+
# @param [Hash] channel_data channel data
|
325
|
+
#
|
326
|
+
# @return [Hash] channel data
|
327
|
+
def unset_channel_data(id:, channel_id:)
|
328
|
+
request = delete_request(
|
329
|
+
auth: true,
|
330
|
+
path: "/v1/users/#{id}/channel_data/#{channel_id}"
|
331
|
+
)
|
332
|
+
|
333
|
+
execute_request(request: request)
|
334
|
+
end
|
335
|
+
|
320
336
|
##
|
321
337
|
# Messages
|
322
338
|
##
|
data/lib/knock/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: knockapi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Knock Labs, Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-05-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|