knockapi 0.4.0 → 0.4.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/knock/client.rb +3 -1
- data/lib/knock/messages.rb +88 -0
- data/lib/knock/objects.rb +176 -1
- data/lib/knock/users.rb +52 -0
- data/lib/knock/version.rb +1 -1
- data/lib/knock/workflows.rb +1 -1
- data/lib/knock.rb +1 -0
- metadata +4 -3
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)
|
@@ -0,0 +1,88 @@
|
|
1
|
+
require "net/http"
|
2
|
+
require "uri"
|
3
|
+
|
4
|
+
module Knock
|
5
|
+
# Methods for interacting with messages in Knock
|
6
|
+
module Messages
|
7
|
+
class << self
|
8
|
+
include Base
|
9
|
+
include Client
|
10
|
+
|
11
|
+
# Retrieves a paginated list of messages for the provided environment
|
12
|
+
#
|
13
|
+
# @param [Hash] options Options to pass to the messages endpoint query
|
14
|
+
#
|
15
|
+
# @return [Hash] Paginated list of Message records
|
16
|
+
def list(options: {})
|
17
|
+
request = get_request(
|
18
|
+
auth: true,
|
19
|
+
path: "/v1/messages",
|
20
|
+
params: options
|
21
|
+
)
|
22
|
+
|
23
|
+
execute_request(request: request)
|
24
|
+
end
|
25
|
+
|
26
|
+
# Retrieves a Message
|
27
|
+
#
|
28
|
+
# @param [String] id The message id
|
29
|
+
#
|
30
|
+
# @return [Hash] The Message
|
31
|
+
def get(id:)
|
32
|
+
request = get_request(
|
33
|
+
auth: true,
|
34
|
+
path: "/v1/messages/#{id}"
|
35
|
+
)
|
36
|
+
|
37
|
+
execute_request(request: request)
|
38
|
+
end
|
39
|
+
|
40
|
+
# Get a Message's content
|
41
|
+
#
|
42
|
+
# @param [String] id The message id
|
43
|
+
#
|
44
|
+
# @return [Hash] The Message content
|
45
|
+
def get_content(id:)
|
46
|
+
request = get_request(
|
47
|
+
auth: true,
|
48
|
+
path: "/v1/messages/#{id}/content"
|
49
|
+
)
|
50
|
+
|
51
|
+
execute_request(request: request)
|
52
|
+
end
|
53
|
+
|
54
|
+
# Get a Message's activities
|
55
|
+
#
|
56
|
+
# @param [String] id The message id
|
57
|
+
# @param [Hash] options Options to pass to the paginated activities endpoint query
|
58
|
+
#
|
59
|
+
# @return [Hash] Paginated Message's activities
|
60
|
+
def get_activities(id:, options: {})
|
61
|
+
request = get_request(
|
62
|
+
auth: true,
|
63
|
+
path: "/v1/messages/#{id}/activities",
|
64
|
+
params: options
|
65
|
+
)
|
66
|
+
|
67
|
+
execute_request(request: request)
|
68
|
+
end
|
69
|
+
|
70
|
+
# Get a Message's events
|
71
|
+
#
|
72
|
+
# @param [String] id The message id
|
73
|
+
# @param [Hash] options Options to pass to the paginated events endpoint query
|
74
|
+
#
|
75
|
+
# @return [Hash] Paginated Message's events
|
76
|
+
def get_events(id:, options: {})
|
77
|
+
request = get_request(
|
78
|
+
auth: true,
|
79
|
+
path: "/v1/messages/#{id}/events",
|
80
|
+
params: options
|
81
|
+
)
|
82
|
+
|
83
|
+
execute_request(request: request)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
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}",
|
@@ -120,6 +122,179 @@ module Knock
|
|
120
122
|
|
121
123
|
execute_request(request: request)
|
122
124
|
end
|
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
|
+
|
142
|
+
# Get object's messages
|
143
|
+
#
|
144
|
+
# @param [String] collection The collection the object is in
|
145
|
+
# @param [String] id The object id
|
146
|
+
# @param [Hash] options Options to pass to the messages endpoint query
|
147
|
+
#
|
148
|
+
# @return [Hash] Paginated messages response
|
149
|
+
def get_messages(collection:, id:, options: {})
|
150
|
+
request = get_request(
|
151
|
+
auth: true,
|
152
|
+
path: "/v1/objects/#{collection}/#{id}/messages",
|
153
|
+
params: options
|
154
|
+
)
|
155
|
+
|
156
|
+
execute_request(request: request)
|
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
|
123
298
|
end
|
124
299
|
end
|
125
300
|
end
|
data/lib/knock/users.rb
CHANGED
@@ -101,6 +101,22 @@ module Knock
|
|
101
101
|
execute_request(request: request)
|
102
102
|
end
|
103
103
|
|
104
|
+
# Merges the user specified with `from_user_id` into the user specified with `user_id`.
|
105
|
+
#
|
106
|
+
# @param [String] id The user id to merge into.
|
107
|
+
# @param [String] from_user_id The user id to merge from
|
108
|
+
#
|
109
|
+
# @return [Hash] the merged User
|
110
|
+
def merge(id:, from_user_id:)
|
111
|
+
request = post_request(
|
112
|
+
auth: true,
|
113
|
+
path: "/v1/users/#{id}/merge",
|
114
|
+
body: {from_user_id: from_user_id}
|
115
|
+
)
|
116
|
+
|
117
|
+
execute_request(request: request)
|
118
|
+
end
|
119
|
+
|
104
120
|
##
|
105
121
|
# Preferences
|
106
122
|
##
|
@@ -300,6 +316,42 @@ module Knock
|
|
300
316
|
|
301
317
|
execute_request(request: request)
|
302
318
|
end
|
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
|
+
|
336
|
+
##
|
337
|
+
# Messages
|
338
|
+
##
|
339
|
+
|
340
|
+
# Get user's messages
|
341
|
+
#
|
342
|
+
# @param [String] id the user ID
|
343
|
+
# @param [Hash] options Options to pass to the messages endpoint query
|
344
|
+
#
|
345
|
+
# @return [Hash] Paginated messages response
|
346
|
+
def get_messages(id:, options: {})
|
347
|
+
request = get_request(
|
348
|
+
auth: true,
|
349
|
+
path: "/v1/users/#{id}/messages",
|
350
|
+
params: options
|
351
|
+
)
|
352
|
+
|
353
|
+
execute_request(request: request)
|
354
|
+
end
|
303
355
|
end
|
304
356
|
end
|
305
357
|
end
|
data/lib/knock/version.rb
CHANGED
data/lib/knock/workflows.rb
CHANGED
@@ -11,7 +11,7 @@ module Knock
|
|
11
11
|
# Triggers the workflow with the given key
|
12
12
|
#
|
13
13
|
# @param [String] key The workflow key
|
14
|
-
# @param [String, Hash] actor The actor identifier
|
14
|
+
# @param [String, Hash] actor The actor identifier (optional)
|
15
15
|
# @param [Array<String, Hash>] recipients The recipient identifiers
|
16
16
|
# @param [Hash] data The data to pass to the workflow
|
17
17
|
# @param [String] cancellation_key An optional key to identify this workflow
|
data/lib/knock.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
|
@@ -76,6 +76,7 @@ files:
|
|
76
76
|
- lib/knock/bulk_operations.rb
|
77
77
|
- lib/knock/client.rb
|
78
78
|
- lib/knock/errors.rb
|
79
|
+
- lib/knock/messages.rb
|
79
80
|
- lib/knock/objects.rb
|
80
81
|
- lib/knock/preferences.rb
|
81
82
|
- lib/knock/users.rb
|
@@ -101,7 +102,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
101
102
|
- !ruby/object:Gem::Version
|
102
103
|
version: '0'
|
103
104
|
requirements: []
|
104
|
-
rubygems_version: 3.3.
|
105
|
+
rubygems_version: 3.3.7
|
105
106
|
signing_key:
|
106
107
|
specification_version: 4
|
107
108
|
summary: API client for Knock
|