knockapi 0.3.0 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- 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/messages.rb +88 -0
- data/lib/knock/objects.rb +142 -0
- data/lib/knock/preferences.rb +39 -67
- data/lib/knock/users.rb +255 -2
- data/lib/knock/version.rb +1 -1
- data/lib/knock/workflows.rb +3 -3
- data/lib/knock.rb +3 -0
- metadata +9 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ed79d84e9b6070feed5df6299073f396d7739c43a5a7c5a1ed2bb87e91722f5a
|
4
|
+
data.tar.gz: 99360a722f4a6f669940d38c08688edb64effb68f4805f26fe3d790dce7038bc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 670a433ef51923fb02f0af1abd618e848c6b5574dc919766ccec8583d364f9a6f3ca2f618592a1c3ed95245a028302eaa2d288d6a1b0b2d8eb979153e4dbaf16
|
7
|
+
data.tar.gz: 9bcbe07af9a0125fb77d1f3ce50bc190ecf12ac2c32f71e214c93a6492276960343d4e59ad7fe98411ebccbdeea7da29de54f78da5a1041471d6bed2d0e6eb55
|
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,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
|
+
|
@@ -0,0 +1,142 @@
|
|
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
|
+
|
124
|
+
# Get object's messages
|
125
|
+
#
|
126
|
+
# @param [String] collection The collection the object is in
|
127
|
+
# @param [String] id The object id
|
128
|
+
# @param [Hash] options Options to pass to the messages endpoint query
|
129
|
+
#
|
130
|
+
# @return [Hash] Paginated messages response
|
131
|
+
def get_messages(collection:, id:, options: {})
|
132
|
+
request = get_request(
|
133
|
+
auth: true,
|
134
|
+
path: "/v1/objects/#{collection}/#{id}/messages",
|
135
|
+
params: options
|
136
|
+
)
|
137
|
+
|
138
|
+
execute_request(request: request)
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
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,222 @@ 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
|
+
# 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
|
+
|
120
|
+
##
|
121
|
+
# Preferences
|
122
|
+
##
|
123
|
+
|
124
|
+
# Returns all preference sets for the user
|
125
|
+
#
|
126
|
+
# @param [String] user_id The ID of the user to retrieve preferences for
|
127
|
+
#
|
128
|
+
# @return [Hash] The preference sets
|
129
|
+
def get_all_preferences(user_id:)
|
130
|
+
endpoint = "/v1/users/#{user_id}/preferences"
|
131
|
+
|
132
|
+
request = get_request(
|
133
|
+
auth: true,
|
134
|
+
path: endpoint
|
135
|
+
)
|
136
|
+
|
137
|
+
execute_request(request: request)
|
138
|
+
end
|
139
|
+
|
140
|
+
# Gets a single preference set, defaults to the 'default' set
|
141
|
+
# for the user given.
|
142
|
+
#
|
143
|
+
# @param [String] user_id The ID of the user to retrieve preferences for
|
144
|
+
# @param [String] preference_set The preference set ID (defaults to `default`)
|
145
|
+
#
|
146
|
+
# @return [Hash] The preference set (if it exists)
|
147
|
+
def get_preferences(user_id:, preference_set: DEFAULT_PREFERENCE_SET_ID)
|
148
|
+
endpoint = "/v1/users/#{user_id}/preferences/#{preference_set}"
|
149
|
+
|
150
|
+
request = get_request(
|
151
|
+
auth: true,
|
152
|
+
path: endpoint
|
153
|
+
)
|
154
|
+
|
155
|
+
execute_request(request: request)
|
156
|
+
end
|
157
|
+
|
158
|
+
# Sets multiple preferences at once for the preference set.
|
159
|
+
#
|
160
|
+
# @param [String] user_id The ID of the user to set preferences for
|
161
|
+
# @param [String] preference_set The preference set ID (defaults to `default`)
|
162
|
+
# @param [Hash] channel_types The channel_types hash to set
|
163
|
+
# @param [Hash] workflows The workflows hash to set
|
164
|
+
# @param [Hash] categories The categories hash to set
|
165
|
+
#
|
166
|
+
# @return [Hash] The preference set
|
167
|
+
def set_preferences(
|
168
|
+
user_id:,
|
169
|
+
channel_types: nil,
|
170
|
+
workflows: nil,
|
171
|
+
categories: nil,
|
172
|
+
preference_set: DEFAULT_PREFERENCE_SET_ID
|
173
|
+
)
|
174
|
+
endpoint = "/v1/users/#{user_id}/preferences/#{preference_set}"
|
175
|
+
|
176
|
+
request = put_request(
|
177
|
+
auth: true,
|
178
|
+
path: endpoint,
|
179
|
+
body: {
|
180
|
+
channel_types: channel_types,
|
181
|
+
workflows: workflows,
|
182
|
+
categories: categories
|
183
|
+
}
|
184
|
+
)
|
185
|
+
|
186
|
+
execute_request(request: request)
|
187
|
+
end
|
188
|
+
|
189
|
+
# Bulk sets the preference object for the users.
|
190
|
+
#
|
191
|
+
# @param [Array<String>] user_ids The ID of the user to set preferences for
|
192
|
+
# @param [Hash] preferences The preferences hash to set
|
193
|
+
# @param [String] preference_set The preference set ID (defaults to `default`)
|
194
|
+
#
|
195
|
+
# @return [Hash] BulkOperation
|
196
|
+
def bulk_set_preferences(
|
197
|
+
user_ids: [],
|
198
|
+
preferences: {},
|
199
|
+
preference_set: DEFAULT_PREFERENCE_SET_ID
|
200
|
+
)
|
201
|
+
endpoint = "/v1/users/bulk/preferences"
|
202
|
+
|
203
|
+
# Put the preference set id if it doesn't already exist
|
204
|
+
unless preferences.has_key("id")
|
205
|
+
preferences["id"] = preference_set
|
206
|
+
end
|
207
|
+
|
208
|
+
request = put_request(
|
209
|
+
auth: true,
|
210
|
+
path: endpoint,
|
211
|
+
body: {
|
212
|
+
user_ids: user_ids,
|
213
|
+
preferences: preferences
|
214
|
+
}
|
215
|
+
)
|
216
|
+
|
217
|
+
execute_request(request: request)
|
218
|
+
end
|
219
|
+
|
220
|
+
# Sets preferences for the given channel type
|
221
|
+
#
|
222
|
+
# @param [String] user_id The ID of the user to set preferences for
|
223
|
+
# @param [String] preference_set The preference set ID (defaults to `default`)
|
224
|
+
# @param [String] channel_type The channel type to set
|
225
|
+
# @param [Bool] setting Whether the channel type is enabled or not
|
226
|
+
#
|
227
|
+
# @return [Hash] The preference set
|
228
|
+
def set_channel_type_preferences(user_id:, channel_type:, setting:, preference_set: DEFAULT_PREFERENCE_SET_ID)
|
229
|
+
endpoint = "/v1/users/#{user_id}/preferences/#{preference_set}/channel_types/#{channel_type}"
|
230
|
+
|
231
|
+
request = put_request(
|
232
|
+
auth: true,
|
233
|
+
path: endpoint,
|
234
|
+
body: {subscribed: setting}
|
235
|
+
)
|
236
|
+
|
237
|
+
execute_request(request: request)
|
238
|
+
end
|
239
|
+
|
240
|
+
# Sets preferences for the given workflow
|
241
|
+
#
|
242
|
+
# @param [String] user_id The ID of the user to set preferences for
|
243
|
+
# @param [String] preference_set The preference set ID (defaults to `default`)
|
244
|
+
# @param [String] workflow The workflow to set preferences for
|
245
|
+
# @param [Bool | Hash] setting Either a boolean to indicate if the type is enabled
|
246
|
+
# or a hash containing channel types and settings
|
247
|
+
#
|
248
|
+
# @return [Hash] The preference set
|
249
|
+
def set_workflow_preferences(user_id:, workflow:, setting:, preference_set: DEFAULT_PREFERENCE_SET_ID)
|
250
|
+
params = setting.is_a?(Hash) ? setting : {subscribed: setting}
|
251
|
+
endpoint = "/v1/users/#{user_id}/preferences/#{preference_set}/workflows/#{workflow}"
|
252
|
+
|
253
|
+
request = put_request(
|
254
|
+
auth: true,
|
255
|
+
path: endpoint,
|
256
|
+
body: params
|
257
|
+
)
|
258
|
+
|
259
|
+
execute_request(request: request)
|
260
|
+
end
|
261
|
+
|
262
|
+
# Sets preferences for the given category
|
263
|
+
#
|
264
|
+
# @param [String] user_id The ID of the user to set preferences for
|
265
|
+
# @param [String] preference_set The preference set ID (defaults to `default`)
|
266
|
+
# @param [String] category The category to set preferences for
|
267
|
+
# @param [Bool | Hash] setting Either a boolean to indicate if the type is enabled
|
268
|
+
# or a hash containing channel types and settings
|
269
|
+
#
|
270
|
+
# @return [Hash] The preference set
|
271
|
+
def set_category_preferences(user_id:, category:, setting:, preference_set: DEFAULT_PREFERENCE_SET_ID)
|
272
|
+
params = setting.is_a?(Hash) ? setting : {subscribed: setting}
|
273
|
+
endpoint = "/v1/users/#{user_id}/preferences/#{preference_set}/categories/#{category}"
|
274
|
+
|
275
|
+
request = put_request(
|
276
|
+
auth: true,
|
277
|
+
path: endpoint,
|
278
|
+
body: params
|
279
|
+
)
|
280
|
+
|
281
|
+
execute_request(request: request)
|
282
|
+
end
|
283
|
+
|
284
|
+
##
|
285
|
+
# Channel data
|
286
|
+
##
|
287
|
+
|
55
288
|
# Get user's channel data for the given channel id
|
56
289
|
#
|
57
290
|
# @param [String] id the user ID
|
@@ -71,14 +304,34 @@ module Knock
|
|
71
304
|
#
|
72
305
|
# @param [String] id the user ID
|
73
306
|
# @param [String] channel_id target channel ID
|
74
|
-
# @param [
|
307
|
+
# @param [Hash] channel_data channel data
|
75
308
|
#
|
76
309
|
# @return [Hash] channel data
|
77
310
|
def set_channel_data(id:, channel_id:, channel_data:)
|
78
311
|
request = put_request(
|
79
312
|
auth: true,
|
80
313
|
path: "/v1/users/#{id}/channel_data/#{channel_id}",
|
81
|
-
body: {
|
314
|
+
body: {data: channel_data}
|
315
|
+
)
|
316
|
+
|
317
|
+
execute_request(request: request)
|
318
|
+
end
|
319
|
+
|
320
|
+
##
|
321
|
+
# Messages
|
322
|
+
##
|
323
|
+
|
324
|
+
# Get user's messages
|
325
|
+
#
|
326
|
+
# @param [String] id the user ID
|
327
|
+
# @param [Hash] options Options to pass to the messages endpoint query
|
328
|
+
#
|
329
|
+
# @return [Hash] Paginated messages response
|
330
|
+
def get_messages(id:, options: {})
|
331
|
+
request = get_request(
|
332
|
+
auth: true,
|
333
|
+
path: "/v1/users/#{id}/messages",
|
334
|
+
params: options
|
82
335
|
)
|
83
336
|
|
84
337
|
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 (optional)
|
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,9 @@ 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"
|
30
|
+
autoload :Messages, "knock/messages"
|
28
31
|
|
29
32
|
# Errors
|
30
33
|
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.2
|
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-04-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -73,8 +73,11 @@ 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/messages.rb
|
80
|
+
- lib/knock/objects.rb
|
78
81
|
- lib/knock/preferences.rb
|
79
82
|
- lib/knock/users.rb
|
80
83
|
- lib/knock/version.rb
|
@@ -84,7 +87,7 @@ licenses:
|
|
84
87
|
- MIT
|
85
88
|
metadata:
|
86
89
|
documentation_uri: https://docs.knock.app
|
87
|
-
post_install_message:
|
90
|
+
post_install_message:
|
88
91
|
rdoc_options: []
|
89
92
|
require_paths:
|
90
93
|
- lib
|
@@ -99,8 +102,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
99
102
|
- !ruby/object:Gem::Version
|
100
103
|
version: '0'
|
101
104
|
requirements: []
|
102
|
-
rubygems_version: 3.
|
103
|
-
signing_key:
|
105
|
+
rubygems_version: 3.3.7
|
106
|
+
signing_key:
|
104
107
|
specification_version: 4
|
105
108
|
summary: API client for Knock
|
106
109
|
test_files: []
|