hooksniff 0.1.0 → 1.0.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.
Files changed (78) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +7 -0
  3. data/Gemfile.lock +56 -0
  4. data/README.md +24 -197
  5. data/Rakefile +2 -0
  6. data/hooksniff.gemspec +48 -0
  7. data/lib/hooksniff/api/authentication.rb +36 -0
  8. data/lib/hooksniff/api/endpoint.rb +102 -0
  9. data/lib/hooksniff/api/event_type.rb +66 -0
  10. data/lib/hooksniff/api/health.rb +16 -0
  11. data/lib/hooksniff/api/message.rb +48 -0
  12. data/lib/hooksniff/api/message_attempt.rb +38 -0
  13. data/lib/hooksniff/api/statistics.rb +37 -0
  14. data/lib/hooksniff/api_error.rb +48 -0
  15. data/lib/hooksniff/errors.rb +107 -21
  16. data/lib/hooksniff/hooksniff.rb +36 -0
  17. data/lib/hooksniff/hooksniff_http_client.rb +128 -0
  18. data/lib/hooksniff/http_error_out.rb +18 -0
  19. data/lib/hooksniff/http_validation_error.rb +18 -0
  20. data/lib/hooksniff/internal.rb +7 -0
  21. data/lib/hooksniff/models/aggregate_event_types_out.rb +59 -0
  22. data/lib/hooksniff/models/endpoint_created_event.rb +50 -0
  23. data/lib/hooksniff/models/endpoint_created_event_data.rb +63 -0
  24. data/lib/hooksniff/models/endpoint_deleted_event.rb +50 -0
  25. data/lib/hooksniff/models/endpoint_deleted_event_data.rb +63 -0
  26. data/lib/hooksniff/models/endpoint_disabled_event.rb +53 -0
  27. data/lib/hooksniff/models/endpoint_disabled_event_data.rb +69 -0
  28. data/lib/hooksniff/models/endpoint_enabled_event.rb +50 -0
  29. data/lib/hooksniff/models/endpoint_enabled_event_data.rb +63 -0
  30. data/lib/hooksniff/models/endpoint_headers_in.rb +46 -0
  31. data/lib/hooksniff/models/endpoint_headers_out.rb +52 -0
  32. data/lib/hooksniff/models/endpoint_headers_patch_in.rb +53 -0
  33. data/lib/hooksniff/models/endpoint_in.rb +102 -0
  34. data/lib/hooksniff/models/endpoint_out.rb +104 -0
  35. data/lib/hooksniff/models/endpoint_patch.rb +97 -0
  36. data/lib/hooksniff/models/endpoint_secret_out.rb +50 -0
  37. data/lib/hooksniff/models/endpoint_secret_rotate_in.rb +53 -0
  38. data/lib/hooksniff/models/endpoint_update.rb +90 -0
  39. data/lib/hooksniff/models/endpoint_updated_event.rb +50 -0
  40. data/lib/hooksniff/models/endpoint_updated_event_data.rb +63 -0
  41. data/lib/hooksniff/models/event_in.rb +50 -0
  42. data/lib/hooksniff/models/event_out.rb +53 -0
  43. data/lib/hooksniff/models/event_type_in.rb +80 -0
  44. data/lib/hooksniff/models/event_type_out.rb +87 -0
  45. data/lib/hooksniff/models/event_type_patch.rb +66 -0
  46. data/lib/hooksniff/models/event_type_update.rb +67 -0
  47. data/lib/hooksniff/models/list_response_endpoint_out.rb +58 -0
  48. data/lib/hooksniff/models/list_response_event_type_out.rb +58 -0
  49. data/lib/hooksniff/models/list_response_message_attempt_out.rb +58 -0
  50. data/lib/hooksniff/models/list_response_message_out.rb +58 -0
  51. data/lib/hooksniff/models/message_attempt_exhausted_event.rb +53 -0
  52. data/lib/hooksniff/models/message_attempt_exhausted_event_data.rb +70 -0
  53. data/lib/hooksniff/models/message_attempt_failed_data.rb +56 -0
  54. data/lib/hooksniff/models/message_attempt_failing_event.rb +54 -0
  55. data/lib/hooksniff/models/message_attempt_failing_event_data.rb +70 -0
  56. data/lib/hooksniff/models/message_attempt_log.rb +112 -0
  57. data/lib/hooksniff/models/message_attempt_log_event.rb +53 -0
  58. data/lib/hooksniff/models/message_attempt_out.rb +96 -0
  59. data/lib/hooksniff/models/message_attempt_recovered_event.rb +53 -0
  60. data/lib/hooksniff/models/message_attempt_recovered_event_data.rb +70 -0
  61. data/lib/hooksniff/models/message_attempt_trigger_type.rb +33 -0
  62. data/lib/hooksniff/models/message_endpoint_out.rb +112 -0
  63. data/lib/hooksniff/models/message_in.rb +100 -0
  64. data/lib/hooksniff/models/message_out.rb +71 -0
  65. data/lib/hooksniff/models/message_status.rb +39 -0
  66. data/lib/hooksniff/models/message_status_text.rb +32 -0
  67. data/lib/hooksniff/models/ordering.rb +30 -0
  68. data/lib/hooksniff/models/status_code_class.rb +41 -0
  69. data/lib/hooksniff/util.rb +69 -0
  70. data/lib/hooksniff/validation_error.rb +28 -0
  71. data/lib/hooksniff/version.rb +1 -1
  72. data/lib/hooksniff/webhook.rb +84 -0
  73. data/lib/hooksniff.rb +71 -12
  74. data/test/test_hooksniff.rb +86 -0
  75. metadata +124 -31
  76. data/lib/hooksniff/client.rb +0 -213
  77. data/lib/hooksniff/models.rb +0 -136
  78. data/lib/hooksniff/verification.rb +0 -134
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d57c84b0d53e5a0affb8331d0a7b6f875783237e8e39791c472be7dde9b55633
4
- data.tar.gz: c0515dc716d6c05b45779530f87af8c0bfa1be1e7de760055510311ebbdf60c8
3
+ metadata.gz: b5aaa88a65699339eb037c794a5d39c3cf2a7aecd9f51536c66f724ceb167e63
4
+ data.tar.gz: 8fc8649416effe14346d24ef9d9853f84b47f172f4e8521761f5a386b1017a47
5
5
  SHA512:
