hookbridge 2.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3faed23c2d36e3294b89adf7dd7843f9f6cc7f8697a3ffe9ceeb8541818fc257
4
- data.tar.gz: a23ce4da13495686b9ad4322f6a02e5bd55a305f0a77405e43c23e1404e5d9c1
3
+ metadata.gz: 31ac5b314c6d5525fc2d2faec83ecb4809454e52b449db44354e230dee9cf58c
4
+ data.tar.gz: 989f74a14e87a7f9a41ca68716aabc7a8b6cd38f0ab00d72782c93670d77ad11
5
5
  SHA512:
6
- metadata.gz: 514e54ba5311f92a5a34d6a5a7fead2a2197467ad4ff5d79395d8af6d5218042ac82324d9858017f0eaf13cd256fa38ffff4f42aec1b63a7850a5ce35eac3a8b
7
- data.tar.gz: a9d084fd4c19ea785642539de316b20aa5fdde48614da099a6da8a271b026b9b6123af1354a2f7dae25f941e4c83e96f379050905f7b2175a0fc3f08dc4c78c6
6
+ metadata.gz: 31cd75696ef83464e4e912f8215a02db23965e97568ca027f13e23020b3a306bbdff19fc4a794eb9def6b106e4e17ae5399c023fad0bc64952d88fb04c413c4e
7
+ data.tar.gz: 29cf35afae19cd298e50f18c6e1e402ef7a277acc1dbc7aa0e29c1c21d8447bfdf51ff78794d52a8a85e317b8283121a980a1581d83f2c6ab56b7c9c4a09136e
data/CHANGELOG.md CHANGED
@@ -5,6 +5,30 @@ 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
+
23
+ ## [2.2.0] - 2026-11-19
24
+
25
+ ### Added
26
+
27
+ - `replay_all_messages_dry_run` - Preview a bulk replay of messages; returns `would_replay`
28
+ - `replay_all_inbound_messages_dry_run` - Preview a bulk replay of inbound messages; returns `would_replay`
29
+ - `list_message_actions` - List actions taken on a message, with cursor paging
30
+ - `list_inbound_message_actions` - List actions taken on an inbound message, with cursor paging
31
+
8
32
  ## [1.0.0] - 2024-01-15
9
33
 
10
34
  ### 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,13 +70,55 @@ 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
 
69
77
  client.replay(message.id)
70
78
  client.replay_all_messages(status: "failed_permanent", endpoint_id: endpoint.id, limit: 50)
79
+
80
+ preview = client.replay_all_messages_dry_run(status: "failed_permanent", endpoint_id: endpoint.id, limit: 50)
81
+ puts preview.would_replay # Nothing is replayed
82
+
83
+ page = client.list_message_actions(message.id, limit: 50)
84
+ page.actions.each { |action| puts "#{action.action} via #{action.via}" }
85
+ page = client.list_message_actions(message.id, cursor: page.next_cursor) if page.has_more
71
86
  ```
72
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
+
73
122
  ## Inbound Webhooks
74
123
 
75
124
  ```ruby
