convoy.rb 0.2.0 → 0.4.0

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: 0bb0d6490ecbfd2a8bbef2429e9057ee9861dd7504d182c58e4bb68b9be929f1
4
- data.tar.gz: e1e2a181c570f0d04af0a07ade86e9fef2839c3528ab1132fdb535fa8d209bb4
3
+ metadata.gz: e8f15617864719123de4834de4b15ae72db7ab5015e9a58a5abd51e4d08dbdac
4
+ data.tar.gz: 41e3736a899549a250bdfe9067e7b8c9d8cbbd24662c4eba4e6f2bebedabe3d0
5
5
  SHA512:
6
- metadata.gz: 2e16c445680e2290940c5d23eb712c26b2b1d893f3e254940fecdb77b0dc1413eb5ed9bfd66b0e52476a14924d86f3b08937d1510ce8c663f6e6105901eb5ef4
7
- data.tar.gz: 6a0db61a950f75867be10eae911c15812f6b5987957d514f362445b52eb9558f994712283590d01bbf042688a6aa608e9e6f6b87722bf3f754902dbb6e9eef67
6
+ metadata.gz: 65ec9158b0afd2ca52b44133f70aa9355ba515c520a78eddc95d1e2d576917c2a5e1bf9a40dae5caf6bc5e3f14a9b5798700a2c9928df03a10d9453198b30273
7
+ data.tar.gz: a60f5bc98eef97a940fad99c84111c164f6948ce01c17929cea9c712ec1403084b293119895e88138f0284c1fc53419e797b5944cabcf55fc8159c312884a417
data/README.md CHANGED
@@ -20,39 +20,20 @@ Or install it yourself as:
20
20
  ## Usage
21
21
 
22
22
  ### Setup Client
23
-
23
+ To configure your client, provide your `api_key` and `project_id`, see below:
24
24
  ```ruby
25
25
  require 'convoy'
26
26
 
27
27
  Convoy.ssl = true
28
28
  Convoy.api_key = "CO.M0aBe..."
29
- Convoy.path_version = "v1"
30
- Convoy.base_uri = "https://dashboard.getconvoy.io/api"
31
-
32
- ```
33
-
34
- ### Creating an application
35
- An application represents a user's application trying to receive webhooks. Once you create an application, you'll receive a `uid` as part of the response that you should save and supply in subsequent API calls to perform other requests such as creating an event.
36
-
37
- ```ruby
38
- app = Convoy::Application.new(
39
- params: {
40
- groupID: "c3637195-53cd-4eba-b9df-e7ba9479fbb2"
41
- },
42
- data: {
43
- name: "Integration One"
44
- }
45
- )
46
-
47
- app_response = app.save
29
+ Convoy.project_id = "23b1..."
48
30
  ```
49
31
 
50
- ### Add an Endpoint to Application
51
- After creating an application, you'll need to add an endpoint to the application you just created. An endpoint represents a target URL to receive events.
32
+ ### Create Endpoint
33
+ An endpoint represents a target URL to receive webhook events. You should create one endpoint per user/business or whatever scope works well for you.
52
34
 
53
35
  ```ruby
54
36
  endpoint = Convoy::Endpoint.new(
55
- app_id,
56
37
  data: {
57
38
  "description": "Endpoint One",
58
39
  "http_timeout": "1m",
@@ -69,25 +50,21 @@ After creating an endpoint, we need to susbcribe the endpoint to events.
69
50
  ```ruby
70
51
  subscription = Convoy::Subscription.new(
71
52
  data: {
72
- app_id: app_id,
73
53
  endpoint_id: endpoint_id,
74
- name: 'ruby subscription',
75
- filter_config: {
76
- event_types: [ "*" ]
77
- }
54
+ name: 'ruby subscription'
78
55
  }
79
56
  )
80
57
 
81
58
  subscription_response = subscription.save
82
59
  ```
83
60
 
84
- ### Publish an Event
85
- Now let's publish an event.
61
+ ### Send Event
62
+ To send an event, you'll need to pass the `uid` from the endpoint we created earlier.
86
63
 
87
64
  ```ruby
