sendly 4.1.0 → 4.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.
@@ -16,6 +16,8 @@ module Sendly
16
16
  # @param mode [String, nil] Event mode filter: "all", "test", or "live" (live requires verification)
17
17
  # @param metadata [Hash, nil] Custom metadata
18
18
  # @return [Sendly::WebhookCreatedResponse]
19
+ # @raise [ArgumentError] If +url+ is not an https:// URL or +events+ is
20
+ # empty; no request is sent
19
21
  #
20
22
  # @example
21
23
  # webhook = client.webhooks.create(
@@ -65,6 +67,8 @@ module Sendly
65
67
  # @param mode [String, nil] Event mode filter: "all", "test", or "live"
66
68
  # @param metadata [Hash, nil] Custom metadata
67
69
  # @return [Sendly::Webhook]
70
+ # @raise [ArgumentError] If +webhook_id+ does not start with +whk_+ or
71
+ # +url+ is not an https:// URL; no request is sent
68
72
  def update(webhook_id, url: nil, events: nil, description: nil, is_active: nil, mode: nil, metadata: nil)
69
73
  validate_webhook_id!(webhook_id)
70
74
  raise ArgumentError, "Webhook URL must be HTTPS" if url && !url.start_with?("https://")
@@ -94,7 +98,9 @@ module Sendly
94
98
  # Test a webhook endpoint
95
99
  #
96
100
  # @param webhook_id [String] Webhook ID
97
- # @return [Sendly::WebhookTestResult]
101
+ # @return [Sendly::WebhookTestResult] The delivered test, with its status code and timing
102
+ # @raise [Sendly::ValidationError] If the test delivery fails; the message
103
+ # is the API's, e.g. "Test webhook failed: ..."
98
104
  def test(webhook_id)
99
105
  validate_webhook_id!(webhook_id)
100
106
  response = @client.post("/webhooks/#{URI.encode_www_form_component(webhook_id)}/test")
@@ -139,8 +145,10 @@ module Sendly
139
145
  # Backfill missed webhook events from the underlying message log.
140
146
  #
141
147
  # Use when a circuit-breaker outage left events with no audit row (the
142
- # case {#redeliver} cannot recover). Synthesized events have fresh IDs;
143
- # clients should dedupe by event.data.object.id (the message ID).
148
+ # case {#redeliver} cannot recover). Synthesized message events carry the
149
+ # same event id the original dispatch used, so dedupe on event.id. Do not
150
+ # dedupe on event.data.object.id: a message's sent and delivered events
151
+ # share it.
144
152
  # Rejects with HTTP 409 if the circuit is currently open — call
145
153
  # {#reset_circuit} first.
146
154
  #
@@ -162,6 +170,11 @@ module Sendly
162
170
 
163
171
  # Rotate the webhook signing secret
164
172
  #
173
+ # Deliveries are signed with the new secret as soon as this returns, and
174
+ # the old secret is not kept, so have your endpoint accept both secrets
175
+ # while you deploy the new one. The new secret is shown only once, on
176
+ # {Sendly::WebhookSecretRotation#new_secret}.
177
+ #
165
178
  # @param webhook_id [String] Webhook ID
166
179
  # @return [Sendly::WebhookSecretRotation]
167
180
  def rotate_secret(webhook_id)
@@ -170,14 +183,24 @@ module Sendly
170
183
  WebhookSecretRotation.new(response)
171
184
  end
172
185
 
173
- # Get delivery history for a webhook
186
+ # Get delivery history for a webhook, newest first
174
187
  #
175
188
  # @param webhook_id [String] Webhook ID
189
+ # @param limit [Integer, nil] Maximum deliveries to return (the API defaults to 50, max 100)
190
+ # @param offset [Integer, nil] Number of deliveries to skip
191
+ # @param status [String, nil] Only deliveries with this status
192
+ # (see {Sendly::WebhookDelivery::STATUSES})
176
193
  # @return [Array<Sendly::WebhookDelivery>]
177
- def deliveries(webhook_id)
194
+ def deliveries(webhook_id, limit: nil, offset: nil, status: nil)
178
195
  validate_webhook_id!(webhook_id)
179
- response = @client.get("/webhooks/#{URI.encode_www_form_component(webhook_id)}/deliveries")
180
- response.map { |data| WebhookDelivery.new(data) }
196
+ params = {}
197
+ params[:limit] = limit unless limit.nil?
198
+ params[:offset] = offset unless offset.nil?
199
+ params[:status] = status unless status.nil?
200
+
201
+ response = @client.get("/webhooks/#{URI.encode_www_form_component(webhook_id)}/deliveries", params)
202
+ items = response.is_a?(Hash) ? response["deliveries"] : response
203
+ (items || []).map { |data| WebhookDelivery.new(data) }
181
204
  end
182
205
 
183
206
  # Retry a failed delivery