knockapi 0.3.0 → 0.4.0
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 +2 -1
- data/README.md +2 -2
- data/lib/knock/bulk_operations.rb +26 -0
- data/lib/knock/objects.rb +125 -0
- data/lib/knock/preferences.rb +39 -67
- data/lib/knock/users.rb +219 -2
- data/lib/knock/version.rb +1 -1
- data/lib/knock/workflows.rb +3 -3
- data/lib/knock.rb +2 -0
- metadata +8 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4565e1e9c707c9edcb5fad6fbe69c90dfabce8362507b7a1b817c1bf6440e094
|
4
|
+
data.tar.gz: cdf934876f3e28a57ac42e8f6af8746f1ff9114987f692d1d419ff2cdec2cf49
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c3e4cbf5daa9efb7c4c4ab1742ee403e2a3e7bd628c2b5540e93bfe6702dd99e4aae7a8748ced4bd5bd31942c454964ede695eceacf978e89ec608d39cc72520
|
7
|
+
data.tar.gz: 04d8e14f0c4244897f0a5f8083fd993a2aa306506c755f81163bc739f5b357b5a621cb10b2493c3b9a6916269f1eed710a9823798cf4c1292550363bdd327083
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -98,7 +98,7 @@ require "knockapi"
|
|
98
98
|
Knock.key = "sk_12345"
|
99
99
|
|
100
100
|
# Set an entire preference set
|
101
|
-
Knock::
|
101
|
+
Knock::Users.set_preferences(
|
102
102
|
user_id: "jhammond",
|
103
103
|
channel_types: { email: true, sms: false },
|
104
104
|
workflows: {
|
@@ -109,7 +109,7 @@ Knock::Preferences.set(
|
|
109
109
|
)
|
110
110
|
|
111
111
|
# Get an entire preference set
|
112
|
-
Knock::
|
112
|
+
Knock::Users.get_preferences(user_id: "jhammond")
|
113
113
|
```
|
114
114
|
|
115
115
|
### Getting and setting channel data
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require "net/http"
|
2
|
+
require "uri"
|
3
|
+
|
4
|
+
module Knock
|
5
|
+
# Provides convienience methods for working with bulk operations
|
6
|
+
module BulkOperations
|
7
|
+
class << self
|
8
|
+
include Base
|
9
|
+
include Client
|
10
|
+
|
11
|
+
# Retrieves the given bulk operation
|
12
|
+
#
|
13
|
+
# @param [String] id The bulk operation ID
|
14
|
+
#
|
15
|
+
# @return [Hash] The bulk operation
|
16
|
+
def get(id:)
|
17
|
+
request = get_request(
|
18
|
+
auth: true,
|
19
|
+
path: "/v1/bulk_operations/#{id}"
|
20
|
+
)
|
21
|
+
|
22
|
+
execute_request(request: request)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,125 @@
|
|
1
|
+
require "net/http"
|
2
|
+
require "uri"
|
3
|
+
|
4
|
+
module Knock
|
5
|
+
# Provides convienience methods for working with bulk operations
|
6
|
+
module Objects
|
7
|
+
class << self
|
8
|
+
include Base
|
9
|
+
include Client
|
10
|
+
|
11
|
+
# Retrieves an Object in a collection
|
12
|
+
#
|
13
|
+
# @param [String] collection The collection the object is in
|
14
|
+
# @param [String] id The object id
|
15
|
+
#
|
16
|
+
# @return [Hash] The Object
|
17
|
+
def get(collection:, id:)
|
18
|
+
request = get_request(
|
19
|
+
auth: true,
|
20
|
+
path: "/v1/objects/#{collection}/#{id}"
|
21
|
+
)
|
22
|
+
|
23
|
+
execute_request(request: request)
|
24
|
+
end
|
25
|
+
|
26
|
+
# Upserts an Object in a collection
|
27
|
+
#
|
28
|
+
# @param [String] collection The collection the object is in
|
29
|
+
# @param [String] id The object id
|
30
|
+
# @param [Hash] properties The properties to set on the object
|
31
|
+
#
|
32
|
+
# @return [Hash] The Object
|
33
|
+
def set(collection:, id:, properties: {})
|
34
|
+
request = put_request(
|
35
|
+
auth: true,
|
36
|
+
path: "/v1/objects/#{collection}/#{id}",
|
37
|
+
body: properties
|
38
|
+
)
|
39
|
+
|
40
|
+
execute_request(request: request)
|
41
|
+
end
|
42
|
+
|
43
|
+
# Bulk upserts Objects in a collection
|
44
|
+
#
|
45
|
+
# @param [String] collection The collection the object is in
|
46
|
+
# @param [Array<Hash>] objects The objects to upsert
|
47
|
+
#
|
48
|
+
# @return [Hash] a BulkOperation
|
49
|
+
def bulk_set(collection:, objects: [])
|
50
|
+
request = post_request(
|
51
|
+
auth: true,
|
52
|
+
path: "/v1/objects/#{collection}/bulk/set",
|
53
|
+
body: {objects: objects}
|
54
|
+
)
|
55
|
+
|
56
|
+
execute_request(request: request)
|
57
|
+
end
|
58
|
+
|
59
|
+
# Deletes an Object in a collection
|
60
|
+
#
|
61
|
+
# @param [String] collection The collection the object is in
|
62
|
+
# @param [String] id The object id
|
63
|
+
#
|
64
|
+
# @return [nil] Nothing
|
65
|
+
def delete(collection:, id:)
|
66
|
+
request = delete_request(
|
67
|
+
auth: true,
|
68
|
+
path: "/v1/objects/#{collection}/#{id}"
|
69
|
+
)
|
70
|
+
|
71
|
+
execute_request(request: request)
|
72
|
+
end
|
73
|
+
|
74
|
+
# Bulk deletes Objects in a collection
|
75
|
+
#
|
76
|
+
# @param [String] collection The collection the object is in
|
77
|
+
# @param [Array<String>] object_ids The object ids to delete
|
78
|
+
#
|
79
|
+
# @return [Hash] a BulkOperation
|
80
|
+
def bulk_delete(collection:, object_ids: [])
|
81
|
+
request = post_request(
|
82
|
+
auth: true,
|
83
|
+
path: "/v1/objects/#{collection}/bulk/delete",
|
84
|
+
body: {object_ids: object_ids}
|
85
|
+
)
|
86
|
+
|
87
|
+
execute_request(request: request)
|
88
|
+
end
|
89
|
+
|
90
|
+
# Get object channel data for the given channel id
|
91
|
+
#
|
92
|
+
# @param [String] collection The collection the object is in
|
93
|
+
# @param [String] id The object id
|
94
|
+
# @param [String] channel_id target channel ID
|
95
|
+
#
|
96
|
+
# @return [Hash] channel data
|
97
|
+
def get_channel_data(collection:, id:, channel_id:)
|
98
|
+
request = get_request(
|
99
|
+
auth: true,
|
100
|
+
path: "/v1/objects/#{collection}/#{id}/channel_data/#{channel_id}"
|
101
|
+
)
|
102
|
+
|
103
|
+
execute_request(request: request)
|
104
|
+
end
|
105
|
+
|
106
|
+
# Upserts object channel data for the given channel id
|
107
|
+
#
|
108
|
+
# @param [String] collection The collection the object is in
|
109
|
+
# @param [String] id The object id
|
110
|
+
# @param [String] channel_id target channel ID
|
111
|
+
# @param [Hash] channel_data channel data
|
112
|
+
#
|
113
|
+
# @return [Hash] channel data
|
114
|
+
def set_channel_data(id:, channel_id:, channel_data:)
|
115
|
+
request = put_request(
|
116
|
+
auth: true,
|
117
|
+
path: "/v1/objects/#{collection}/#{id}/channel_data/#{channel_id}",
|
118
|
+
body: {data: channel_data}
|
119
|
+
)
|
120
|
+
|
121
|
+
execute_request(request: request)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
data/lib/knock/preferences.rb
CHANGED
@@ -2,28 +2,20 @@ require "net/http"
|
|
2
2
|
require "uri"
|
3
3
|
|
4
4
|
module Knock
|
5
|
-
# Provides convienience methods for working with preferences
|
5
|
+
# Provides convienience methods for working with preferences (deprecated)
|
6
6
|
module Preferences
|
7
7
|
class << self
|
8
8
|
include Base
|
9
9
|
include Client
|
10
10
|
|
11
|
-
DEFAULT_SET_ID = "default"
|
12
|
-
|
13
11
|
# Returns all preference sets for the user
|
14
12
|
#
|
15
13
|
# @param [String] user_id The ID of the user to retrieve preferences for
|
16
14
|
#
|
17
15
|
# @return [Hash] The preference sets
|
16
|
+
# @deprecated Please use {#Knock::Users.get_all_preferences} instead
|
18
17
|
def get_all(user_id:)
|
19
|
-
|
20
|
-
|
21
|
-
request = get_request(
|
22
|
-
auth: true,
|
23
|
-
path: endpoint
|
24
|
-
)
|
25
|
-
|
26
|
-
execute_request(request: request)
|
18
|
+
Knock::Users.get_all_preferences(user_id: user_id)
|
27
19
|
end
|
28
20
|
|
29
21
|
# Gets a single preference set, defaults to the 'default' set
|
@@ -33,15 +25,9 @@ module Knock
|
|
33
25
|
# @param [String] preference_set The preference set ID (defaults to `default`)
|
34
26
|
#
|
35
27
|
# @return [Hash] The preference set (if it exists)
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
request = get_request(
|
40
|
-
auth: true,
|
41
|
-
path: endpoint
|
42
|
-
)
|
43
|
-
|
44
|
-
execute_request(request: request)
|
28
|
+
# @deprecated Please use {#Knock::Users.get_preferences} instead
|
29
|
+
def get(user_id:, preference_set:)
|
30
|
+
Knock::Users.get_preferences(user_id: user_id, preference_set: preference_set)
|
45
31
|
end
|
46
32
|
|
47
33
|
# Sets multiple preferences at once for the preference set.
|
@@ -51,26 +37,20 @@ module Knock
|
|
51
37
|
# @param [Hash] preferences The preferences hash to set
|
52
38
|
#
|
53
39
|
# @return [Hash] The preference set
|
40
|
+
# @deprecated Please use {#Knock::Users.set_preferences} instead
|
54
41
|
def update(
|
55
42
|
user_id:,
|
56
|
-
channel_types: nil,
|
43
|
+
preference_set:, channel_types: nil,
|
57
44
|
workflows: nil,
|
58
|
-
categories: nil
|
59
|
-
preference_set: DEFAULT_SET_ID
|
45
|
+
categories: nil
|
60
46
|
)
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
channel_types: channel_types,
|
68
|
-
workflows: workflows,
|
69
|
-
categories: categories
|
70
|
-
}
|
47
|
+
Knock::Users.set_preferences(
|
48
|
+
user_id: user_id,
|
49
|
+
channel_types: channel_types,
|
50
|
+
workflows: workflows,
|
51
|
+
categories: categories,
|
52
|
+
preference_set: preference_set
|
71
53
|
)
|
72
|
-
|
73
|
-
execute_request(request: request)
|
74
54
|
end
|
75
55
|
|
76
56
|
# Sets preferences for the given channel type
|
@@ -80,17 +60,15 @@ module Knock
|
|
80
60
|
# @param [String] channel_type The channel type to set
|
81
61
|
# @param [Bool] setting Whether the channel type is enabled or not
|
82
62
|
#
|
83
|
-
#
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
63
|
+
# @return [Hash] The preference set
|
64
|
+
# @deprecated Please use {#Knock::Users.set_channel_type_preferences} instead
|
65
|
+
def set_channel_type(user_id:, channel_type:, setting:, preference_set:)
|
66
|
+
Knock::Users.set_channel_type_preferences(
|
67
|
+
user_id: user_id,
|
68
|
+
channel_type: channel_type,
|
69
|
+
setting: setting,
|
70
|
+
preference_set: preference_set
|
91
71
|
)
|
92
|
-
|
93
|
-
execute_request(request: request)
|
94
72
|
end
|
95
73
|
|
96
74
|
# Sets preferences for the given workflow
|
@@ -101,18 +79,15 @@ module Knock
|
|
101
79
|
# @param [Bool | Hash] setting Either a boolean to indicate if the type is enabled
|
102
80
|
# or a hash containing channel types and settings
|
103
81
|
#
|
104
|
-
#
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
body: params
|
82
|
+
# @return [Hash] The preference set
|
83
|
+
# @deprecated Please use {#Knock::Users.set_workflow_preferences} instead
|
84
|
+
def set_workflow(user_id:, workflow:, setting:, preference_set:)
|
85
|
+
Knock::Users.set_workflow_preferences(
|
86
|
+
user_id: user_id,
|
87
|
+
workflow: workflow,
|
88
|
+
setting: setting,
|
89
|
+
preference_set: preference_set
|
113
90
|
)
|
114
|
-
|
115
|
-
execute_request(request: request)
|
116
91
|
end
|
117
92
|
|
118
93
|
# Sets preferences for the given category
|
@@ -123,18 +98,15 @@ module Knock
|
|
123
98
|
# @param [Bool | Hash] setting Either a boolean to indicate if the type is enabled
|
124
99
|
# or a hash containing channel types and settings
|
125
100
|
#
|
126
|
-
#
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
body: params
|
101
|
+
# @return [Hash] The preference set
|
102
|
+
# @deprecated Please use {#Knock::Users.set_category_preferences} instead
|
103
|
+
def set_category(user_id:, category:, setting:, preference_set:)
|
104
|
+
Knock::Users.set_category_preferences(
|
105
|
+
user_id: user_id,
|
106
|
+
category: category,
|
107
|
+
setting: setting,
|
108
|
+
preference_set: preference_set
|
135
109
|
)
|
136
|
-
|
137
|
-
execute_request(request: request)
|
138
110
|
end
|
139
111
|
end
|
140
112
|
end
|
data/lib/knock/users.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
|
# Identifies the user
|
12
14
|
#
|
13
15
|
# @param [String] id The user ID
|
@@ -24,6 +26,21 @@ module Knock
|
|
24
26
|
execute_request(request: request)
|
25
27
|
end
|
26
28
|
|
29
|
+
# Bulk identifies users
|
30
|
+
#
|
31
|
+
# @param [Array<Hash>] users The users to upsert
|
32
|
+
#
|
33
|
+
# @return [Hash] the BulkOperation
|
34
|
+
def bulk_identify(users: [])
|
35
|
+
request = post_request(
|
36
|
+
auth: true,
|
37
|
+
path: "/v1/users/bulk/identify",
|
38
|
+
body: {users: users}
|
39
|
+
)
|
40
|
+
|
41
|
+
execute_request(request: request)
|
42
|
+
end
|
43
|
+
|
27
44
|
# Retrieves the given user
|
28
45
|
#
|
29
46
|
# @param [String] id The user ID
|
@@ -52,6 +69,206 @@ module Knock
|
|
52
69
|
execute_request(request: request)
|
53
70
|
end
|
54
71
|
|
72
|
+
# Bulk deletes users
|
73
|
+
#
|
74
|
+
# @param [Array<String>] user_ids The users to delete
|
75
|
+
#
|
76
|
+
# @return [Hash] the BulkOperation
|
77
|
+
def bulk_delete(user_ids: [])
|
78
|
+
request = post_request(
|
79
|
+
auth: true,
|
80
|
+
path: "/v1/users/bulk/delete",
|
81
|
+
body: {user_ids: user_ids}
|
82
|
+
)
|
83
|
+
|
84
|
+
execute_request(request: request)
|
85
|
+
end
|
86
|
+
|
87
|
+
# Gets a feed for a user
|
88
|
+
#
|
89
|
+
# @param [String] id The user id
|
90
|
+
# @param [String] channel_id The feed id to retrieve
|
91
|
+
# @param [Hash] options Options to pass to the feed query
|
92
|
+
#
|
93
|
+
# @return [Hash] the feed response
|
94
|
+
def get_feed(id:, channel_id:, options: {})
|
95
|
+
request = get_request(
|
96
|
+
auth: true,
|
97
|
+
path: "/v1/users/#{id}/feeds/#{channel_id}",
|
98
|
+
params: options
|
99
|
+
)
|
100
|
+
|
101
|
+
execute_request(request: request)
|
102
|
+
end
|
103
|
+
|
104
|
+
##
|
105
|
+
# Preferences
|
106
|
+
##
|
107
|
+
|
108
|
+
# Returns all preference sets for the user
|
109
|
+
#
|
110
|
+
# @param [String] user_id The ID of the user to retrieve preferences for
|
111
|
+
#
|
112
|
+
# @return [Hash] The preference sets
|
113
|
+
def get_all_preferences(user_id:)
|
114
|
+
endpoint = "/v1/users/#{user_id}/preferences"
|
115
|
+
|
116
|
+
request = get_request(
|
117
|
+
auth: true,
|
118
|
+
path: endpoint
|
119
|
+
)
|
120
|
+
|
121
|
+
execute_request(request: request)
|
122
|
+
end
|
123
|
+
|
124
|
+
# Gets a single preference set, defaults to the 'default' set
|
125
|
+
# for the user given.
|
126
|
+
#
|
127
|
+
# @param [String] user_id The ID of the user to retrieve preferences for
|
128
|
+
# @param [String] preference_set The preference set ID (defaults to `default`)
|
129
|
+
#
|
130
|
+
# @return [Hash] The preference set (if it exists)
|
131
|
+
def get_preferences(user_id:, preference_set: DEFAULT_PREFERENCE_SET_ID)
|
132
|
+
endpoint = "/v1/users/#{user_id}/preferences/#{preference_set}"
|
133
|
+
|
134
|
+
request = get_request(
|
135
|
+
auth: true,
|
136
|
+
path: endpoint
|
137
|
+
)
|
138
|
+
|
139
|
+
execute_request(request: request)
|
140
|
+
end
|
141
|
+
|
142
|
+
# Sets multiple preferences at once for the preference set.
|
143
|
+
#
|
144
|
+
# @param [String] user_id The ID of the user to set preferences for
|
145
|
+
# @param [String] preference_set The preference set ID (defaults to `default`)
|
146
|
+
# @param [Hash] channel_types The channel_types hash to set
|
147
|
+
# @param [Hash] workflows The workflows hash to set
|
148
|
+
# @param [Hash] categories The categories hash to set
|
149
|
+
#
|
150
|
+
# @return [Hash] The preference set
|
151
|
+
def set_preferences(
|
152
|
+
user_id:,
|
153
|
+
channel_types: nil,
|
154
|
+
workflows: nil,
|
155
|
+
categories: nil,
|
156
|
+
preference_set: DEFAULT_PREFERENCE_SET_ID
|
157
|
+
)
|
158
|
+
endpoint = "/v1/users/#{user_id}/preferences/#{preference_set}"
|
159
|
+
|
160
|
+
request = put_request(
|
161
|
+
auth: true,
|
162
|
+
path: endpoint,
|
163
|
+
body: {
|
164
|
+
channel_types: channel_types,
|
165
|
+
workflows: workflows,
|
166
|
+
categories: categories
|
167
|
+
}
|
168
|
+
)
|
169
|
+
|
170
|
+
execute_request(request: request)
|
171
|
+
end
|
172
|
+
|
173
|
+
# Bulk sets the preference object for the users.
|
174
|
+
#
|
175
|
+
# @param [Array<String>] user_ids The ID of the user to set preferences for
|
176
|
+
# @param [Hash] preferences The preferences hash to set
|
177
|
+
# @param [String] preference_set The preference set ID (defaults to `default`)
|
178
|
+
#
|
179
|
+
# @return [Hash] BulkOperation
|
180
|
+
def bulk_set_preferences(
|
181
|
+
user_ids: [],
|
182
|
+
preferences: {},
|
183
|
+
preference_set: DEFAULT_PREFERENCE_SET_ID
|
184
|
+
)
|
185
|
+
endpoint = "/v1/users/bulk/preferences"
|
186
|
+
|
187
|
+
# Put the preference set id if it doesn't already exist
|
188
|
+
unless preferences.has_key("id")
|
189
|
+
preferences["id"] = preference_set
|
190
|
+
end
|
191
|
+
|
192
|
+
request = put_request(
|
193
|
+
auth: true,
|
194
|
+
path: endpoint,
|
195
|
+
body: {
|
196
|
+
user_ids: user_ids,
|
197
|
+
preferences: preferences
|
198
|
+
}
|
199
|
+
)
|
200
|
+
|
201
|
+
execute_request(request: request)
|
202
|
+
end
|
203
|
+
|
204
|
+
# Sets preferences for the given channel type
|
205
|
+
#
|
206
|
+
# @param [String] user_id The ID of the user to set preferences for
|
207
|
+
# @param [String] preference_set The preference set ID (defaults to `default`)
|
208
|
+
# @param [String] channel_type The channel type to set
|
209
|
+
# @param [Bool] setting Whether the channel type is enabled or not
|
210
|
+
#
|
211
|
+
# @return [Hash] The preference set
|
212
|
+
def set_channel_type_preferences(user_id:, channel_type:, setting:, preference_set: DEFAULT_PREFERENCE_SET_ID)
|
213
|
+
endpoint = "/v1/users/#{user_id}/preferences/#{preference_set}/channel_types/#{channel_type}"
|
214
|
+
|
215
|
+
request = put_request(
|
216
|
+
auth: true,
|
217
|
+
path: endpoint,
|
218
|
+
body: {subscribed: setting}
|
219
|
+
)
|
220
|
+
|
221
|
+
execute_request(request: request)
|
222
|
+
end
|
223
|
+
|
224
|
+
# Sets preferences for the given workflow
|
225
|
+
#
|
226
|
+
# @param [String] user_id The ID of the user to set preferences for
|
227
|
+
# @param [String] preference_set The preference set ID (defaults to `default`)
|
228
|
+
# @param [String] workflow The workflow to set preferences for
|
229
|
+
# @param [Bool | Hash] setting Either a boolean to indicate if the type is enabled
|
230
|
+
# or a hash containing channel types and settings
|
231
|
+
#
|
232
|
+
# @return [Hash] The preference set
|
233
|
+
def set_workflow_preferences(user_id:, workflow:, setting:, preference_set: DEFAULT_PREFERENCE_SET_ID)
|
234
|
+
params = setting.is_a?(Hash) ? setting : {subscribed: setting}
|
235
|
+
endpoint = "/v1/users/#{user_id}/preferences/#{preference_set}/workflows/#{workflow}"
|
236
|
+
|
237
|
+
request = put_request(
|
238
|
+
auth: true,
|
239
|
+
path: endpoint,
|
240
|
+
body: params
|
241
|
+
)
|
242
|
+
|
243
|
+
execute_request(request: request)
|
244
|
+
end
|
245
|
+
|
246
|
+
# Sets preferences for the given category
|
247
|
+
#
|
248
|
+
# @param [String] user_id The ID of the user to set preferences for
|
249
|
+
# @param [String] preference_set The preference set ID (defaults to `default`)
|
250
|
+
# @param [String] category The category to set preferences for
|
251
|
+
# @param [Bool | Hash] setting Either a boolean to indicate if the type is enabled
|
252
|
+
# or a hash containing channel types and settings
|
253
|
+
#
|
254
|
+
# @return [Hash] The preference set
|
255
|
+
def set_category_preferences(user_id:, category:, setting:, preference_set: DEFAULT_PREFERENCE_SET_ID)
|
256
|
+
params = setting.is_a?(Hash) ? setting : {subscribed: setting}
|
257
|
+
endpoint = "/v1/users/#{user_id}/preferences/#{preference_set}/categories/#{category}"
|
258
|
+
|
259
|
+
request = put_request(
|
260
|
+
auth: true,
|
261
|
+
path: endpoint,
|
262
|
+
body: params
|
263
|
+
)
|
264
|
+
|
265
|
+
execute_request(request: request)
|
266
|
+
end
|
267
|
+
|
268
|
+
##
|
269
|
+
# Channel data
|
270
|
+
##
|
271
|
+
|
55
272
|
# Get user's channel data for the given channel id
|
56
273
|
#
|
57
274
|
# @param [String] id the user ID
|
@@ -71,14 +288,14 @@ module Knock
|
|
71
288
|
#
|
72
289
|
# @param [String] id the user ID
|
73
290
|
# @param [String] channel_id target channel ID
|
74
|
-
# @param [
|
291
|
+
# @param [Hash] channel_data channel data
|
75
292
|
#
|
76
293
|
# @return [Hash] channel data
|
77
294
|
def set_channel_data(id:, channel_id:, channel_data:)
|
78
295
|
request = put_request(
|
79
296
|
auth: true,
|
80
297
|
path: "/v1/users/#{id}/channel_data/#{channel_id}",
|
81
|
-
body: {
|
298
|
+
body: {data: channel_data}
|
82
299
|
)
|
83
300
|
|
84
301
|
execute_request(request: request)
|
data/lib/knock/version.rb
CHANGED
data/lib/knock/workflows.rb
CHANGED
@@ -11,8 +11,8 @@ module Knock
|
|
11
11
|
# Triggers the workflow with the given key
|
12
12
|
#
|
13
13
|
# @param [String] key The workflow key
|
14
|
-
# @param [String] actor The actor
|
15
|
-
# @param [Array<String>] recipients The recipient
|
14
|
+
# @param [String, Hash] actor The actor identifier
|
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
|
18
18
|
# invocation for cancelling
|
@@ -41,7 +41,7 @@ module Knock
|
|
41
41
|
#
|
42
42
|
# @param [String] key The workflow key
|
43
43
|
# @param [String] cancellation_key The cancellation key
|
44
|
-
# @param [Array<String>] recipients The recipient
|
44
|
+
# @param [Array<String, Hash>] recipients The recipient identifiers
|
45
45
|
#
|
46
46
|
# @return [Hash] - Cancellation result
|
47
47
|
def cancel(key:, cancellation_key:, recipients: nil)
|
data/lib/knock.rb
CHANGED
@@ -25,6 +25,8 @@ module Knock
|
|
25
25
|
autoload :Preferences, "knock/preferences"
|
26
26
|
autoload :Users, "knock/users"
|
27
27
|
autoload :Workflows, "knock/workflows"
|
28
|
+
autoload :BulkOperations, "knock/bulk_operations"
|
29
|
+
autoload :Objects, "knock/objects"
|
28
30
|
|
29
31
|
# Errors
|
30
32
|
autoload :APIError, "knock/errors"
|
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
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Knock Labs, Inc.
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-01-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -73,8 +73,10 @@ files:
|
|
73
73
|
- knockapi.gemspec
|
74
74
|
- lib/knock.rb
|
75
75
|
- lib/knock/base.rb
|
76
|
+
- lib/knock/bulk_operations.rb
|
76
77
|
- lib/knock/client.rb
|
77
78
|
- lib/knock/errors.rb
|
79
|
+
- lib/knock/objects.rb
|
78
80
|
- lib/knock/preferences.rb
|
79
81
|
- lib/knock/users.rb
|
80
82
|
- lib/knock/version.rb
|
@@ -84,7 +86,7 @@ licenses:
|
|
84
86
|
- MIT
|
85
87
|
metadata:
|
86
88
|
documentation_uri: https://docs.knock.app
|
87
|
-
post_install_message:
|
89
|
+
post_install_message:
|
88
90
|
rdoc_options: []
|
89
91
|
require_paths:
|
90
92
|
- lib
|
@@ -99,8 +101,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
99
101
|
- !ruby/object:Gem::Version
|
100
102
|
version: '0'
|
101
103
|
requirements: []
|
102
|
-
rubygems_version: 3.
|
103
|
-
signing_key:
|
104
|
+
rubygems_version: 3.3.3
|
105
|
+
signing_key:
|
104
106
|
specification_version: 4
|
105
107
|
summary: API client for Knock
|
106
108
|
test_files: []
|