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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 829d797080c6841ef0bda6f2e775e17d45f4c30c466f2b0e1b8ea2abb7e8602e
4
- data.tar.gz: 34bfb3a3bcad22f326a3195d67f879d57e746c1eaef1bb8fd5be490a5eac1058
3
+ metadata.gz: 1fe65a30d36b287d6c125fa1a2dab2cc5203b46ed782c80f4b8c794a131d746d
4
+ data.tar.gz: 2af32dacf68a984235ae45d9bb2cf7e67c22849cbf2e063d8e56ec56aae1fb22
5
5
  SHA512:
6
- metadata.gz: 8da11f98837db48e400a3387a081f2309fc7302029b592b6990293127302fd9c17c8c50747e6786943ede84a6cbda9b9496dce58cca25f8f603d016b844d4c8c
7
- data.tar.gz: fc8224278dc1ef927eed734a5e55877d9d934a204a8cf22bd11b32ddeee3d04281bbff1195da500755fb1e248e30f30f28967d42e010f79da96ae4f53cbf3436
6
+ metadata.gz: 6a6ba784cd2ab7ff11d2d0412522703a19a8f49ffe623589e50262d4eed97f80b423afb5cb9338d57ad8c6959daf12abb3bc58a95451741742f01966576d51f1
7
+ data.tar.gz: 7e47f4c8bfdf1ca6192f4d35cefe57bbd08746147099b802bd66caefb1e48ffeee5d16f0256fb274907e8636685a25b1049dfb7d4f156c1bcad8c252cad1685f
data/.rubocop.yml CHANGED
@@ -5,4 +5,4 @@ Metrics/LineLength:
5
5
  Metrics/MethodLength:
6
6
  Max: 35
7
7
  Metrics/ParameterLists:
8
- Max: 6
8
+ Max: 7
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- knockapi (0.4.7)
4
+ knockapi (0.4.9)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
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, 443)
12
- @client.use_ssl = true
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Knock
4
- VERSION = '0.4.7'
4
+ VERSION = '0.4.9'
5
5
  end
@@ -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) # rubocop:disable Metrics/ParameterLists
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.7
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-04-10 00:00:00.000000000 Z
11
+ date: 2023-06-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler