knockapi 0.4.4 → 0.4.6

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: 9d0a730346c7c39ec862f160ac31fd80844b3f0907129a02ad320bf724e74888
4
- data.tar.gz: bab747c80c86891e7e5d8135748deec4cd8c6bee1b20fbddf19546aefebe5646
3
+ metadata.gz: bb2117c38dcd672ea551af82b0803b141576d46ba155bbb345e3dd3136c8ad13
4
+ data.tar.gz: eebda102aea7791d7b664f244dadb26b98d529d4eb197227684dcb1f64bbdfe4
5
5
  SHA512:
6
- metadata.gz: a7e879b66a557daac3950155ec7429cbfe72b7f6d7f2491eb440f92cf1b1f620753a2dab325751bdb704933df7be8c598b9b47c67b191c7659dbd9470c888f2c
7
- data.tar.gz: 689dba9548ddba6fe5e2e90fb339eb2dee6c23f9c8d51ce878d4d163da70453482a1fae0806c7fa56638e3dec9aa0cf38f3c5669c657b11768d7e1087a57dd47
6
+ metadata.gz: 7f56c9b141388fbf5793b1699a958b71b321593acc86f19afaadb96c15425c3ce0895e47d2e7f229d36a0a512a55a77cad90ae8da5e5c9e812833d035db93eb1
7
+ data.tar.gz: a1837d1bc86cecf3250ac99286e0a46c8ea6f3bc5b7c07cca6f806fe6b443a02ee7996daa7009f39169065ba377b5acce24c337ad7fc9a05d37cad7f383be1d7
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- knockapi (0.4.4)
4
+ knockapi (0.4.6)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/lib/knock/client.rb CHANGED
@@ -45,7 +45,7 @@ module Knock
45
45
  request
46
46
  end
47
47
 
48
- def delete_request(path:, auth: false, params: {})
48
+ def delete_request(path:, auth: false, params: {}, body: nil)
49
49
  uri = URI(path)
50
50
  uri.query = URI.encode_www_form(params) if params
51
51
 
@@ -54,6 +54,7 @@ module Knock
54
54
  'Content-Type' => 'application/json'
55
55
  )
56
56
 
57
+ request.body = body.to_json if body
57
58
  request['Authorization'] = "Bearer #{Knock.key!}" if auth
58
59
  request['User-Agent'] = user_agent
59
60
  request
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'json'
3
4
  require 'net/http'
4
5
  require 'uri'
5
6
 
@@ -16,6 +17,8 @@ module Knock
16
17
  #
17
18
  # @return [Hash] Paginated list of Message records
18
19
  def list(options: {})
20
+ options[:trigger_data] = JSON.generate(options[:trigger_data]) if options[:trigger_data]
21
+
19
22
  request = get_request(
20
23
  auth: true,
21
24
  path: '/v1/messages',
@@ -60,6 +63,8 @@ module Knock
60
63
  #
61
64
  # @return [Hash] Paginated Message's activities
62
65
  def get_activities(id:, options: {})
66
+ options[:trigger_data] = JSON.generate(options[:trigger_data]) if options[:trigger_data]
67
+
63
68
  request = get_request(
64
69
  auth: true,
65
70
  path: "/v1/messages/#{id}/activities",
data/lib/knock/objects.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'json'
3
4
  require 'net/http'
4
5
  require 'uri'
5
6
 
@@ -150,6 +151,8 @@ module Knock
150
151
  #
151
152
  # @return [Hash] Paginated messages response
152
153
  def get_messages(collection:, id:, options: {})
154
+ options[:trigger_data] = JSON.generate(options[:trigger_data]) if options[:trigger_data]
155
+
153
156
  request = get_request(
154
157
  auth: true,
155
158
  path: "/v1/objects/#{collection}/#{id}/messages",
@@ -303,6 +306,58 @@ module Knock
303
306
 
304
307
  execute_request(request: request)
305
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
306
361
  end
307
362
  end
308
363
  # rubocop:enable Metrics/ModuleLength
data/lib/knock/users.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'json'
3
4
  require 'net/http'
4
5
  require 'uri'
5
6
 
@@ -95,6 +96,8 @@ module Knock
95
96
  #
96
97
  # @return [Hash] the feed response
97
98
  def get_feed(id:, channel_id:, options: {})
99
+ options[:trigger_data] = JSON.generate(options[:trigger_data]) if options[:trigger_data]
100
+
98
101
  request = get_request(
99
102
  auth: true,
100
103
  path: "/v1/users/#{id}/feeds/#{channel_id}",
@@ -345,6 +348,8 @@ module Knock
345
348
  #
346
349
  # @return [Hash] Paginated messages response
347
350
  def get_messages(id:, options: {})
351
+ options[:trigger_data] = JSON.generate(options[:trigger_data]) if options[:trigger_data]
352
+
348
353
  request = get_request(
349
354
  auth: true,
350
355
  path: "/v1/users/#{id}/messages",
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.4'
4
+ VERSION = '0.4.6'
5
5
  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
4
+ version: 0.4.6
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-07-18 00:00:00.000000000 Z
11
+ date: 2023-03-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -106,7 +106,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
106
106
  - !ruby/object:Gem::Version
107
107
  version: '0'
108
108
  requirements: []
109
- rubygems_version: 3.3.7
109
+ rubygems_version: 3.4.6
110
110
  signing_key:
111
111
  specification_version: 4
112
112
  summary: API client for Knock