6
- metadata.gz: 68b178b1d814e4112af255c973522bc461d21042ab835c90dbc4ad7d4a7be29c1fd5c6d9ff0c7416cd79776e90422dc30e525def3f125c1cf8a5662b9eea1f01
7
- data.tar.gz: f1c27cbb1954ab4a1785cdd351bce37d1bdce6b695282925c07a2c90f19ffbf4927ca2e702f089666679f0ceafaef7844777d4a97322101b8818f363ee084229
6
+ metadata.gz: 28cf8842859a1b34b5fa563d8e076845d2657d956c4bcde51be444ee250aaaedae8814eb354130884a733ba6e9b9de5cfac3883d63da697f5db113973806362f
7
+ data.tar.gz: f3d265478cc4bba62e1eb27631da361d3249529d45ab06111babd9adbdd57223b954c23e49b5cdea9671d3c62067ea89254c19948b3b1acf66c62333f7a907c4
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem 'base64'
4
+ gem 'logger'
5
+ gem 'ostruct'
6
+
7
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,56 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ svix (1.93.0)
5
+ base64 (~> 0.3.0)
6
+ logger (~> 1.0)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ addressable (2.9.0)
12
+ public_suffix (>= 2.0.2, < 8.0)
13
+ base64 (0.3.0)
14
+ bigdecimal (4.1.1)
15
+ crack (1.0.1)
16
+ bigdecimal
17
+ rexml
18
+ diff-lcs (1.6.2)
19
+ hashdiff (1.2.1)
20
+ logger (1.7.0)
21
+ ostruct (0.6.3)
22
+ public_suffix (7.0.5)
23
+ rake (13.4.1)
24
+ rexml (3.4.4)
25
+ rspec (3.13.2)
26
+ rspec-core (~> 3.13.0)
27
+ rspec-expectations (~> 3.13.0)
28
+ rspec-mocks (~> 3.13.0)
29
+ rspec-core (3.13.6)
30
+ rspec-support (~> 3.13.0)
31
+ rspec-expectations (3.13.5)
32
+ diff-lcs (>= 1.2.0, < 2.0)
33
+ rspec-support (~> 3.13.0)
34
+ rspec-mocks (3.13.8)
35
+ diff-lcs (>= 1.2.0, < 2.0)
36
+ rspec-support (~> 3.13.0)
37
+ rspec-support (3.13.7)
38
+ webmock (3.26.2)
39
+ addressable (>= 2.8.0)
40
+ crack (>= 0.3.2)
41
+ hashdiff (>= 0.4.0, < 2.0.0)
42
+
43
+ PLATFORMS
44
+ ruby
45
+
46
+ DEPENDENCIES
47
+ base64
48
+ logger
49
+ ostruct
50
+ rake (~> 13.0)
51
+ rspec (~> 3.2)
52
+ svix!
53
+ webmock (~> 3.25)
54
+
55
+ BUNDLED WITH
56
+ 2.6.5
data/README.md CHANGED
@@ -1,16 +1,12 @@
1
1
  # HookSniff Ruby SDK
