knockapi 0.4.6 → 0.4.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bb2117c38dcd672ea551af82b0803b141576d46ba155bbb345e3dd3136c8ad13
4
- data.tar.gz: eebda102aea7791d7b664f244dadb26b98d529d4eb197227684dcb1f64bbdfe4
3
+ metadata.gz: f76a1fe37f883f760b872f6b52bafb40e22a870f650fb0c4cc5b40e85912888c
4
+ data.tar.gz: 7dc8c721a049b9b3a25ff67db18dc9cdca1e551f1bbcdddbf025305f6b23e582
5
5
  SHA512:
6
- metadata.gz: 7f56c9b141388fbf5793b1699a958b71b321593acc86f19afaadb96c15425c3ce0895e47d2e7f229d36a0a512a55a77cad90ae8da5e5c9e812833d035db93eb1
7
- data.tar.gz: a1837d1bc86cecf3250ac99286e0a46c8ea6f3bc5b7c07cca6f806fe6b443a02ee7996daa7009f39169065ba377b5acce24c337ad7fc9a05d37cad7f383be1d7
6
+ metadata.gz: 38e0c87a2c2e4fe46c1cc80c9a7707e1b26416f682a5de387f8725afa0e9a9599a9ee35b0b57e693b1a37897d2cf5e132c75595304497281f4b014e350946ef5
7
+ data.tar.gz: 4a3be25fd78f03bc7605fea581486950639ea333c819828e1859e30d94ea8f0e42d00807a5076ba9d97db508c48e08163dbe81f694adc49517401028b8f582f2
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/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.6)
4
+ knockapi (0.4.8)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/lib/knock/client.rb CHANGED
@@ -37,11 +37,12 @@ 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
 
@@ -60,11 +61,12 @@ module Knock
60
61
  request
61
62
  end
62
63
 
63
- def put_request(path:, auth: false, _idempotency_key: nil, body: nil)
64
+ def put_request(path:, auth: false, idempotency_key: nil, body: nil)
64
65
  request = Net::HTTP::Put.new(path, 'Content-Type' => 'application/json')
65
66
  request.body = body.to_json if body
66
67
  request['Authorization'] = "Bearer #{Knock.key!}" if auth
67
68
  request['User-Agent'] = user_agent
69
+ request['Idempotency-Key'] = idempotency_key if idempotency_key
68
70
  request
69
71
  end
70
72
 
data/lib/knock/objects.rb CHANGED
@@ -358,6 +358,23 @@ module Knock
358
358
 
359
359
  execute_request(request: request)
360
360
  end
361
+
362
+ # Get object's schedules
363
+ #
364
+ # @param [String] collection The collection the object is in
365
+ # @param [String] id The object id
366
+ # @param [Hash] options Options to pass to the schedules endpoint query
367
+ #
368
+ # @return [Hash] Paginated schedules response
369
+ def get_schedules(collection:, id:, options: {})
370
+ request = get_request(
371
+ auth: true,
372
+ path: "/v1/objects/#{collection}/#{id}/schedules",
373
+ params: options
374
+ )
375
+
376
+ execute_request(request: request)
377
+ end
361
378
  end
362
379
  end
363
380
  # rubocop:enable Metrics/ModuleLength
data/lib/knock/users.rb CHANGED
@@ -358,6 +358,26 @@ module Knock
358
358
 
359
359
  execute_request(request: request)
360
360
  end
361
+
362
+ ##
363
+ # Schedules
364
+ ##
365
+
366
+ # Get user's schedules
367
+ #
368
+ # @param [String] id the user ID
369
+ # @param [Hash] options Options to pass to the schedules endpoint query
370
+ #
371
+ # @return [Hash] Paginated schedules response
372
+ def get_schedules(id:, options: {})
373
+ request = get_request(
374
+ auth: true,
375
+ path: "/v1/users/#{id}/schedules",
376
+ params: options
377
+ )
378
+
379
+ execute_request(request: request)
380
+ end
361
381
  end
362
382
  end
363
383
  # 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.6'
4
+ VERSION = '0.4.8'
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)
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)
@@ -60,6 +63,91 @@ module Knock
60
63
 
61
64
  execute_request(request: request)
62
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
63
151
  end
64
152
  end
65
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.6
4
+ version: 0.4.8
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-03-28 00:00:00.000000000 Z
11
+ date: 2023-04-14 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.4.6
110
+ rubygems_version: 3.4.10
110
111
  signing_key:
111
112
  specification_version: 4
112
113
  summary: API client for Knock