knockapi 0.4.7 → 0.4.9
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/.rubocop.yml +1 -1
- data/Gemfile.lock +1 -1
- data/lib/knock/client.rb +3 -2
- data/lib/knock/objects.rb +61 -0
- data/lib/knock/users.rb +57 -0
- data/lib/knock/version.rb +1 -1
- data/lib/knock/workflows.rb +86 -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: 1fe65a30d36b287d6c125fa1a2dab2cc5203b46ed782c80f4b8c794a131d746d
|
4
|
+
data.tar.gz: 2af32dacf68a984235ae45d9bb2cf7e67c22849cbf2e063d8e56ec56aae1fb22
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6a6ba784cd2ab7ff11d2d0412522703a19a8f49ffe623589e50262d4eed97f80b423afb5cb9338d57ad8c6959daf12abb3bc58a95451741742f01966576d51f1
|
7
|
+
data.tar.gz: 7e47f4c8bfdf1ca6192f4d35cefe57bbd08746147099b802bd66caefb1e48ffeee5d16f0256fb274907e8636685a25b1049dfb7d4f156c1bcad8c252cad1685f
|
data/.rubocop.yml
CHANGED
data/Gemfile.lock
CHANGED
data/lib/knock/client.rb
CHANGED
@@ -8,8 +8,9 @@ module Knock
|
|
8
8
|
def client
|
9
9
|
return @client if defined?(@client)
|
10
10
|
|
11
|
-
@client = Net::HTTP.new(Knock::API_HOSTNAME,
|
12
|
-
@client
|
11
|
+
@client = Net::HTTP.new(Knock::API_HOSTNAME, 4001)
|
12
|
+
# @client = Net::HTTP.new(Knock::API_HOSTNAME, 443)
|
13
|
+
# @client.use_ssl = true
|
13
14
|
|
14
15
|
@client
|
15
16
|
end
|
data/lib/knock/objects.rb
CHANGED
@@ -29,6 +29,23 @@ module Knock
|
|
29
29
|
execute_request(request: request)
|
30
30
|
end
|
31
31
|
|
32
|
+
# Retrieves paginated objects in a collection for the provided environment
|
33
|
+
#
|
34
|
+
# @param [Hash] options Options to pass to the paginated users endpoint query.
|
35
|
+
# These include:
|
36
|
+
# - page_size: size of page to be returned (max: 50)
|
37
|
+
# - after: after cursor for pagination
|
38
|
+
# - before: before cursor for pagination
|
39
|
+
def list(collection:, options: {})
|
40
|
+
request = get_request(
|
41
|
+
auth: true,
|
42
|
+
path: "/v1/objects/#{collection}",
|
43
|
+
params: options
|
44
|
+
)
|
45
|
+
|
46
|
+
execute_request(request: request)
|
47
|
+
end
|
48
|
+
|
32
49
|
# Upserts an Object in a collection
|
33
50
|
#
|
34
51
|
# @param [String] collection The collection the object is in
|
@@ -312,6 +329,10 @@ module Knock
|
|
312
329
|
# @param [String] collection The collection the object is in
|
313
330
|
# @param [String] id The object id
|
314
331
|
# @param [Hash] options Options to pass to the subscriptions endpoint
|
332
|
+
# These include:
|
333
|
+
# - page_size: size of page to be returned (max: 50)
|
334
|
+
# - after: after cursor for pagination
|
335
|
+
# - before: before cursor for pagination
|
315
336
|
#
|
316
337
|
# @return [Hash] Paginated subscriptions response
|
317
338
|
def list_subscriptions(collection:, id:, options: {})
|
@@ -358,6 +379,46 @@ module Knock
|
|
358
379
|
|
359
380
|
execute_request(request: request)
|
360
381
|
end
|
382
|
+
|
383
|
+
# Get object's schedules
|
384
|
+
#
|
385
|
+
# @param [String] collection The collection the object is in
|
386
|
+
# @param [String] id The object id
|
387
|
+
# @param [Hash] options Options to pass to the schedules endpoint query
|
388
|
+
#
|
389
|
+
# @return [Hash] Paginated schedules response
|
390
|
+
def get_schedules(collection:, id:, options: {})
|
391
|
+
request = get_request(
|
392
|
+
auth: true,
|
393
|
+
path: "/v1/objects/#{collection}/#{id}/schedules",
|
394
|
+
params: options
|
395
|
+
)
|
396
|
+
|
397
|
+
execute_request(request: request)
|
398
|
+
end
|
399
|
+
|
400
|
+
# Get object's subscriptions as recipient
|
401
|
+
#
|
402
|
+
# @param [String] collection The collection the object is in
|
403
|
+
# @param [String] id The object id
|
404
|
+
# @param [Hash] options Options to pass to the subscriptions endpoint query
|
405
|
+
# These include:
|
406
|
+
# - page_size: size of page to be returned (max: 50)
|
407
|
+
# - after: after cursor for pagination
|
408
|
+
# - before: before cursor for pagination
|
409
|
+
#
|
410
|
+
# @return [Hash] Paginated subscriptions response
|
411
|
+
def get_subscriptions(collection:, id:, options: {})
|
412
|
+
options[:mode] = 'recipient'
|
413
|
+
|
414
|
+
request = get_request(
|
415
|
+
auth: true,
|
416
|
+
path: "/v1/objects/#{collection}/#{id}/subscriptions",
|
417
|
+
params: options
|
418
|
+
)
|
419
|
+
|
420
|
+
execute_request(request: request)
|
421
|
+
end
|
361
422
|
end
|
362
423
|
end
|
363
424
|
# rubocop:enable Metrics/ModuleLength
|
data/lib/knock/users.rb
CHANGED
@@ -45,6 +45,23 @@ module Knock
|
|
45
45
|
execute_request(request: request)
|
46
46
|
end
|
47
47
|
|
48
|
+
# Retrieves paginated users for the provided environment
|
49
|
+
#
|
50
|
+
# @param [Hash] options Options to pass to the paginated users endpoint query.
|
51
|
+
# These include:
|
52
|
+
# - page_size: size of page to be returned (max: 50)
|
53
|
+
# - after: after cursor for pagination
|
54
|
+
# - before: before cursor for pagination
|
55
|
+
def list(options: {})
|
56
|
+
request = get_request(
|
57
|
+
auth: true,
|
58
|
+
path: '/v1/users',
|
59
|
+
params: options
|
60
|
+
)
|
61
|
+
|
62
|
+
execute_request(request: request)
|
63
|
+
end
|
64
|
+
|
48
65
|
# Retrieves the given user
|
49
66
|
#
|
50
67
|
# @param [String] id The user ID
|
@@ -358,6 +375,46 @@ module Knock
|
|
358
375
|
|
359
376
|
execute_request(request: request)
|
360
377
|
end
|
378
|
+
|
379
|
+
##
|
380
|
+
# Schedules
|
381
|
+
##
|
382
|
+
|
383
|
+
# Get user's schedules
|
384
|
+
#
|
385
|
+
# @param [String] id the user ID
|
386
|
+
# @param [Hash] options Options to pass to the schedules endpoint query
|
387
|
+
#
|
388
|
+
# @return [Hash] Paginated schedules response
|
389
|
+
def get_schedules(id:, options: {})
|
390
|
+
request = get_request(
|
391
|
+
auth: true,
|
392
|
+
path: "/v1/users/#{id}/schedules",
|
393
|
+
params: options
|
394
|
+
)
|
395
|
+
|
396
|
+
execute_request(request: request)
|
397
|
+
end
|
398
|
+
|
399
|
+
##
|
400
|
+
# Subscriptions
|
401
|
+
##
|
402
|
+
|
403
|
+
# Get user's subscriptions
|
404
|
+
#
|
405
|
+
# @param [String] id the user ID
|
406
|
+
# @param [Hash] options Options to pass to the subscriptions endpoint query
|
407
|
+
#
|
408
|
+
# @return [Hash] Paginated subscriptions response
|
409
|
+
def get_subscriptions(id:, options: {})
|
410
|
+
request = get_request(
|
411
|
+
auth: true,
|
412
|
+
path: "/v1/users/#{id}/subscriptions",
|
413
|
+
params: options
|
414
|
+
)
|
415
|
+
|
416
|
+
execute_request(request: request)
|
417
|
+
end
|
361
418
|
end
|
362
419
|
end
|
363
420
|
# rubocop:enable Metrics/ModuleLength
|
data/lib/knock/version.rb
CHANGED
data/lib/knock/workflows.rb
CHANGED
@@ -23,7 +23,7 @@ module Knock
|
|
23
23
|
# duplicate workflow invocations
|
24
24
|
#
|
25
25
|
# @return [Hash] A workflow trigger result
|
26
|
-
def trigger(key:, actor:, recipients:, data: {}, cancellation_key: nil, tenant: nil, idempotency_key: nil)
|
26
|
+
def trigger(key:, actor:, recipients:, data: {}, cancellation_key: nil, tenant: nil, idempotency_key: nil)
|
27
27
|
attrs = {
|
28
28
|
actor: actor,
|
29
29
|
recipients: recipients,
|
@@ -63,6 +63,91 @@ module Knock
|
|
63
63
|
|
64
64
|
execute_request(request: request)
|
65
65
|
end
|
66
|
+
|
67
|
+
# Creates schedule instances for all recipients for the given
|
68
|
+
# workflow.
|
69
|
+
#
|
70
|
+
# @param [String] key The workflow key
|
71
|
+
# @param [String, Hash] actor An optional actor identifier to be used when trigger the workflow
|
72
|
+
# @param [Array<String, Hash>] recipients The recipient identifiers
|
73
|
+
# @param [Array<Hash>] repeats The repeat rules for when to schedule the workflow run
|
74
|
+
# @param [Hash] data Parameters to be used as variables on the workflow run
|
75
|
+
# @param [String] tenant An optional tenant identifier
|
76
|
+
|
77
|
+
def create_schedules(key:, recipients:, repeats:, scheduled_at: nil, data: {}, actor: nil, tenant: nil)
|
78
|
+
attrs = {
|
79
|
+
workflow: key,
|
80
|
+
actor: actor,
|
81
|
+
recipients: recipients,
|
82
|
+
repeats: repeats,
|
83
|
+
data: data,
|
84
|
+
tenant: tenant,
|
85
|
+
scheduled_at: scheduled_at
|
86
|
+
}
|
87
|
+
|
88
|
+
request = post_request(
|
89
|
+
auth: true,
|
90
|
+
path: '/v1/schedules',
|
91
|
+
body: attrs
|
92
|
+
)
|
93
|
+
|
94
|
+
execute_request(request: request)
|
95
|
+
end
|
96
|
+
|
97
|
+
# Updates schedule instances with the attributes passed as params
|
98
|
+
#
|
99
|
+
# @param [Array<String>] schedule_ids The ids of the schedules to be updated
|
100
|
+
# @param [Hash] schedule_attrs The attributes to be used to update the schedules
|
101
|
+
# Possible attributes: actor, repeats, data and tenant
|
102
|
+
|
103
|
+
def update_schedules(schedule_ids:, schedule_attrs:)
|
104
|
+
attrs = {
|
105
|
+
schedule_ids: schedule_ids
|
106
|
+
}
|
107
|
+
|
108
|
+
attrs = attrs.merge(schedule_attrs)
|
109
|
+
|
110
|
+
request = put_request(
|
111
|
+
auth: true,
|
112
|
+
path: '/v1/schedules',
|
113
|
+
body: attrs
|
114
|
+
)
|
115
|
+
|
116
|
+
execute_request(request: request)
|
117
|
+
end
|
118
|
+
|
119
|
+
# Get paginated workflow schedules
|
120
|
+
#
|
121
|
+
# @param [String] key The workflow key
|
122
|
+
# @param [Hash] opts Options to filter the results: recipients, tenant and pagination params
|
123
|
+
def list_schedules(key:, opts: {})
|
124
|
+
attrs = opts.merge(workflow: key)
|
125
|
+
|
126
|
+
request = get_request(
|
127
|
+
auth: true,
|
128
|
+
path: '/v1/schedules',
|
129
|
+
params: attrs
|
130
|
+
)
|
131
|
+
|
132
|
+
execute_request(request: request)
|
133
|
+
end
|
134
|
+
|
135
|
+
# Delete schedule instances
|
136
|
+
#
|
137
|
+
# @param [Array<String>] schedule_ids The ids of the schedules to be deleted
|
138
|
+
def delete_schedules(schedule_ids:)
|
139
|
+
attrs = {
|
140
|
+
schedule_ids: schedule_ids
|
141
|
+
}
|
142
|
+
|
143
|
+
request = delete_request(
|
144
|
+
auth: true,
|
145
|
+
path: '/v1/schedules',
|
146
|
+
body: attrs
|
147
|
+
)
|
148
|
+
|
149
|
+
execute_request(request: request)
|
150
|
+
end
|
66
151
|
end
|
67
152
|
end
|
68
153
|
end
|
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.9
|
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: 2023-
|
11
|
+
date: 2023-06-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|