@@ -108,6 +157,11 @@ inbound_logs = client.get_inbound_logs(inbound_endpoint_id: inbound.id, limit: 5
108
157
  inbound_metrics = client.get_inbound_metrics(inbound_endpoint_id: inbound.id)
109
158
  inbound_timeseries = client.get_inbound_timeseries_metrics(inbound_endpoint_id: inbound.id)
110
159
  rejections = client.list_inbound_rejections(inbound_endpoint_id: inbound.id, limit: 25)
160
+
161
+ preview = client.replay_all_inbound_messages_dry_run(status: "failed_permanent", inbound_endpoint_id: inbound.id)
162
+ puts preview.would_replay # Nothing is replayed
163
+
164
+ actions = client.list_inbound_message_actions(inbound_message_id, limit: 50)
111
165
  ```
112
166
 
113
167
  ## Billing and Exports
@@ -3,6 +3,7 @@
3
3
  require "faraday"
4
4
  require "faraday/retry"
5
5
  require "json"
6
+ require "erb"
6
7
 
7
8
  module HookBridge
8
9
  class Client
@@ -10,17 +11,22 @@ module HookBridge
10
11
  DEFAULT_SEND_URL = "https://send.hookbridge.io"
11
12
  DEFAULT_TIMEOUT = 30
12
13
  DEFAULT_RETRIES = 3
14
+ UNSET = Object.new.freeze
15
+ private_constant :UNSET
13
16
 
14
17
  attr_reader :api_key, :base_url, :send_url, :timeout, :retries
15
18
 
16
- 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)
17
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)
18
23
 
19
24
  @api_key = api_key
20
25
  @base_url = (base_url || ENV.fetch("HOOKBRIDGE_BASE_URL", DEFAULT_BASE_URL)).chomp("/")
21
26
  @send_url = (send_url || ENV.fetch("HOOKBRIDGE_SEND_URL", DEFAULT_SEND_URL)).chomp("/")
22
27
  @timeout = timeout
23
28
  @retries = retries
29
+ @client_name = client_name
24
30
  @connection = build_connection(@base_url)
25
31
  @send_connection = build_connection(@send_url)
26
32
  end
@@ -33,6 +39,15 @@ module HookBridge
33
39
  SendResponse.new(extract_data(request(:post, "/v1/webhooks/send", body, use_send_connection: true)))
34
40
  end
35
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
+
36
51
  def get_message(message_id)
37
52
  Message.new(extract_data(request(:get, "/v1/messages/#{message_id}")))
38
53
  end
@@ -63,14 +78,27 @@ module HookBridge
63
78
  ReplayAllMessagesResponse.new(extract_data(request(:post, "/v1/messages/replay-all", nil, params)))
64
79
  end
65
80
 
81
+ def replay_all_messages_dry_run(status:, endpoint_id: nil, limit: nil)
82
+ params = { status: status }
83
+ params[:endpoint_id] = endpoint_id if endpoint_id
84
+ params[:limit] = limit if limit
85
+ params[:dry_run] = "true"
86
+ ReplayAllDryRunResponse.new(extract_data(request(:post, "/v1/messages/replay-all", nil, params)))
87
+ end
88
+
89
+ def list_message_actions(message_id, cursor: nil, limit: nil)
90
+ fetch_message_actions("/v1/messages/#{ERB::Util.url_encode(message_id)}/actions", cursor, limit)
91
+ end
92
+
66
93
  def replay_batch_messages(message_ids)
67
94
  ReplayBatchMessagesResponse.new(
68
95
  extract_data(request(:post, "/v1/messages/replay-batch", { message_ids: message_ids }))
69
96
  )
70
97
  end
71
98
 
72
- 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)
73
100
  params = {}
101
+ params[:endpoint_id] = endpoint_id if endpoint_id
74
102
  params[:status] = status if status
75
103
  params[:start_time] = format_time(start_time) if start_time
76
104
  params[:end_time] = format_time(end_time) if end_time
@@ -130,7 +158,7 @@ module HookBridge
130
158
  end
131
159
 
132
160
  def create_endpoint(url:, description: nil, hmac_enabled: nil, rate_limit_rps: 0, burst: 0, headers: nil,
133
- ephemeral: nil, ttl_minutes: nil)
161
+ ephemeral: nil, ttl_minutes: nil, subscriptions: nil)
134
162
  body = { url: url }
135
163
  body[:description] = description if description
136
164
  body[:hmac_enabled] = hmac_enabled unless hmac_enabled.nil?
@@ -139,6 +167,7 @@ module HookBridge
139
167
  body[:headers] = headers if headers
140
168
  body[:ephemeral] = ephemeral unless ephemeral.nil?
141
169
  body[:ttl_minutes] = ttl_minutes unless ttl_minutes.nil?
170
+ body[:subscriptions] = subscriptions unless subscriptions.nil?
142
171
  CreateEndpointResponse.new(extract_data(request(:post, "/v1/endpoints", body)))
143
172
  end
144
173
 
@@ -146,10 +175,11 @@ module HookBridge
146
175
  Endpoint.new(extract_data(request(:get, "/v1/endpoints/#{endpoint_id}")))
147
176
  end
148
177
 
149
- def list_endpoints(limit: nil, cursor: nil)
178
+ def list_endpoints(limit: nil, cursor: nil, event_type: nil)
150
179
  params = {}
151
180
  params[:limit] = limit if limit
152
181
  params[:cursor] = cursor if cursor
182
+ params[:event_type] = event_type if event_type
153
183
  response = request(:get, "/v1/endpoints", nil, params)
154
184
  ListEndpointsResponse.new(
155
185
  "data" => extract_data(response),
@@ -158,7 +188,8 @@ module HookBridge
158
188
  )
159
189
  end
160
190
 
161
- 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)
162
193
  body = {}
163
194
  body[:url] = url if url
164
195
  body[:description] = description if description
@@ -166,6 +197,7 @@ module HookBridge
166
197
  body[:rate_limit_rps] = rate_limit_rps if rate_limit_rps
167
198
  body[:burst] = burst if burst
168
199
  body[:headers] = headers if headers
200
+ body[:subscriptions] = subscriptions unless subscriptions.nil?
169
201
  request(:patch, "/v1/endpoints/#{endpoint_id}", body)
170
202
  nil
171
203
  end
@@ -202,6 +234,89 @@ module HookBridge
202
234
  create_endpoint_signing_key(endpoint_id)
203
235
  end
204
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
+
205
320
  def create_pull_endpoint(name: nil, description: nil, retention_days: nil, event_type_source: nil,
206
321
  event_type_path: nil,
207
322
  verify_static_token: nil, token_header_name: nil, token_query_param: nil, token_value: nil,
@@ -437,6 +552,18 @@ module HookBridge
437
552
  ReplayAllMessagesResponse.new(extract_data(request(:post, "/v1/inbound-messages/replay-all", nil, params)))
438
553
  end
439
554
 
555
+ def replay_all_inbound_messages_dry_run(status:, inbound_endpoint_id: nil, limit: nil)
556
+ params = { status: status }
557
+ params[:inbound_endpoint_id] = inbound_endpoint_id if inbound_endpoint_id
558
+ params[:limit] = limit if limit
559
+ params[:dry_run] = "true"
560
+ ReplayAllDryRunResponse.new(extract_data(request(:post, "/v1/inbound-messages/replay-all", nil, params)))
561
+ end
562
+
563
+ def list_inbound_message_actions(message_id, cursor: nil, limit: nil)
564
+ fetch_message_actions("/v1/inbound-messages/#{ERB::Util.url_encode(message_id)}/actions", cursor, limit)
565
+ end
566
+
440
567
  def replay_batch_inbound_messages(message_ids)
441
568
  ReplayBatchMessagesResponse.new(
442
569
  extract_data(request(:post, "/v1/inbound-messages/replay-batch", { message_ids: message_ids }))
@@ -581,6 +708,10 @@ module HookBridge
581
708
 
582
709
  private
583
710
 
711
+ def event_type_path(name)
712
+ "/v1/event-types/#{ERB::Util.url_encode(name)}"
713
+ end
714
+
584
715
  def build_connection(url)
585
716
  Faraday.new(url: url) do |conn|
586
717
  conn.request :retry,
@@ -597,10 +728,15 @@ module HookBridge
597
728
  conn.headers["Content-Type"] = "application/json"
598
729
  conn.headers["Accept"] = "application/json"
599
730
  conn.headers["User-Agent"] = "hookbridge-ruby/#{VERSION}"
731
+ conn.headers["X-Hookbridge-Client"] = @client_name unless @client_name.nil? || @client_name.empty?
600
732
  conn.adapter Faraday.default_adapter
601
733
  end
602
734
  end
603
735
 
736
+ def valid_client_name?(name)
737
+ name.nil? || name.match?(/\A[\x20-\x7E]*\z/)
738
+ end
739
+
604
740
  def request(method, path, body = nil, params = nil, use_send_connection: false, allow_redirect: false)
605
741
  conn = use_send_connection ? @send_connection : @connection
606
742
  response = conn.run_request(method, path, body&.to_json, nil) do |req|
@@ -627,13 +763,15 @@ module HookBridge
627
763
  JSON.parse(response.body)
628
764
  when 400
629
765
  error = parse_error(response.body)
630
- 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])
631
768
  when 401
632
769
  error = parse_error(response.body)
633
770
  raise AuthenticationError.new(error[:message], request_id: error[:request_id])
634
771
  when 404
635
772
  error = parse_error(response.body)
636
- 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])
637
775
  when 409
638
776
  error = parse_error(response.body)
639
777
  if %w[IDEMPOTENCY_MISMATCH IDEMPOTENCY_CONFLICT].include?(error[:code])
@@ -641,9 +779,14 @@ module HookBridge
641
779
  end
642
780
  raise ReplayLimitError.new(error[:message], request_id: error[:request_id]) if error[:code] == "REPLAY_LIMIT_EXCEEDED"
643
781
 
644
- 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])
645
784
  when 429
646
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
647
790
  raise ReplayLimitError.new(error[:message], request_id: error[:request_id]) if error[:code] == "REPLAY_LIMIT_EXCEEDED"
648
791
 
649
792
  raise RateLimitError.new(error[:message], request_id: error[:request_id], retry_after: response.headers["retry-after"]&.to_i)
@@ -660,7 +803,8 @@ module HookBridge
660
803
  {
661
804
  code: error_data["code"],
662
805
  message: error_data["message"] || "Request failed",
663
- request_id: parsed.dig("meta", "request_id")
806
+ request_id: parsed.dig("meta", "request_id"),
807
+ details: error_data["details"]
664
808
  }
665
809
  else
666
810
  {
@@ -673,6 +817,19 @@ module HookBridge
673
817
  { code: nil, message: "Request failed", request_id: nil }
674
818
  end
675
819
 
820
+ def fetch_message_actions(path, cursor, limit)
821
+ params = {}
822
+ params[:cursor] = cursor if cursor
823
+ params[:limit] = limit if limit
824
+ response = request(:get, path, nil, params)
825
+ meta = extract_meta(response)
826
+ ListMessageActionsResponse.new(
827
+ "actions" => extract_data(response),
828
+ "has_more" => meta["has_more"] || false,
829
+ "next_cursor" => meta["next_cursor"]
830
+ )
831
+ end
832
+
676
833
  def extract_data(response)
677
834
  response.is_a?(Hash) && response.key?("data") ? response["data"] : response
678
835
  end
@@ -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)
@@ -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
 
@@ -203,6 +290,23 @@ module HookBridge
203
290
  class ReplayAllMessagesResponse < BaseModel
204
291
  end
205
292
 
293
+ class ReplayAllDryRunResponse < BaseModel
294
+ end
295
+
296
+ class MessageAction < BaseModel
297
+ def initialize(data)
298
+ super(data, time_fields: %w[created_at])
299
+ end
300
+ end
301
+
302
+ class ListMessageActionsResponse < BaseModel
303
+ def initialize(data)
304
+ super
305
+ @attributes["actions"] = (data["actions"] || []).map { |entry| MessageAction.new(entry) }
306
+ @attributes["has_more"] ||= false
307
+ end
308
+ end
309
+
206
310
  class ReplayBatchResult < BaseModel
207
311
  end
208
312
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module HookBridge
4
- VERSION = "2.1.0"
4
+ VERSION = "2.3.0"
5
5
  end
metadata CHANGED
@@ -1,186 +1,207 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hookbridge
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
- - HookBridge
7
+ - HookBridge
8
8
  bindir: bin
9
9
  cert_chain: []
10
10
  date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
- - !ruby/object:Gem::Dependency
13
- name: faraday
14
- requirement: !ruby/object:Gem::Requirement
15
- requirements:
16
- - - ">="
17
- - !ruby/object:Gem::Version
18
- version: '2.0'
19
- - - "<"
20
- - !ruby/object:Gem::Version
21
- version: '3.0'
22
- type: :runtime
23
- prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- version: '2.0'
29
- - - "<"
30
- - !ruby/object:Gem::Version
31
- version: '3.0'
32
- - !ruby/object:Gem::Dependency
33
- name: faraday-retry
34
- requirement: !ruby/object:Gem::Requirement
35
- requirements:
36
- - - "~>"
37
- - !ruby/object:Gem::Version
38
- version: '2.0'
39
- type: :runtime
40
- prerelease: false
41
- version_requirements: !ruby/object:Gem::Requirement
42
- requirements:
43
- - - "~>"
44
- - !ruby/object:Gem::Version
45
- version: '2.0'
46
- - !ruby/object:Gem::Dependency
47
- name: bundler
48
- requirement: !ruby/object:Gem::Requirement
49
- requirements:
50
- - - "~>"
51
- - !ruby/object:Gem::Version
52
- version: '2.0'
53
- type: :development
54
- prerelease: false
55
- version_requirements: !ruby/object:Gem::Requirement
56
- requirements:
57
- - - "~>"
58
- - !ruby/object:Gem::Version
59
- version: '2.0'
60
- - !ruby/object:Gem::Dependency
61
- name: rake
62
- requirement: !ruby/object:Gem::Requirement
63
- requirements:
64
- - - "~>"
65
- - !ruby/object:Gem::Version
66
- version: '13.0'
67
- type: :development
68
- prerelease: false
69
- version_requirements: !ruby/object:Gem::Requirement
70
- requirements:
71
- - - "~>"
72
- - !ruby/object:Gem::Version
73
- version: '13.0'
74
- - !ruby/object:Gem::Dependency
75
- name: rspec
76
- requirement: !ruby/object:Gem::Requirement
77
- requirements:
78
- - - "~>"
79
- - !ruby/object:Gem::Version
80
- version: '3.12'
81
- type: :development
82
- prerelease: false
83
- version_requirements: !ruby/object:Gem::Requirement
84
- requirements:
85
- - - "~>"
86
- - !ruby/object:Gem::Version
87
- version: '3.12'
88
- - !ruby/object:Gem::Dependency
89
- name: webmock
90
- requirement: !ruby/object:Gem::Requirement
91
- requirements:
92
- - - "~>"
93
- - !ruby/object:Gem::Version
94
- version: '3.18'
95
- type: :development
96
- prerelease: false
97
- version_requirements: !ruby/object:Gem::Requirement
98
- requirements:
99
- - - "~>"
100
- - !ruby/object:Gem::Version
101
- version: '3.18'
102
- - !ruby/object:Gem::Dependency
103
- name: rubocop
104
- requirement: !ruby/object:Gem::Requirement
105
- requirements:
106
- - - "~>"
107
- - !ruby/object:Gem::Version
108
- version: '1.50'
109
- type: :development
110
- prerelease: false
111
- version_requirements: !ruby/object:Gem::Requirement
112
- requirements:
113
- - - "~>"
114
- - !ruby/object:Gem::Version
115
- version: '1.50'
116
- - !ruby/object:Gem::Dependency
117
- name: rubocop-rspec
118
- requirement: !ruby/object:Gem::Requirement
119
- requirements:
120
- - - "~>"
121
- - !ruby/object:Gem::Version
122
- version: '2.20'
123
- type: :development
124
- prerelease: false
125
- version_requirements: !ruby/object:Gem::Requirement
126
- requirements:
127
- - - "~>"
128
- - !ruby/object:Gem::Version
129
- version: '2.20'
130
- - !ruby/object:Gem::Dependency
131
- name: yard
132
- requirement: !ruby/object:Gem::Requirement
133
- requirements:
134
- - - "~>"
135
- - !ruby/object:Gem::Version
136
- version: '0.9'
137
- type: :development
138
- prerelease: false
139
- version_requirements: !ruby/object:Gem::Requirement
140
- requirements:
141
- - - "~>"
142
- - !ruby/object:Gem::Version
143
- version: '0.9'
144
- description: Official Ruby client library for the HookBridge API. Send webhooks with
145
- guaranteed delivery, automatic retries, and comprehensive delivery tracking.
12
+ - !ruby/object:Gem::Dependency
13
+ name: faraday
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ -
17
+ - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: "2.0"
20
+ -
21
+ - "<"
22
+ - !ruby/object:Gem::Version
23
+ version: "3.0"
24
+ type: :runtime
25
+ prerelease: false
26
+ version_requirements: !ruby/object:Gem::Requirement
27
+ requirements:
28
+ -
29
+ - ">="
30
+ - !ruby/object:Gem::Version
31
+ version: "2.0"
32
+ -
33
+ - "<"
34
+ - !ruby/object:Gem::Version
35
+ version: "3.0"
36
+ - !ruby/object:Gem::Dependency
37
+ name: faraday-retry
38
+ requirement: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ -
41
+ - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: "2.0"
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ -
49
+ - ~>
50
+ - !ruby/object:Gem::Version
51
+ version: "2.0"
52
+ - !ruby/object:Gem::Dependency
53
+ name: bundler
54
+ requirement: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ -
57
+ - ~>
58
+ - !ruby/object:Gem::Version
59
+ version: "2.0"
60
+ type: :development
61
+ prerelease: false
62
+ version_requirements: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ -
65
+ - ~>
66
+ - !ruby/object:Gem::Version
67
+ version: "2.0"
68
+ - !ruby/object:Gem::Dependency
69
+ name: rake
70
+ requirement: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ -
73
+ - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: "13.0"
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ -
81
+ - ~>
82
+ - !ruby/object:Gem::Version
83
+ version: "13.0"
84
+ - !ruby/object:Gem::Dependency
85
+ name: rspec
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ -
89
+ - ~>
90
+ - !ruby/object:Gem::Version
91
+ version: "3.12"
92
+ type: :development
93
+ prerelease: false
94
+ version_requirements: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ -
97
+ - ~>
98
+ - !ruby/object:Gem::Version
99
+ version: "3.12"
100
+ - !ruby/object:Gem::Dependency
101
+ name: webmock
102
+ requirement: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ -
105
+ - ~>
106
+ - !ruby/object:Gem::Version
107
+ version: "3.18"
108
+ type: :development
109
+ prerelease: false
110
+ version_requirements: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ -
113
+ - ~>
114
+ - !ruby/object:Gem::Version
115
+ version: "3.18"
116
+ - !ruby/object:Gem::Dependency
117
+ name: rubocop
118
+ requirement: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ -
121
+ - ~>
122
+ - !ruby/object:Gem::Version
123
+ version: "1.50"
124
+ type: :development
125
+ prerelease: false
126
+ version_requirements: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ -
129
+ - ~>
130
+ - !ruby/object:Gem::Version
131
+ version: "1.50"
132
+ - !ruby/object:Gem::Dependency
133
+ name: rubocop-rspec
134
+ requirement: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ -
137
+ - ~>
138
+ - !ruby/object:Gem::Version
139
+ version: "2.20"
140
+ type: :development
141
+ prerelease: false
142
+ version_requirements: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ -
145
+ - ~>
146
+ - !ruby/object:Gem::Version
147
+ version: "2.20"
148
+ - !ruby/object:Gem::Dependency
149
+ name: yard
150
+ requirement: !ruby/object:Gem::Requirement
151
+ requirements:
152
+ -
153
+ - ~>
154
+ - !ruby/object:Gem::Version
155
+ version: "0.9"
156
+ type: :development
157
+ prerelease: false
158
+ version_requirements: !ruby/object:Gem::Requirement
159
+ requirements:
160
+ -
161
+ - ~>
162
+ - !ruby/object:Gem::Version
163
+ version: "0.9"
164
+ description: "Official Ruby client library for the HookBridge API. Send webhooks with guaranteed delivery, automatic retries, and comprehensive delivery tracking."
146
165
  email:
147
- - support@hookbridge.io
166
+ - support@hookbridge.io
148
167
  executables: []
149
168
  extensions: []
150
169
  extra_rdoc_files: []
151
170
  files:
152
- - CHANGELOG.md
153
- - LICENSE
154
- - README.md
155
- - lib/hookbridge.rb
156
- - lib/hookbridge/client.rb
157
- - lib/hookbridge/errors.rb
158
- - lib/hookbridge/types.rb
159
- - lib/hookbridge/version.rb
160
- homepage: https://github.com/hookbridge/hookbridge-ruby
171
+ - CHANGELOG.md
172
+ - LICENSE
173
+ - README.md
174
+ - lib/hookbridge.rb
175
+ - lib/hookbridge/client.rb
176
+ - lib/hookbridge/errors.rb
177
+ - lib/hookbridge/types.rb
178
+ - lib/hookbridge/version.rb
179
+ homepage: "https://github.com/hookbridge/hookbridge-ruby"
161
180
  licenses:
162
- - MIT
181
+ - MIT
163
182
  metadata:
164
- homepage_uri: https://github.com/hookbridge/hookbridge-ruby
165
- source_code_uri: https://github.com/hookbridge/hookbridge-ruby
166
- changelog_uri: https://github.com/hookbridge/hookbridge-ruby/blob/main/CHANGELOG.md
167
- documentation_uri: https://docs.hookbridge.io
168
- rubygems_mfa_required: 'true'
183
+ homepage_uri: "https://github.com/hookbridge/hookbridge-ruby"
184
+ source_code_uri: "https://github.com/hookbridge/hookbridge-ruby"
185
+ changelog_uri: "https://github.com/hookbridge/hookbridge-ruby/blob/main/CHANGELOG.md"
186
+ documentation_uri: "https://docs.hookbridge.io"
187
+ rubygems_mfa_required: "true"
169
188
  rdoc_options: []
170
189
  require_paths:
171
- - lib
190
+ - lib
172
191
  required_ruby_version: !ruby/object:Gem::Requirement
173
192
  requirements:
174
- - - ">="
175
- - !ruby/object:Gem::Version
176
- version: 3.0.0
193
+ -
194
+ - ">="
195
+ - !ruby/object:Gem::Version
196
+ version: 3.0.0
177
197
  required_rubygems_version: !ruby/object:Gem::Requirement
178
198
  requirements:
179
- - - ">="
180
- - !ruby/object:Gem::Version
181
- version: '0'
199
+ -
200
+ - ">="
201
+ - !ruby/object:Gem::Version
202
+ version: "0"
182
203
  requirements: []
183
- rubygems_version: 4.0.23
204
+ rubygems_version: 4.1.0
184
205
  specification_version: 4
185
206
  summary: Ruby SDK for HookBridge - Guaranteed webhook delivery
186
207
  test_files: []