hookbridge 2.2.0 → 2.3.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 +4 -4
- data/CHANGELOG.md +15 -0
- data/README.md +42 -0
- data/lib/hookbridge/client.rb +128 -9
- data/lib/hookbridge/errors.rb +4 -2
- data/lib/hookbridge/types.rb +87 -0
- data/lib/hookbridge/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 31ac5b314c6d5525fc2d2faec83ecb4809454e52b449db44354e230dee9cf58c
|
|
4
|
+
data.tar.gz: 989f74a14e87a7f9a41ca68716aabc7a8b6cd38f0ab00d72782c93670d77ad11
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 31cd75696ef83464e4e912f8215a02db23965e97568ca027f13e23020b3a306bbdff19fc4a794eb9def6b106e4e17ae5399c023fad0bc64952d88fb04c413c4e
|
|
7
|
+
data.tar.gz: 29cf35afae19cd298e50f18c6e1e402ef7a277acc1dbc7aa0e29c1c21d8447bfdf51ff78794d52a8a85e317b8283121a980a1581d83f2c6ab56b7c9c4a09136e
|
data/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,21 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [2.3.0] - 2026-11-24
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- `send_event` - Send a typed event, delivered to every endpoint subscribed to the type (or to one `endpoint_id`)
|
|
13
|
+
- `create_event_type`, `list_event_types`, `get_event_type`, `update_event_type`, `archive_event_type`, `unarchive_event_type`, `list_event_type_groups` - Manage the event type catalog
|
|
14
|
+
- `list_events`, `get_event`, `delete_event` - Inspect and delete events
|
|
15
|
+
- `subscriptions` on `create_endpoint` and `update_endpoint`, and an `event_type` filter on `list_endpoints`
|
|
16
|
+
- `recover_endpoint`, `get_recover_job` - Give an endpoint the events it missed in a time window
|
|
17
|
+
- `send_test_event` - Send a test message of an event type to an endpoint
|
|
18
|
+
- `event_type`, `event_id` and `is_test` on messages (`get_message`) and log entries (`get_logs`); `nil` for untyped messages
|
|
19
|
+
- `status_counts` on events (`list_events`, `get_event`): message counts by status, plus `deleted`
|
|
20
|
+
- `endpoint_id` filter on `get_logs`
|
|
21
|
+
- `client_name` option on `HookBridge::Client.new`; sent as `X-Hookbridge-Client` (printable ASCII, up to 200 bytes) and recorded in the audit trail of replay, retry and cancel actions. It is self-reported and not authenticated
|
|
22
|
+
|
|
8
23
|
## [2.2.0] - 2026-11-19
|
|
9
24
|
|
|
10
25
|
### Added
|
data/README.md
CHANGED
|
@@ -36,6 +36,13 @@ result = client.send(
|
|
|
36
36
|
puts result.message_id
|
|
37
37
|
```
|
|
38
38
|
|
|
39
|
+
To label your integration in the audit trail of replay, retry and cancel actions, pass `client_name`
|
|
40
|
+
(printable ASCII, up to 200 bytes; self-reported, not authenticated). It is sent as `X-Hookbridge-Client`.
|
|
41
|
+
|
|
42
|
+
```ruby
|
|
43
|
+
client = HookBridge.new(api_key: "hb_live_xxxxxxxxxxxxxxxxxxxx", client_name: "my-integration/1.0")
|
|
44
|
+
```
|
|
45
|
+
|
|
39
46
|
## Outbound Endpoints
|
|
40
47
|
|
|
41
48
|
```ruby
|
|
@@ -63,6 +70,7 @@ result = client.send(
|
|
|
63
70
|
|
|
64
71
|
message = client.get_message(result.message_id)
|
|
65
72
|
logs = client.get_logs(limit: 100)
|
|
73
|
+
endpoint_logs = client.get_logs(endpoint_id: endpoint.id)
|
|
66
74
|
metrics = client.get_metrics
|
|
67
75
|
timeseries = client.get_timeseries_metrics(endpoint_id: endpoint.id)
|
|
68
76
|
|
|
@@ -77,6 +85,40 @@ page.actions.each { |action| puts "#{action.action} via #{action.via}" }
|
|
|
77
85
|
page = client.list_message_actions(message.id, cursor: page.next_cursor) if page.has_more
|
|
78
86
|
```
|
|
79
87
|
|
|
88
|
+
## Event Types
|
|
89
|
+
|
|
90
|
+
```ruby
|
|
91
|
+
client.create_event_type(name: "order.created", group: "orders", description: "A customer placed an order")
|
|
92
|
+
|
|
93
|
+
endpoint = client.create_endpoint(
|
|
94
|
+
url: "https://customer.app/webhooks",
|
|
95
|
+
subscriptions: { event_types: ["order.created"], groups: ["billing"] }
|
|
96
|
+
)
|
|
97
|
+
client.update_endpoint(endpoint.id, subscriptions: { event_types: ["order.*"] }) # omit to leave unchanged
|
|
98
|
+
client.list_endpoints(event_type: "order.created")
|
|
99
|
+
|
|
100
|
+
sent = client.send_event("order.created", { order_id: "ord_123" }) # fans out to subscribed endpoints
|
|
101
|
+
event = client.get_event(sent.event_id)
|
|
102
|
+
puts event.matched_count
|
|
103
|
+
puts event.status_counts # { "succeeded" => 2, "deleted" => 1 }, {} when no messages
|
|
104
|
+
message = client.get_message(event.messages.first.id)
|
|
105
|
+
puts message.event_type, message.event_id, message.is_test # nil for untyped messages
|
|
106
|
+
client.list_events(event_type: "order.created", since: Time.now - 3600)
|
|
107
|
+
client.delete_event(sent.event_id)
|
|
108
|
+
|
|
109
|
+
types = client.list_event_types(name_prefix: "order.", include_archived: false)
|
|
110
|
+
client.update_event_type("order.created", group: nil) # nil clears the group
|
|
111
|
+
client.archive_event_type("order.created")
|
|
112
|
+
client.unarchive_event_type("order.created")
|
|
113
|
+
client.list_event_type_groups
|
|
114
|
+
|
|
115
|
+
job = client.recover_endpoint(endpoint.id, since: Time.now - 86_400)
|
|
116
|
+
client.get_recover_job(endpoint.id, job.recover_job_id)
|
|
117
|
+
client.send_test_event(endpoint.id, event_type: "order.created")
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
Event `target_endpoint_id` and event message `endpoint_id` are public `ep_...` ids, not raw UUIDs.
|
|
121
|
+
|
|
80
122
|
## Inbound Webhooks
|
|
81
123
|
|
|
82
124
|
```ruby
|
data/lib/hookbridge/client.rb
CHANGED
|
@@ -11,17 +11,22 @@ module HookBridge
|
|
|
11
11
|
DEFAULT_SEND_URL = "https://send.hookbridge.io"
|
|
12
12
|
DEFAULT_TIMEOUT = 30
|
|
13
13
|
DEFAULT_RETRIES = 3
|
|
14
|
+
UNSET = Object.new.freeze
|
|
15
|
+
private_constant :UNSET
|
|
14
16
|
|
|
15
17
|
attr_reader :api_key, :base_url, :send_url, :timeout, :retries
|
|
16
18
|
|
|
17
|
-
def initialize(api_key:, base_url: nil, send_url: nil, timeout: DEFAULT_TIMEOUT, retries: DEFAULT_RETRIES
|
|
19
|
+
def initialize(api_key:, base_url: nil, send_url: nil, timeout: DEFAULT_TIMEOUT, retries: DEFAULT_RETRIES,
|
|
20
|
+
client_name: nil)
|
|
18
21
|
raise ValidationError, "API key is required" if api_key.nil? || api_key.empty?
|
|
22
|
+
raise ValidationError, "client_name must be printable ASCII" unless valid_client_name?(client_name)
|
|
19
23
|
|
|
20
24
|
@api_key = api_key
|
|
21
25
|
@base_url = (base_url || ENV.fetch("HOOKBRIDGE_BASE_URL", DEFAULT_BASE_URL)).chomp("/")
|
|
22
26
|
@send_url = (send_url || ENV.fetch("HOOKBRIDGE_SEND_URL", DEFAULT_SEND_URL)).chomp("/")
|
|
23
27
|
@timeout = timeout
|
|
24
28
|
@retries = retries
|
|
29
|
+
@client_name = client_name
|
|
25
30
|
@connection = build_connection(@base_url)
|
|
26
31
|
@send_connection = build_connection(@send_url)
|
|
27
32
|
end
|
|
@@ -34,6 +39,15 @@ module HookBridge
|
|
|
34
39
|
SendResponse.new(extract_data(request(:post, "/v1/webhooks/send", body, use_send_connection: true)))
|
|
35
40
|
end
|
|
36
41
|
|
|
42
|
+
def send_event(event_type, payload, endpoint_id: nil, headers: nil, idempotency_key: nil, retention_hours: nil)
|
|
43
|
+
body = { event_type: event_type, payload: payload }
|
|
44
|
+
body[:endpoint_id] = endpoint_id if endpoint_id
|
|
45
|
+
body[:headers] = headers if headers
|
|
46
|
+
body[:idempotency_key] = idempotency_key if idempotency_key
|
|
47
|
+
body[:retention_hours] = retention_hours unless retention_hours.nil?
|
|
48
|
+
SendEventResponse.new(extract_data(request(:post, "/v1/webhooks/send", body, use_send_connection: true)))
|
|
49
|
+
end
|
|
50
|
+
|
|
37
51
|
def get_message(message_id)
|
|
38
52
|
Message.new(extract_data(request(:get, "/v1/messages/#{message_id}")))
|
|
39
53
|
end
|
|
@@ -82,8 +96,9 @@ module HookBridge
|
|
|
82
96
|
)
|
|
83
97
|
end
|
|
84
98
|
|
|
85
|
-
def get_logs(status: nil, start_time: nil, end_time: nil, limit: nil, cursor: nil)
|
|
99
|
+
def get_logs(status: nil, start_time: nil, end_time: nil, limit: nil, cursor: nil, endpoint_id: nil)
|
|
86
100
|
params = {}
|
|
101
|
+
params[:endpoint_id] = endpoint_id if endpoint_id
|
|
87
102
|
params[:status] = status if status
|
|
88
103
|
params[:start_time] = format_time(start_time) if start_time
|
|
89
104
|
params[:end_time] = format_time(end_time) if end_time
|
|
@@ -143,7 +158,7 @@ module HookBridge
|
|
|
143
158
|
end
|
|
144
159
|
|
|
145
160
|
def create_endpoint(url:, description: nil, hmac_enabled: nil, rate_limit_rps: 0, burst: 0, headers: nil,
|
|
146
|
-
ephemeral: nil, ttl_minutes: nil)
|
|
161
|
+
ephemeral: nil, ttl_minutes: nil, subscriptions: nil)
|
|
147
162
|
body = { url: url }
|
|
148
163
|
body[:description] = description if description
|
|
149
164
|
body[:hmac_enabled] = hmac_enabled unless hmac_enabled.nil?
|
|
@@ -152,6 +167,7 @@ module HookBridge
|
|
|
152
167
|
body[:headers] = headers if headers
|
|
153
168
|
body[:ephemeral] = ephemeral unless ephemeral.nil?
|
|
154
169
|
body[:ttl_minutes] = ttl_minutes unless ttl_minutes.nil?
|
|
170
|
+
body[:subscriptions] = subscriptions unless subscriptions.nil?
|
|
155
171
|
CreateEndpointResponse.new(extract_data(request(:post, "/v1/endpoints", body)))
|
|
156
172
|
end
|
|
157
173
|
|
|
@@ -159,10 +175,11 @@ module HookBridge
|
|
|
159
175
|
Endpoint.new(extract_data(request(:get, "/v1/endpoints/#{endpoint_id}")))
|
|
160
176
|
end
|
|
161
177
|
|
|
162
|
-
def list_endpoints(limit: nil, cursor: nil)
|
|
178
|
+
def list_endpoints(limit: nil, cursor: nil, event_type: nil)
|
|
163
179
|
params = {}
|
|
164
180
|
params[:limit] = limit if limit
|
|
165
181
|
params[:cursor] = cursor if cursor
|
|
182
|
+
params[:event_type] = event_type if event_type
|
|
166
183
|
response = request(:get, "/v1/endpoints", nil, params)
|
|
167
184
|
ListEndpointsResponse.new(
|
|
168
185
|
"data" => extract_data(response),
|
|
@@ -171,7 +188,8 @@ module HookBridge
|
|
|
171
188
|
)
|
|
172
189
|
end
|
|
173
190
|
|
|
174
|
-
def update_endpoint(endpoint_id, url: nil, description: nil, hmac_enabled: nil, rate_limit_rps: nil, burst: nil, headers: nil
|
|
191
|
+
def update_endpoint(endpoint_id, url: nil, description: nil, hmac_enabled: nil, rate_limit_rps: nil, burst: nil, headers: nil,
|
|
192
|
+
subscriptions: nil)
|
|
175
193
|
body = {}
|
|
176
194
|
body[:url] = url if url
|
|
177
195
|
body[:description] = description if description
|
|
@@ -179,6 +197,7 @@ module HookBridge
|
|
|
179
197
|
body[:rate_limit_rps] = rate_limit_rps if rate_limit_rps
|
|
180
198
|
body[:burst] = burst if burst
|
|
181
199
|
body[:headers] = headers if headers
|
|
200
|
+
body[:subscriptions] = subscriptions unless subscriptions.nil?
|
|
182
201
|
request(:patch, "/v1/endpoints/#{endpoint_id}", body)
|
|
183
202
|
nil
|
|
184
203
|
end
|
|
@@ -215,6 +234,89 @@ module HookBridge
|
|
|
215
234
|
create_endpoint_signing_key(endpoint_id)
|
|
216
235
|
end
|
|
217
236
|
|
|
237
|
+
def recover_endpoint(endpoint_id, since:, until_time: nil)
|
|
238
|
+
body = { since: format_time(since) }
|
|
239
|
+
body[:until] = format_time(until_time) if until_time
|
|
240
|
+
RecoverJob.new(extract_data(request(:post, "/v1/endpoints/#{endpoint_id}/recover", body)))
|
|
241
|
+
end
|
|
242
|
+
|
|
243
|
+
def get_recover_job(endpoint_id, job_id)
|
|
244
|
+
RecoverJob.new(extract_data(request(:get, "/v1/endpoints/#{endpoint_id}/recover/#{job_id}")))
|
|
245
|
+
end
|
|
246
|
+
|
|
247
|
+
def send_test_event(endpoint_id, event_type:, payload: nil)
|
|
248
|
+
body = { event_type: event_type }
|
|
249
|
+
body[:payload] = payload unless payload.nil?
|
|
250
|
+
TestEventResponse.new(extract_data(request(:post, "/v1/endpoints/#{endpoint_id}/test", body)))
|
|
251
|
+
end
|
|
252
|
+
|
|
253
|
+
def create_event_type(name:, description: nil, group: nil, schema: nil, sample_payload: nil, deprecated: nil, public: nil)
|
|
254
|
+
body = compact_hash(
|
|
255
|
+
name: name,
|
|
256
|
+
description: description,
|
|
257
|
+
group: group,
|
|
258
|
+
schema: schema,
|
|
259
|
+
sample_payload: sample_payload,
|
|
260
|
+
deprecated: deprecated,
|
|
261
|
+
public: public
|
|
262
|
+
)
|
|
263
|
+
EventType.new(extract_data(request(:post, "/v1/event-types", body)))
|
|
264
|
+
end
|
|
265
|
+
|
|
266
|
+
def list_event_types(limit: nil, cursor: nil, group: nil, name_prefix: nil, include_archived: nil)
|
|
267
|
+
params = compact_hash(limit: limit, cursor: cursor, group: group, name_prefix: name_prefix,
|
|
268
|
+
include_archived: include_archived)
|
|
269
|
+
response = request(:get, "/v1/event-types", nil, params)
|
|
270
|
+
ListEventTypesResponse.new("data" => extract_data(response), "next_cursor" => extract_meta(response)["next_cursor"])
|
|
271
|
+
end
|
|
272
|
+
|
|
273
|
+
def get_event_type(name)
|
|
274
|
+
EventType.new(extract_data(request(:get, event_type_path(name))))
|
|
275
|
+
end
|
|
276
|
+
|
|
277
|
+
def update_event_type(name, description: UNSET, group: UNSET, schema: UNSET, sample_payload: UNSET,
|
|
278
|
+
deprecated: UNSET, public: UNSET)
|
|
279
|
+
body = {
|
|
280
|
+
description: description, group: group, schema: schema, sample_payload: sample_payload,
|
|
281
|
+
deprecated: deprecated, public: public
|
|
282
|
+
}.reject { |_key, value| value.equal?(UNSET) }
|
|
283
|
+
EventType.new(extract_data(request(:patch, event_type_path(name), body)))
|
|
284
|
+
end
|
|
285
|
+
|
|
286
|
+
def archive_event_type(name)
|
|
287
|
+
EventType.new(extract_data(request(:delete, event_type_path(name))))
|
|
288
|
+
end
|
|
289
|
+
|
|
290
|
+
def unarchive_event_type(name)
|
|
291
|
+
EventType.new(extract_data(request(:post, "#{event_type_path(name)}/unarchive")))
|
|
292
|
+
end
|
|
293
|
+
|
|
294
|
+
def list_event_type_groups
|
|
295
|
+
extract_data(request(:get, "/v1/event-type-groups")).map { |entry| EventTypeGroup.new(entry) }
|
|
296
|
+
end
|
|
297
|
+
|
|
298
|
+
def list_events(limit: nil, cursor: nil, event_type: nil, since: nil, until_time: nil)
|
|
299
|
+
params = compact_hash(limit: limit, cursor: cursor, event_type: event_type, since: format_time(since),
|
|
300
|
+
until: format_time(until_time))
|
|
301
|
+
response = request(:get, "/v1/events", nil, params)
|
|
302
|
+
meta = extract_meta(response)
|
|
303
|
+
ListEventsResponse.new(
|
|
304
|
+
"data" => extract_data(response),
|
|
305
|
+
"has_more" => meta["has_more"],
|
|
306
|
+
"next_cursor" => meta["next_cursor"]
|
|
307
|
+
)
|
|
308
|
+
end
|
|
309
|
+
|
|
310
|
+
def get_event(event_id, messages_limit: nil, messages_cursor: nil)
|
|
311
|
+
params = compact_hash(messages_limit: messages_limit, messages_cursor: messages_cursor)
|
|
312
|
+
Event.new(extract_data(request(:get, "/v1/events/#{event_id}", nil, params)))
|
|
313
|
+
end
|
|
314
|
+
|
|
315
|
+
def delete_event(event_id)
|
|
316
|
+
request(:delete, "/v1/events/#{event_id}")
|
|
317
|
+
true
|
|
318
|
+
end
|
|
319
|
+
|
|
218
320
|
def create_pull_endpoint(name: nil, description: nil, retention_days: nil, event_type_source: nil,
|
|
219
321
|
event_type_path: nil,
|
|
220
322
|
verify_static_token: nil, token_header_name: nil, token_query_param: nil, token_value: nil,
|
|
@@ -606,6 +708,10 @@ module HookBridge
|
|
|
606
708
|
|
|
607
709
|
private
|
|
608
710
|
|
|
711
|
+
def event_type_path(name)
|
|
712
|
+
"/v1/event-types/#{ERB::Util.url_encode(name)}"
|
|
713
|
+
end
|
|
714
|
+
|
|
609
715
|
def build_connection(url)
|
|
610
716
|
Faraday.new(url: url) do |conn|
|
|
611
717
|
conn.request :retry,
|
|
@@ -622,10 +728,15 @@ module HookBridge
|
|
|
622
728
|
conn.headers["Content-Type"] = "application/json"
|
|
623
729
|
conn.headers["Accept"] = "application/json"
|
|
624
730
|
conn.headers["User-Agent"] = "hookbridge-ruby/#{VERSION}"
|
|
731
|
+
conn.headers["X-Hookbridge-Client"] = @client_name unless @client_name.nil? || @client_name.empty?
|
|
625
732
|
conn.adapter Faraday.default_adapter
|
|
626
733
|
end
|
|
627
734
|
end
|
|
628
735
|
|
|
736
|
+
def valid_client_name?(name)
|
|
737
|
+
name.nil? || name.match?(/\A[\x20-\x7E]*\z/)
|
|
738
|
+
end
|
|
739
|
+
|
|
629
740
|
def request(method, path, body = nil, params = nil, use_send_connection: false, allow_redirect: false)
|
|
630
741
|
conn = use_send_connection ? @send_connection : @connection
|
|
631
742
|
response = conn.run_request(method, path, body&.to_json, nil) do |req|
|
|
@@ -652,13 +763,15 @@ module HookBridge
|
|
|
652
763
|
JSON.parse(response.body)
|
|
653
764
|
when 400
|
|
654
765
|
error = parse_error(response.body)
|
|
655
|
-
raise ValidationError.new(error[:message], request_id: error[:request_id]
|
|
766
|
+
raise ValidationError.new(error[:message], request_id: error[:request_id], server_code: error[:code],
|
|
767
|
+
details: error[:details])
|
|
656
768
|
when 401
|
|
657
769
|
error = parse_error(response.body)
|
|
658
770
|
raise AuthenticationError.new(error[:message], request_id: error[:request_id])
|
|
659
771
|
when 404
|
|
660
772
|
error = parse_error(response.body)
|
|
661
|
-
raise NotFoundError.new(error[:message], request_id: error[:request_id]
|
|
773
|
+
raise NotFoundError.new(error[:message], request_id: error[:request_id], server_code: error[:code],
|
|
774
|
+
details: error[:details])
|
|
662
775
|
when 409
|
|
663
776
|
error = parse_error(response.body)
|
|
664
777
|
if %w[IDEMPOTENCY_MISMATCH IDEMPOTENCY_CONFLICT].include?(error[:code])
|
|
@@ -666,9 +779,14 @@ module HookBridge
|
|
|
666
779
|
end
|
|
667
780
|
raise ReplayLimitError.new(error[:message], request_id: error[:request_id]) if error[:code] == "REPLAY_LIMIT_EXCEEDED"
|
|
668
781
|
|
|
669
|
-
raise Error.new(error[:message], code: error[:code], request_id: error[:request_id], status_code: 409
|
|
782
|
+
raise Error.new(error[:message], code: error[:code], request_id: error[:request_id], status_code: 409,
|
|
783
|
+
details: error[:details])
|
|
670
784
|
when 429
|
|
671
785
|
error = parse_error(response.body)
|
|
786
|
+
if error[:code].to_s.end_with?("_LIMIT_REACHED")
|
|
787
|
+
raise Error.new(error[:message], code: error[:code], request_id: error[:request_id], status_code: 429,
|
|
788
|
+
details: error[:details])
|
|
789
|
+
end
|
|
672
790
|
raise ReplayLimitError.new(error[:message], request_id: error[:request_id]) if error[:code] == "REPLAY_LIMIT_EXCEEDED"
|
|
673
791
|
|
|
674
792
|
raise RateLimitError.new(error[:message], request_id: error[:request_id], retry_after: response.headers["retry-after"]&.to_i)
|
|
@@ -685,7 +803,8 @@ module HookBridge
|
|
|
685
803
|
{
|
|
686
804
|
code: error_data["code"],
|
|
687
805
|
message: error_data["message"] || "Request failed",
|
|
688
|
-
request_id: parsed.dig("meta", "request_id")
|
|
806
|
+
request_id: parsed.dig("meta", "request_id"),
|
|
807
|
+
details: error_data["details"]
|
|
689
808
|
}
|
|
690
809
|
else
|
|
691
810
|
{
|
data/lib/hookbridge/errors.rb
CHANGED
|
@@ -3,10 +3,12 @@
|
|
|
3
3
|
module HookBridge
|
|
4
4
|
# Base error class for all HookBridge errors
|
|
5
5
|
class Error < StandardError
|
|
6
|
-
attr_reader :code, :request_id, :status_code
|
|
6
|
+
attr_reader :code, :request_id, :status_code, :server_code, :details
|
|
7
7
|
|
|
8
|
-
def initialize(message, code: nil, request_id: nil, status_code: nil)
|
|
8
|
+
def initialize(message, code: nil, request_id: nil, status_code: nil, server_code: nil, details: nil)
|
|
9
9
|
@code = code
|
|
10
|
+
@server_code = server_code || code
|
|
11
|
+
@details = details
|
|
10
12
|
@request_id = request_id
|
|
11
13
|
@status_code = status_code
|
|
12
14
|
super(message)
|
data/lib/hookbridge/types.rb
CHANGED
|
@@ -45,6 +45,10 @@ module HookBridge
|
|
|
45
45
|
end
|
|
46
46
|
end
|
|
47
47
|
|
|
48
|
+
def self.optional_fields(*names)
|
|
49
|
+
names.each { |name| define_method(name) { @attributes[name.to_s] } }
|
|
50
|
+
end
|
|
51
|
+
|
|
48
52
|
def to_h
|
|
49
53
|
@attributes.transform_keys(&:to_sym)
|
|
50
54
|
end
|
|
@@ -74,12 +78,16 @@ module HookBridge
|
|
|
74
78
|
end
|
|
75
79
|
|
|
76
80
|
class Message < BaseModel
|
|
81
|
+
optional_fields :event_type, :event_id, :is_test
|
|
82
|
+
|
|
77
83
|
def initialize(data)
|
|
78
84
|
super(data, time_fields: %w[next_attempt_at first_attempt_at created_at updated_at deleted_at])
|
|
79
85
|
end
|
|
80
86
|
end
|
|
81
87
|
|
|
82
88
|
class MessageSummary < BaseModel
|
|
89
|
+
optional_fields :event_type, :event_id, :is_test
|
|
90
|
+
|
|
83
91
|
def initialize(data)
|
|
84
92
|
super(data, time_fields: %w[created_at delivered_at next_attempt_at first_attempt_at deleted_at])
|
|
85
93
|
end
|
|
@@ -91,6 +99,62 @@ module HookBridge
|
|
|
91
99
|
class ReplayResponse < BaseModel
|
|
92
100
|
end
|
|
93
101
|
|
|
102
|
+
class SendEventResponse < BaseModel
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
class EventType < BaseModel
|
|
106
|
+
def initialize(data)
|
|
107
|
+
super(data, time_fields: %w[archived_at created_at updated_at])
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
class ListEventTypesResponse
|
|
112
|
+
attr_reader :event_types, :next_cursor
|
|
113
|
+
|
|
114
|
+
def initialize(data)
|
|
115
|
+
@event_types = (data["data"] || []).map { |entry| EventType.new(entry) }
|
|
116
|
+
@next_cursor = data["next_cursor"].then { |cursor| cursor&.empty? ? nil : cursor }
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
class EventTypeGroup < BaseModel
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
class EventMessage < BaseModel
|
|
124
|
+
def initialize(data)
|
|
125
|
+
super(data, time_fields: %w[next_attempt_at deleted_at created_at])
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
class Event < BaseModel
|
|
130
|
+
optional_fields :status_counts
|
|
131
|
+
|
|
132
|
+
def initialize(data)
|
|
133
|
+
super(data, time_fields: %w[fanned_out_at deleted_at created_at])
|
|
134
|
+
@attributes["messages"] = (@attributes["messages"] || []).map { |entry| EventMessage.new(entry) } if
|
|
135
|
+
@attributes.key?("messages")
|
|
136
|
+
end
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
class ListEventsResponse
|
|
140
|
+
attr_reader :events, :has_more, :next_cursor
|
|
141
|
+
|
|
142
|
+
def initialize(data)
|
|
143
|
+
@events = (data["data"] || []).map { |entry| Event.new(entry) }
|
|
144
|
+
@has_more = data["has_more"] || false
|
|
145
|
+
@next_cursor = data["next_cursor"].then { |cursor| cursor&.empty? ? nil : cursor }
|
|
146
|
+
end
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
class RecoverJob < BaseModel
|
|
150
|
+
def initialize(data)
|
|
151
|
+
super(data, time_fields: %w[since until created_at finished_at])
|
|
152
|
+
end
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
class TestEventResponse < BaseModel
|
|
156
|
+
end
|
|
157
|
+
|
|
94
158
|
class LogsResponse
|
|
95
159
|
attr_reader :messages, :has_more, :next_cursor
|
|
96
160
|
|
|
@@ -160,21 +224,44 @@ module HookBridge
|
|
|
160
224
|
end
|
|
161
225
|
end
|
|
162
226
|
|
|
227
|
+
module NormalizesSubscriptions
|
|
228
|
+
private
|
|
229
|
+
|
|
230
|
+
def normalize_subscriptions
|
|
231
|
+
subscriptions = @attributes["subscriptions"]
|
|
232
|
+
return unless subscriptions.is_a?(Hash)
|
|
233
|
+
|
|
234
|
+
@attributes["subscriptions"] = subscriptions.merge(
|
|
235
|
+
"event_types" => subscriptions["event_types"] || [],
|
|
236
|
+
"groups" => subscriptions["groups"] || []
|
|
237
|
+
)
|
|
238
|
+
end
|
|
239
|
+
end
|
|
240
|
+
|
|
163
241
|
class CreateEndpointResponse < BaseModel
|
|
242
|
+
include NormalizesSubscriptions
|
|
243
|
+
|
|
164
244
|
def initialize(data)
|
|
165
245
|
super(data, time_fields: %w[created_at expires_at])
|
|
246
|
+
normalize_subscriptions
|
|
166
247
|
end
|
|
167
248
|
end
|
|
168
249
|
|
|
169
250
|
class Endpoint < BaseModel
|
|
251
|
+
include NormalizesSubscriptions
|
|
252
|
+
|
|
170
253
|
def initialize(data)
|
|
171
254
|
super(data, time_fields: %w[created_at updated_at expires_at])
|
|
255
|
+
normalize_subscriptions
|
|
172
256
|
end
|
|
173
257
|
end
|
|
174
258
|
|
|
175
259
|
class EndpointSummary < BaseModel
|
|
260
|
+
include NormalizesSubscriptions
|
|
261
|
+
|
|
176
262
|
def initialize(data)
|
|
177
263
|
super(data, time_fields: %w[created_at expires_at])
|
|
264
|
+
normalize_subscriptions
|
|
178
265
|
end
|
|
179
266
|
end
|
|
180
267
|
|
data/lib/hookbridge/version.rb
CHANGED