2
2
 
3
- Official Ruby client for the [HookSniff](https://hooksniff.vercel.app) webhook delivery service.
3
+ <p align="center">
4
+ <a href="https://github.com/servetarslan02/HookSniff"><img src="https://img.shields.io/github/license/servetarslan02/HookSniff" alt="License"></a>
5
+ </p>
4
6
 
5
- ## Installation
6
-
7
- Add to your Gemfile:
8
-
9
- ```ruby
10
- gem "hooksniff"
11
- ```
7
+ Ruby SDK for the [HookSniff](https://hooksniff.com) webhook delivery platform.
12
8
 
13
- Or install directly:
9
+ ## Installation
14
10
 
15
11
  ```bash
16
12
  gem install hooksniff
@@ -21,200 +17,31 @@ gem install hooksniff
21
17
  ```ruby
22
18
  require "hooksniff"
23
19
 
24
- # Initialize client
25
- client = HookSniff::Client.new(api_key: "hr_live_your_api_key_here")
26
-
27
- # Create a webhook endpoint
28
- endpoint = client.endpoints.create(
29
- url: "https://myapp.com/webhook",
30
- description: "Order notifications"
31
- )
32
- puts "Endpoint created: #{endpoint[:id]}"
33
-
34
- # Send a webhook
35
- delivery = client.webhooks.send(
36
- endpoint_id: endpoint[:id],
37
- event: "order.created",
38
- data: { order_id: "12345", amount: 99.99 }
39
- )
40
- puts "Delivery queued: #{delivery[:id]}, status: #{delivery[:status]}"
41
-
42
- # Check delivery status
43
- status = client.webhooks.get(delivery[:id])
44
- puts "Status: #{status[:status]}, attempts: #{status[:attempt_count]}"
45
-
46
- # List deliveries
47
- deliveries = client.webhooks.list(status: "failed", page: 1)
48
- deliveries[:deliveries].each do |d|
49
- puts " #{d[:id]}: #{d[:status]}"
50
- end
51
-
52
- # Replay a failed delivery
53
- replayed = client.webhooks.replay(delivery[:id])
54
- puts "Replay queued: #{replayed[:id]}"
55
- ```
56
-
57
- ## Batch Webhooks
58
-
59
- Send multiple webhooks in a single request (max 100):
60
-
61
- ```ruby
62
- results = client.webhooks.batch([
63
- { endpoint_id: "ep_1", event: "order.created", data: { order_id: "12345" } },
64
- { endpoint_id: "ep_2", event: "payment.completed", data: { payment_id: "pay_67890" } }
65
- ])
66
-
67
- puts "Delivered: #{results[:deliveries].length}"
68
- puts "Errors: #{results[:errors].length}"
69
- results[:errors].each do |err|
70
- puts " Item #{err['index']}: #{err['error']}"
71
- end
72
- ```
73
-
74
- ## Retry Policy
75
-
76
- Configure custom retry behavior when creating endpoints:
77
-
78
- ```ruby
79
- endpoint = client.endpoints.create(
80
- url: "https://myapp.com/webhook",
81
- description: "Critical notifications",
82
- retry_policy: {
83
- max_attempts: 5,
84
- backoff: "exponential",
85
- initial_delay_secs: 10,
86
- max_delay_secs: 3600
87
- }
88
- )
89
- ```
90
-
91
- ## Delivery Attempts
92
-
93
- Inspect individual delivery attempts:
94
-
95
- ```ruby
96
- attempts = client.webhooks.attempts(delivery[:id])
97
- attempts.each do |attempt|
98
- puts " Attempt #{attempt[:attempt_number]}: status=#{attempt[:status_code]}, " \
99
- "duration=#{attempt[:duration_ms]}ms"
100
- puts " Error: #{attempt[:error_message]}" if attempt[:error_message]
101
- end
102
- ```
103
-
104
- ## Export Logs
105
-
106
- Export webhook logs as JSON or CSV:
107
-
108
- ```ruby
109
- # JSON export
110
- logs = client.webhooks.export(format: "json", status: "failed")
111
-
112
- # CSV export
113
- csv_data = client.webhooks.export(format: "csv", date_from: "2024-01-01")
114
- File.write("webhooks.csv", csv_data)
115
- ```
116
-
117
- ## Signature Verification
118
-
119
- Verify incoming webhook signatures in your handler:
120
-
121
- ```ruby
122
- require "hooksniff"
123
- require "sinatra"
124
-
125
- post "/webhook" do
126
- payload = request.body.read
127
- signature = request.env["HTTP_X_HOOKRELAY_SIGNATURE"]
128
- secret = "whsec_your_endpoint_signing_secret"
129
-
130
- unless HookSniff.verify_signature(payload, signature, secret)
131
- halt 401, { error: "Invalid signature" }.to_json
132
- end
133
-
134
- data = JSON.parse(payload)
135
- puts "Received event: #{data['event']}"
136
- content_type :json
137
- { received: true }.to_json
138
- end
20
+ client = HookSniff::Client.new("hs_xxx")
21
+ endpoints = client.endpoint.list
22
+ puts endpoints
139
23
  ```
140
24
 
141
- ### Standard Webhooks Verification
142
-
143
- For Standard Webhooks compatible verification:
25
+ ## Webhook Verification
144
26
 
145
27
  ```ruby
146
- result = HookSniff.verify_webhook(
147
- payload: request.body.read,
148
- msg_id: request.env["HTTP_WEBHOOK_ID"],
149
- timestamp: request.env["HTTP_WEBHOOK_TIMESTAMP"],
150
- signature_header: request.env["HTTP_WEBHOOK_SIGNATURE"],
151
- secret: "whsec_..."
152
- )
153
-
154
- unless result[:valid]
155
- halt 401, { error: result[:error] }.to_json
156
- end
157
-
158
- puts "Event: #{result[:payload]['event']}"
28
+ wh = HookSniff::Webhook.new("whsec_xxx")
29
+ payload = wh.verify(body, headers)
159
30
  ```
160
31
 
161
- ## Error Handling
162
-
163
- ```ruby
164
- begin
165
- delivery = client.webhooks.send(
166
- endpoint_id: "nonexistent",
167
- event: "test.event",
168
- data: { test: true }
169
- )
170
- rescue HookSniff::AuthenticationError => e
171
- puts "Invalid API key"
172
- rescue HookSniff::NotFoundError => e
173
- puts "Endpoint not found"
174
- rescue HookSniff::RateLimitError => e
175
- puts "Rate limit exceeded - try again later"
176
- rescue HookSniff::ValidationError => e
177
- puts "Invalid request: #{e.message}"
178
- rescue HookSniff::PayloadTooLargeError => e
179
- puts "Payload exceeds maximum size"
180
- end
181
- ```
182
-
183
- ## API Reference
184
-
185
- ### `HookSniff::Client.new(api_key:, base_url: nil, timeout: nil)`
186
-
187
- | Option | Type | Default | Description |
188
- |--------|------|---------|-------------|
189
- | `api_key` | `String` | required | Your HookSniff API key |
190
- | `base_url` | `String` | `https://hooksniff-api-1046140057667.europe-west1.run.app/v1` | API base URL |
191
- | `timeout` | `Integer` | `30` | Request timeout in seconds |
192
-
193
- ### `client.endpoints`
194
-
195
- - `.create(url:, description: nil, retry_policy: nil)` → `Hash`
196
- - `.get(endpoint_id)` → `Hash`
197
- - `.list` → `Array<Hash>`
198
- - `.delete(endpoint_id)` → `Boolean`
199
-
200
- ### `client.webhooks`
201
-
202
- - `.send(endpoint_id:, data:, event: nil)` → `Hash`
203
- - `.get(delivery_id)` → `Hash`
204
- - `.list(status: nil, page: 1, per_page: 20)` → `Hash`
205
- - `.replay(delivery_id)` → `Hash`
206
- - `.batch(webhooks)` → `Hash`
207
- - `.attempts(delivery_id)` → `Array<Hash>`
208
- - `.export(format: nil, status: nil, date_from: nil, date_to: nil)` → `Array<Hash> | String`
209
-
210
- ### `HookSniff.verify_signature(payload, signature, secret)` → `Boolean`
211
-
212
- Verify a webhook signature using HMAC-SHA256.
213
-
214
- ### `HookSniff.verify_webhook(payload:, msg_id:, timestamp:, signature_header:, secret:, tolerance_secs: 300)` → `Hash`
32
+ ## Resources
215
33
 
216
- Verify a webhook using Standard Webheaders headers.
34
+ | Resource | Methods |
35
+ |----------|---------|
36
+ | Endpoint | list, create, get, update, delete |
37
+ | Message | create, list, get |
38
+ | MessageAttempt | list, listByMsg, get, resend |
39
+ | Authentication | dashboardAccess |
40
+ | EventType | list |
41
+ | Statistics | aggregate |
217
42
 
218
- ## License
43
+ ## Links
219
44
 
220
- MIT
45
+ - [Documentation](https://docs.hooksniff.com)
46
+ - [API Reference](https://api.hooksniff.com)
47
+ - [GitHub](https://github.com/servetarslan02/HookSniff)
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/hooksniff.gemspec ADDED
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path("../lib", __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require "hooksniff/version"
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = "hooksniff"
9
+ spec.version = HookSniff::VERSION
10
+ spec.authors = ["HookSniff"]
11
+ spec.email = ["support@hooksniff.vercel.app"]
12
+ spec.license = "MIT"
13
+
14
+ spec.summary = "HookSniff webhooks API client and webhook verification library"
15
+ spec.description = "HookSniff makes webhooks easy and reliable. " \
16
+ "Learn more at https://hooksniff.vercel.app"
17
+ spec.homepage = "https://hooksniff.vercel.app"
18
+
19
+ spec.required_ruby_version = ">= 3.2"
20
+
21
+ if spec.respond_to?(:metadata)
22
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
23
+ spec.metadata["homepage_uri"] = spec.homepage
24
+ spec.metadata["source_code_uri"] = "https://github.com/servetarslan02/HookSniff"
25
+ else
26
+ raise "RubyGems 2.0 or newer is required to protect against " \
27
+ "public gem pushes."
28
+ end
29
+
30
+ ignored = Regexp.union(
31
+ /\Aspec/,
32
+ /\Apkg/,
33
+ /\A.gitignore/,
34
+ /.gem\z/
35
+ )
36
+ spec.files = Dir['**/*'].reject {|f| !File.file?(f) || ignored.match(f) }
37
+
38
+ spec.bindir = "exe"
39
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
40
+ spec.require_paths = ["lib"]
41
+
42
+ spec.add_dependency "base64", "~> 0.3.0"
43
+ spec.add_dependency "logger", "~> 1.0"
44
+
45
+ spec.add_development_dependency "rake", "~> 13.0"
46
+ spec.add_development_dependency "rspec", "~> 3.2"
47
+ spec.add_development_dependency "webmock", "~> 3.25"
48
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "net/http"
4
+
5
+ module HookSniff
6
+ class Authentication
7
+ def initialize(client)
8
+ @client = client
9
+ end
10
+
11
+ def app_portal_access(app_id, app_portal_access_in, options = {})
12
+ options = options.transform_keys(&:to_s)
13
+ res = @client.execute_request(
14
+ "POST",
15
+ "/v1/auth/portal-access/#{app_id}",
16
+ headers: {
17
+ "idempotency-key" => options["idempotency-key"]
18
+ },
19
+ body: app_portal_access_in
20
+ )
21
+ DashboardAccessOut.deserialize(res)
22
+ end
23
+
24
+ def logout(options = {})
25
+ options = options.transform_keys(&:to_s)
26
+ @client.execute_request(
27
+ "POST",
28
+ "/v1/auth/logout",
29
+ headers: {
30
+ "idempotency-key" => options["idempotency-key"]
31
+ }
32
+ )
33
+ nil
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,102 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "net/http"
4
+
5
+ module HookSniff
6
+ class Endpoint
7
+ def initialize(client)
8
+ @client = client
9
+ end
10
+
11
+ def list(options = {})
12
+ options = options.transform_keys(&:to_s)
13
+ res = @client.execute_request(
14
+ "GET",
15
+ "/v1/endpoints",
16
+ query_params: {
17
+ "limit" => options["limit"],
18
+ "offset" => options["offset"]
19
+ }
20
+ )
21
+ ListResponseEndpointOut.deserialize(res)
22
+ end
23
+
24
+ def create(endpoint_in, options = {})
25
+ options = options.transform_keys(&:to_s)
26
+ res = @client.execute_request(
27
+ "POST",
28
+ "/v1/endpoints",
29
+ headers: {
30
+ "idempotency-key" => options["idempotency-key"]
31
+ },
32
+ body: endpoint_in
33
+ )
34
+ EndpointOut.deserialize(res)
35
+ end
36
+
37
+ def get(endpoint_id)
38
+ res = @client.execute_request("GET", "/v1/endpoints/#{endpoint_id}")
39
+ EndpointOut.deserialize(res)
40
+ end
41
+
42
+ def update(endpoint_id, endpoint_update)
43
+ res = @client.execute_request(
44
+ "PUT",
45
+ "/v1/endpoints/#{endpoint_id}",
46
+ body: endpoint_update
47
+ )
48
+ EndpointOut.deserialize(res)
49
+ end
50
+
51
+ def patch(endpoint_id, endpoint_patch)
52
+ res = @client.execute_request(
53
+ "PATCH",
54
+ "/v1/endpoints/#{endpoint_id}",
55
+ body: endpoint_patch
56
+ )
57
+ EndpointOut.deserialize(res)
58
+ end
59
+
60
+ def delete(endpoint_id)
61
+ @client.execute_request("DELETE", "/v1/endpoints/#{endpoint_id}")
62
+ nil
63
+ end
64
+
65
+ def rotate_secret(endpoint_id, endpoint_secret_rotate_in)
66
+ res = @client.execute_request(
67
+ "POST",
68
+ "/v1/endpoints/#{endpoint_id}/rotate-secret",
69
+ body: endpoint_secret_rotate_in
70
+ )
71
+ EndpointSecretOut.deserialize(res)
72
+ end
73
+
74
+ def get_headers(endpoint_id)
75
+ res = @client.execute_request("GET", "/v1/endpoints/#{endpoint_id}/headers")
76
+ EndpointHeadersOut.deserialize(res)
77
+ end
78
+
79
+ def update_headers(endpoint_id, endpoint_headers_in)
80
+ @client.execute_request(
81
+ "PUT",
82
+ "/v1/endpoints/#{endpoint_id}/headers",
83
+ body: endpoint_headers_in
84
+ )
85
+ nil
86
+ end
87
+
88
+ def patch_headers(endpoint_id, endpoint_headers_patch_in)
89
+ @client.execute_request(
90
+ "PATCH",
91
+ "/v1/endpoints/#{endpoint_id}/headers",
92
+ body: endpoint_headers_patch_in
93
+ )
94
+ nil
95
+ end
96
+
97
+ def get_secret(endpoint_id)
98
+ res = @client.execute_request("GET", "/v1/endpoints/#{endpoint_id}/secret")
99
+ EndpointSecretOut.deserialize(res)
100
+ end
101
+ end
102
+ end
@@ -0,0 +1,66 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "net/http"
4
+
5
+ module HookSniff
6
+ class EventType
7
+ def initialize(client)
8
+ @client = client
9
+ end
10
+
11
+ def list(options = {})
12
+ options = options.transform_keys(&:to_s)
13
+ res = @client.execute_request(
14
+ "GET",
15
+ "/v1/event-types",
16
+ query_params: {
17
+ "limit" => options["limit"],
18
+ "offset" => options["offset"],
19
+ "include_archived" => options["include_archived"]
20
+ }
21
+ )
22
+ ListResponseEventTypeOut.deserialize(res)
23
+ end
24
+
25
+ def create(event_type_in, options = {})
26
+ options = options.transform_keys(&:to_s)
27
+ res = @client.execute_request(
28
+ "POST",
29
+ "/v1/event-types",
30
+ headers: {
31
+ "idempotency-key" => options["idempotency-key"]
32
+ },
33
+ body: event_type_in
34
+ )
35
+ EventTypeOut.deserialize(res)
36
+ end
37
+
38
+ def get(event_type_name)
39
+ res = @client.execute_request("GET", "/v1/event-types/#{event_type_name}")
40
+ EventTypeOut.deserialize(res)
41
+ end
42
+
43
+ def update(event_type_name, event_type_update)
44
+ res = @client.execute_request(
45
+ "PUT",
46
+ "/v1/event-types/#{event_type_name}",
47
+ body: event_type_update
48
+ )
49
+ EventTypeOut.deserialize(res)
50
+ end
51
+
52
+ def patch(event_type_name, event_type_patch)
53
+ res = @client.execute_request(
54
+ "PATCH",
55
+ "/v1/event-types/#{event_type_name}",
56
+ body: event_type_patch
57
+ )
58
+ EventTypeOut.deserialize(res)
59
+ end
60
+
61
+ def delete(event_type_name)
62
+ @client.execute_request("DELETE", "/v1/event-types/#{event_type_name}")
63
+ nil
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "net/http"
4
+
5
+ module HookSniff
6
+ class Health
7
+ def initialize(client)
8
+ @client = client
9
+ end
10
+
11
+ def get
12
+ res = @client.execute_request("GET", "/v1/health")
13
+ res
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "net/http"
4
+
5
+ module HookSniff
6
+ class Message
7
+ def initialize(client)
8
+ @client = client
9
+ end
10
+
11
+ def create(message_in, options = {})
12
+ options = options.transform_keys(&:to_s)
13
+ res = @client.execute_request(
14
+ "POST",
15
+ "/v1/webhooks",
16
+ headers: {
17
+ "idempotency-key" => options["idempotency-key"]
18
+ },
19
+ body: message_in
20
+ )
21
+ MessageOut.deserialize(res)
22
+ end
23
+
24
+ def list(options = {})
25
+ options = options.transform_keys(&:to_s)
26
+ res = @client.execute_request(
27
+ "GET",
28
+ "/v1/webhooks",
29
+ query_params: {
30
+ "limit" => options["limit"],
31
+ "offset" => options["offset"],
32
+ "status" => options["status"]
33
+ }
34
+ )
35
+ ListResponseMessageOut.deserialize(res)
36
+ end
37
+
38
+ def get(message_id)
39
+ res = @client.execute_request("GET", "/v1/webhooks/#{message_id}")
40
+ MessageOut.deserialize(res)
41
+ end
42
+
43
+ def replay(message_id)
44
+ res = @client.execute_request("POST", "/v1/webhooks/#{message_id}/replay")
45
+ ReplayOut.deserialize(res)
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "net/http"
4
+
5
+ module HookSniff
6
+ class MessageAttempt
7
+ def initialize(client)
8
+ @client = client
9
+ end
10
+
11
+ def list_by_msg(message_id, options = {})
12
+ options = options.transform_keys(&:to_s)
13
+ res = @client.execute_request(
14
+ "GET",
15
+ "/v1/webhooks/#{message_id}/attempts",
16
+ query_params: {
17
+ "limit" => options["limit"],
18
+ "offset" => options["offset"],
19
+ "status" => options["status"]
20
+ }
21
+ )
22
+ ListResponseMessageAttemptOut.deserialize(res)
23
+ end
24
+
25
+ def get(attempt_id)
26
+ res = @client.execute_request("GET", "/v1/webhooks/attempts/#{attempt_id}")
27
+ MessageAttemptOut.deserialize(res)
28
+ end
29
+
30
+ def resend(message_id, endpoint_id)
31
+ res = @client.execute_request(
32
+ "POST",
33
+ "/v1/webhooks/#{message_id}/attempts/#{endpoint_id}/resend"
34
+ )
35
+ nil
36
+ end
37
+ end
38
+ end