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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 81cfa3f6f13dddad567058c6c1bf837d41fbf4227247e6d5f7cd4bcedf94cb2b
4
- data.tar.gz: 18ed9ffaed543083c5edcb5c2a0274919b10fca298938e324f96d2514c2dfa81
3
+ metadata.gz: 829d797080c6841ef0bda6f2e775e17d45f4c30c466f2b0e1b8ea2abb7e8602e
4
+ data.tar.gz: 34bfb3a3bcad22f326a3195d67f879d57e746c1eaef1bb8fd5be490a5eac1058
5
5
  SHA512:
6
- metadata.gz: 8e2e848f8d590fff5367f1a805c671fc9ad0643fc6b14e1300d362d99007de94922fe56a74dc1a9bf73e4d4aa79002239b9f7171d25aef68cea6ef3c261304e8
7
- data.tar.gz: c4c4ee1372ed47fea5d4fa4c7fddeb1daf4d101959214101b671c1ea8408c7144f98f0e263c0c785639cc8978b2639d438a38b1a97974eab1333fde9fa2d7fc4
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
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- knockapi (0.4.5)
4
+ knockapi (0.4.7)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
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, _idempotency_key: nil, body: nil)
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, _idempotency_key: nil, body: nil)
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Knock
4
- VERSION = '0.4.5'
4
+ VERSION = '0.4.7'
5
5
  end
@@ -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.5
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: 2022-12-22 00:00:00.000000000 Z
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.3.26
110
+ rubygems_version: 3.4.10
110
111
  signing_key:
111
112
  specification_version: 4
112
113
  summary: API client for Knock