88
65
  event = Convoy::Event.new(
89
66
  data: {
90
- app_id: app_id,
67
+ endpoint_id: endpoint_id,
91
68
  event_type: "wallet.created",
92
69
  data: {
93
70
  status: "completed",
data/convoy.gemspec CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.description = "Convoy ruby client to push webhook events from any ruby application."
11
11
  spec.homepage = "https://getconvoy.io"
12
12
  spec.license = "MIT"
13
- spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
13
+ spec.required_ruby_version = Gem::Requirement.new(">= 3.0.0")
14
14
 
15
15
  spec.metadata["homepage_uri"] = spec.homepage
16
16
  spec.metadata["source_code_uri"] = "https://github.com/frain-dev/convoy.rb"
@@ -10,7 +10,7 @@ module Convoy
10
10
  @id = id
11
11
  @config = config
12
12
 
13
- super(kwargs)
13
+ super(**kwargs)
14
14
  end
15
15
 
16
16
  def resource_uri
@@ -8,7 +8,7 @@ module Convoy
8
8
  @eventId = eventId
9
9
  @config = config
10
10
 
11
- super(kwargs)
11
+ super(**kwargs)
12
12
  end
13
13
 
14
14
  def resource_uri
@@ -10,7 +10,7 @@ module Convoy
10
10
  @id = id
11
11
  @config = config
12
12
 
13
- super(kwargs)
13
+ super(**kwargs)
14
14
  end
15
15
 
16
16
  def resource_uri
@@ -20,5 +20,10 @@ module Convoy
20
20
 
21
21
  "#{project_base_uri}/endpoints/#{@id}"
22
22
  end
23
+
24
+ def pause
25
+ pause_uri = "#{resource_uri}/pause"
26
+ send_request(pause_uri, :post, data: @data, params: @params)
27
+ end
23
28
  end
24
29
  end
@@ -10,7 +10,7 @@ module Convoy
10
10
  @id = id
11
11
  @config = config
12
12
 
13
- super(kwargs)
13
+ super(**kwargs)
14
14
  end
15
15
 
16
16
  def resource_uri
@@ -20,5 +20,10 @@ module Convoy
20
20
 
21
21
  "#{project_base_uri}/events/#{@id}"
22
22
  end
23
+
24
+ def fanout
25
+ fanout_uri = "#{resource_uri}/fanout"
26
+ send_request(fanout_uri, :post, data: @data, params: @params)
27
+ end
23
28
  end
24
29
  end
@@ -8,7 +8,7 @@ module Convoy
8
8
  @eventId = eventId
9
9
  @config = config
10
10
 
11
- super(kwargs)
11
+ super(**kwargs)
12
12
  end
13
13
 
14
14
  def resource_uri
@@ -19,7 +19,15 @@ module Convoy
19
19
  "#{project_base_uri}/events/#{@eventId}/eventdelivery/#{@id}"
20
20
  end
21
21
 
22
- # TODO: resend event delivery.
22
+
23
+ def retry
24
+ retry_uri = "#{resource_uri}/resend"
25
+ send_request(retry_uri, :put, data: @data, params: @params)
26
+ end
23
27
 
28
+ def force_retry
29
+ force_retry_uri = "#{resource_uri}/forceresend"
30
+ send_request(force_retry_uri, :post, data: @data, params: @params)
31
+ end
24
32
  end
25
33
  end
@@ -0,0 +1,24 @@
1
+ module Convoy
2
+ class PortalLink < ApiResource
3
+ include ApiOperations::Get
4
+ include ApiOperations::Save
5
+ include ApiOperations::List
6
+ include ApiOperations::Delete
7
+ extend ApiOperations::Create
8
+
9
+ def initialize(id = nil, config = Convoy.config, **kwargs)
10
+ @id = id
11
+ @config = config
12
+
13
+ super(**kwargs)
14
+ end
15
+
16
+ def resource_uri
17
+ if @id.nil?
18
+ return "#{project_base_uri}/portal-links"
19
+ end
20
+
21
+ "#{project_base_uri}/portal-links/#{@id}"
22
+ end
23
+ end
24
+ end
@@ -10,7 +10,7 @@ module Convoy
10
10
  @id = id
11
11
  @config = config
12
12
 
13
- super(kwargs)
13
+ super(**kwargs)
14
14
  end
15
15
 
16
16
  def resource_uri
@@ -9,7 +9,7 @@ module Convoy
9
9
  @id = id
10
10
  @config = config
11
11
 
12
- super(kwargs)
12
+ super(**kwargs)
13
13
  end
14
14
 
15
15
  def resource_uri
@@ -9,7 +9,7 @@ module Convoy
9
9
  @id = id
10
10
  @config = config
11
11
 
12
- super(kwargs)
12
+ super(**kwargs)
13
13
  end
14
14
 
15
15
  def resource_uri
@@ -1,3 +1,3 @@
1
1
  module Convoy
2
- VERSION = "0.2.0"
2
+ VERSION = "0.4.0"
3
3
  end
@@ -34,8 +34,7 @@ module Convoy
34
34
  is_advanced = (sig_header.split(",")).length > 1
35
35
 
36
36
  if is_advanced
37
- verify_advanced_signature(payload, sig_header)
38
- return
37
+ return verify_advanced_signature(payload, sig_header)
39
38
  end
40
39
 
41
40
  verify_simple_signature(payload, sig_header)
@@ -47,15 +46,18 @@ module Convoy
47
46
  return Util.secure_compare(compute_signature(payload), sig_header)
48
47
  end
49
48
 
50
- def verify_advanced_signature
49
+ def verify_advanced_signature(payload, sig_header)
51
50
  timestamp_header, signatures = get_timestamp_and_signatures(sig_header)
51
+ payload = "#{Integer(timestamp_header)},#{payload}"
52
52
 
53
53
  verify_timestamp(timestamp_header)
54
54
 
55
- unless signatures.any? { |s| Util.secure_compare(expected_sig, s) }
55
+ unless signatures.any? { |s| Util.secure_compare(compute_signature(payload), s) }
56
56
  raise SignatureVerificationError.new,
57
57
  "No signatures found matching the expected signature for payload"
58
58
  end
59
+
60
+ return true
59
61
  end
60
62
 
61
63
  def verify_timestamp(timestamp_header)
@@ -74,18 +76,20 @@ module Convoy
74
76
  # return encoded string
75
77
  def compute_signature(payload)
76
78
  case @encoding
77
- when "hex":
78
- return OpenSSL::HMAC.hexdigest(@hash, @secret, payload)
79
- when "base64":
79
+ when "hex"
80
+ val = OpenSSL::HMAC.hexdigest(@hash, @secret, payload)
81
+ return val
82
+ when "base64"
80
83
  hmac = OpenSSL::HMAC.digest(@hash, @secret, payload)
81
- return Base64.encode64(hmac)
84
+ return Base64.strict_encode64(hmac)
82
85
  end
83
86
  end
84
87
 
85
88
  def get_timestamp_and_signatures(sig_header)
86
89
  list_items = sig_header.split(/,\s*/).map { |i| i.split("=", 2) }
87
90
  timestamp = Integer(list_items.select { |i| i[0] == "t" }[0][1])
88
- [Time.at(timestamp), list_items[1]]
91
+ signatures = list_items[1..].map { |i| i[1] }
92
+ [Time.at(timestamp), signatures]
89
93
  end
90
94
  end
91
95
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: convoy.rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Subomi Oluwalana
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-11-24 00:00:00.000000000 Z
11
+ date: 2024-01-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: zeitwerk
@@ -58,6 +58,7 @@ files:
58
58
  - lib/convoy/resources/endpoint.rb
59
59
  - lib/convoy/resources/event.rb
60
60
  - lib/convoy/resources/event_delivery.rb
61
+ - lib/convoy/resources/portal_link.rb
61
62
  - lib/convoy/resources/project.rb
62
63
  - lib/convoy/resources/source.rb
63
64
  - lib/convoy/resources/subscription.rb
@@ -71,7 +72,7 @@ metadata:
71
72
  homepage_uri: https://getconvoy.io
72
73
  source_code_uri: https://github.com/frain-dev/convoy.rb
73
74
  changelog_uri: https://github.com/frain-dev/convoy.rb/blob/main/CHANGELOG
74
- post_install_message:
75
+ post_install_message:
75
76
  rdoc_options: []
76
77
  require_paths:
77
78
  - lib
@@ -79,15 +80,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
79
80
  requirements:
80
81
  - - ">="
81
82
  - !ruby/object:Gem::Version
82
- version: 2.3.0
83
+ version: 3.0.0
83
84
  required_rubygems_version: !ruby/object:Gem::Requirement
84
85
  requirements:
85
86
  - - ">="
86
87
  - !ruby/object:Gem::Version
87
88
  version: '0'
88
89
  requirements: []
89
- rubygems_version: 3.1.4
90
- signing_key:
90
+ rubygems_version: 3.3.7
91
+ signing_key:
91
92
  specification_version: 4
92
93
  summary: Convoy Ruby Client.
93
94
  test_files: []