knockapi 0.4.5 → 0.4.7
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/CONTRIBUTING.md +31 -0
- data/Gemfile.lock +1 -1
- data/lib/knock/client.rb +6 -3
- data/lib/knock/objects.rb +52 -0
- data/lib/knock/version.rb +1 -1
- data/lib/knock/workflows.rb +5 -2
- 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: 829d797080c6841ef0bda6f2e775e17d45f4c30c466f2b0e1b8ea2abb7e8602e
|
4
|
+
data.tar.gz: 34bfb3a3bcad22f326a3195d67f879d57e746c1eaef1bb8fd5be490a5eac1058
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8da11f98837db48e400a3387a081f2309fc7302029b592b6990293127302fd9c17c8c50747e6786943ede84a6cbda9b9496dce58cca25f8f603d016b844d4c8c
|
7
|
+
data.tar.gz: fc8224278dc1ef927eed734a5e55877d9d934a204a8cf22bd11b32ddeee3d04281bbff1195da500755fb1e248e30f30f28967d42e010f79da96ae4f53cbf3436
|
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# Contributing
|
2
|
+
|
3
|
+
## Getting Started
|
4
|
+
|
5
|
+
1. Install [asdf](https://asdf-vm.com)
|
6
|
+
2. Install the asdf Ruby plugin
|
7
|
+
|
8
|
+
```bash
|
9
|
+
asdf plugin add ruby https://github.com/asdf-vm/asdf-ruby.git # Visit that repository to see installation prerequisites
|
10
|
+
```
|
11
|
+
|
12
|
+
3. Run `asdf install` to install the version of Ruby specified in the [.ruby-version](.ruby-version) file
|
13
|
+
4. Run `bundle install` to install the Ruby dependencies
|
14
|
+
|
15
|
+
## Running the tests
|
16
|
+
|
17
|
+
```bash
|
18
|
+
bundle exec rspec
|
19
|
+
```
|
20
|
+
|
21
|
+
## Running the linter
|
22
|
+
|
23
|
+
```bash
|
24
|
+
bundle exec rubocop
|
25
|
+
```
|
26
|
+
|
27
|
+
## Formatting
|
28
|
+
|
29
|
+
```bash
|
30
|
+
bundle exec rubocop -a
|
31
|
+
```
|
data/Gemfile.lock
CHANGED
data/lib/knock/client.rb
CHANGED
@@ -37,15 +37,16 @@ module Knock
|
|
37
37
|
request
|
38
38
|
end
|
39
39
|
|
40
|
-
def post_request(path:, auth: false,
|
40
|
+
def post_request(path:, auth: false, idempotency_key: nil, body: nil)
|
41
41
|
request = Net::HTTP::Post.new(path, 'Content-Type' => 'application/json')
|
42
42
|
request.body = body.to_json if body
|
43
43
|
request['Authorization'] = "Bearer #{Knock.key!}" if auth
|
44
44
|
request['User-Agent'] = user_agent
|
45
|
+
request['Idempotency-Key'] = idempotency_key if idempotency_key
|
45
46
|
request
|
46
47
|
end
|
47
48
|
|
48
|
-
def delete_request(path:, auth: false, params: {})
|
49
|
+
def delete_request(path:, auth: false, params: {}, body: nil)
|
49
50
|
uri = URI(path)
|
50
51
|
uri.query = URI.encode_www_form(params) if params
|
51
52
|
|
@@ -54,16 +55,18 @@ module Knock
|
|
54
55
|
'Content-Type' => 'application/json'
|
55
56
|
)
|
56
57
|
|
58
|
+
request.body = body.to_json if body
|
57
59
|
request['Authorization'] = "Bearer #{Knock.key!}" if auth
|
58
60
|
request['User-Agent'] = user_agent
|
59
61
|
request
|
60
62
|
end
|
61
63
|
|
62
|
-
def put_request(path:, auth: false,
|
64
|
+
def put_request(path:, auth: false, idempotency_key: nil, body: nil)
|
63
65
|
request = Net::HTTP::Put.new(path, 'Content-Type' => 'application/json')
|
64
66
|
request.body = body.to_json if body
|
65
67
|
request['Authorization'] = "Bearer #{Knock.key!}" if auth
|
66
68
|
request['User-Agent'] = user_agent
|
69
|
+
request['Idempotency-Key'] = idempotency_key if idempotency_key
|
67
70
|
request
|
68
71
|
end
|
69
72
|
|
data/lib/knock/objects.rb
CHANGED
@@ -306,6 +306,58 @@ module Knock
|
|
306
306
|
|
307
307
|
execute_request(request: request)
|
308
308
|
end
|
309
|
+
|
310
|
+
# Lists all subscriptiopns for the given object
|
311
|
+
#
|
312
|
+
# @param [String] collection The collection the object is in
|
313
|
+
# @param [String] id The object id
|
314
|
+
# @param [Hash] options Options to pass to the subscriptions endpoint
|
315
|
+
#
|
316
|
+
# @return [Hash] Paginated subscriptions response
|
317
|
+
def list_subscriptions(collection:, id:, options: {})
|
318
|
+
request = get_request(
|
319
|
+
auth: true,
|
320
|
+
path: "/v1/objects/#{collection}/#{id}/subscriptions",
|
321
|
+
params: options
|
322
|
+
)
|
323
|
+
|
324
|
+
execute_request(request: request)
|
325
|
+
end
|
326
|
+
|
327
|
+
# Creates a set of subscriptions for the recipients on the object
|
328
|
+
#
|
329
|
+
# @param [String] collection The collection the object is in
|
330
|
+
# @param [String] id The object id
|
331
|
+
# @param [Array<String, Hash>] recipients An array of recipients
|
332
|
+
# @param [Hash] properties A set of custom properties to set on the subscriptions
|
333
|
+
#
|
334
|
+
# @return [Array<Hash>] List of created subscriptions
|
335
|
+
def add_subscriptions(collection:, id:, recipients: [], properties: {})
|
336
|
+
request = post_request(
|
337
|
+
auth: true,
|
338
|
+
path: "/v1/objects/#{collection}/#{id}/subscriptions",
|
339
|
+
body: { recipients: recipients, properties: properties }
|
340
|
+
)
|
341
|
+
|
342
|
+
execute_request(request: request)
|
343
|
+
end
|
344
|
+
|
345
|
+
# Removes subscriptions for the recipients on the object
|
346
|
+
#
|
347
|
+
# @param [String] collection The collection the object is in
|
348
|
+
# @param [String] id The object id
|
349
|
+
# @param [Array<String, Hash>] recipients An array of recipients
|
350
|
+
#
|
351
|
+
# @return [Array<Hash>] List of deleted subscriptions
|
352
|
+
def delete_subscriptions(collection:, id:, recipients: [])
|
353
|
+
request = delete_request(
|
354
|
+
auth: true,
|
355
|
+
path: "/v1/objects/#{collection}/#{id}/subscriptions",
|
356
|
+
body: { recipients: recipients }
|
357
|
+
)
|
358
|
+
|
359
|
+
execute_request(request: request)
|
360
|
+
end
|
309
361
|
end
|
310
362
|
end
|
311
363
|
# rubocop:enable Metrics/ModuleLength
|
data/lib/knock/version.rb
CHANGED
data/lib/knock/workflows.rb
CHANGED
@@ -19,9 +19,11 @@ module Knock
|
|
19
19
|
# @param [String] cancellation_key An optional key to identify this workflow
|
20
20
|
# invocation for cancelling
|
21
21
|
# @param [String] tenant An optional tenant identifier
|
22
|
+
# @param [String] idempotency_key An optional idempotency key to prevent
|
23
|
+
# duplicate workflow invocations
|
22
24
|
#
|
23
25
|
# @return [Hash] A workflow trigger result
|
24
|
-
def trigger(key:, actor:, recipients:, data: {}, cancellation_key: nil, tenant: nil)
|
26
|
+
def trigger(key:, actor:, recipients:, data: {}, cancellation_key: nil, tenant: nil, idempotency_key: nil) # rubocop:disable Metrics/ParameterLists
|
25
27
|
attrs = {
|
26
28
|
actor: actor,
|
27
29
|
recipients: recipients,
|
@@ -33,7 +35,8 @@ module Knock
|
|
33
35
|
request = post_request(
|
34
36
|
auth: true,
|
35
37
|
path: "/v1/workflows/#{key}/trigger",
|
36
|
-
body: attrs
|
38
|
+
body: attrs,
|
39
|
+
idempotency_key: idempotency_key
|
37
40
|
)
|
38
41
|
|
39
42
|
execute_request(request: request)
|
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.7
|
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:
|
11
|
+
date: 2023-04-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -66,6 +66,7 @@ files:
|
|
66
66
|
- ".gitignore"
|
67
67
|
- ".rubocop.yml"
|
68
68
|
- ".ruby-version"
|
69
|
+
- CONTRIBUTING.md
|
69
70
|
- Gemfile
|
70
71
|
- Gemfile.lock
|
71
72
|
- LICENSE
|
@@ -106,7 +107,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
106
107
|
- !ruby/object:Gem::Version
|
107
108
|
version: '0'
|
108
109
|
requirements: []
|
109
|
-
rubygems_version: 3.
|
110
|
+
rubygems_version: 3.4.10
|
110
111
|
signing_key:
|
111
112
|
specification_version: 4
|
112
113
|
summary: API client for Knock
|