senddart 1.0.0 → 1.1.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.
@@ -0,0 +1,240 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SendDart
4
+ # Shared team inboxes: the inbox, its labels, conversations (threads) and
5
+ # their emails, drafts, and the AI agent settings. Path ids come first, in
6
+ # path order, then one params hash.
7
+ #
8
+ # Lists answer { "object" => "list", "has_more", "data" }. A refusal from the
9
+ # inbox rules is a 422 `validation_error` (404 `not_found`) whose body also
10
+ # carries a machine "code" (e.g. "receiving_choice_required") — read it from
11
+ # `SendDart::Error#body["code"]`.
12
+ module Inboxes
13
+ # Thread list / search filters, in the order they are sent.
14
+ THREAD_QUERY = %i[folder label query from to start_date end_date unread limit after].freeze
15
+
16
+ class << self
17
+ # Create an inbox. POST /inboxes — params: { email_address: } or
18
+ # { local:, domain_id: }, plus name:, from_name:, receiving: ("domain" |
19
+ # "forward", asked only when the domain cannot receive yet). Returns the
20
+ # "inbox": "id", "address", "name", "from_name", "view_mode",
21
+ # "domain_id", "domain", "receiving" ("forward" | "ready" | "pending" |
22
+ # "off"), "forward_address", "unread", "drafts", "last_received_at",
23
+ # "created_at".
24
+ def create(params)
25
+ Client.request(:post, "/inboxes", body: params)
26
+ end
27
+
28
+ # List the workspace's inboxes (limit / after / before). GET /inboxes
29
+ def list(params = {})
30
+ Client.request(:get, "/inboxes", query: Client.pagination(params))
31
+ end
32
+
33
+ # GET /inboxes/:id
34
+ def get(inbox_id)
35
+ Client.request(:get, "/inboxes/#{Client.path_escape(inbox_id)}")
36
+ end
37
+
38
+ # PATCH /inboxes/:id — params: { name:, from_name:, view_mode: ("list" | "board") }
39
+ def update(inbox_id, params)
40
+ Client.request(:patch, "/inboxes/#{Client.path_escape(inbox_id)}", body: params)
41
+ end
42
+
43
+ # Delete an inbox with its threads, labels and drafts (the messages stay
44
+ # under Emails). Returns { "object" => "inbox", "id", "deleted" => true }.
45
+ # DELETE /inboxes/:id
46
+ def delete(inbox_id)
47
+ Client.request(:delete, "/inboxes/#{Client.path_escape(inbox_id)}")
48
+ end
49
+
50
+ # @api private — "/inboxes/:id" + the (already escaped) segments that follow it.
51
+ def path(inbox_id, *segments)
52
+ (["/inboxes", Client.path_escape(inbox_id)] + segments.map { |s| s.is_a?(Symbol) ? s.to_s : s }).join("/")
53
+ end
54
+ end
55
+
56
+ # SendDart::Inboxes::Labels — an inbox's labels.
57
+ module Labels
58
+ class << self
59
+ # POST /inboxes/:id/labels — params: { name:, color: } (gray, red,
60
+ # orange, amber, green, teal, blue, violet, pink). Returns { "object" =>
61
+ # "inbox_label", "id", "inbox_id", "name", "color", "threads" }.
62
+ def create(inbox_id, params)
63
+ Client.request(:post, Inboxes.path(inbox_id, :labels), body: params)
64
+ end
65
+
66
+ # Every label with how many threads carry it. GET /inboxes/:id/labels
67
+ def list(inbox_id, params = {})
68
+ Client.request(:get, Inboxes.path(inbox_id, :labels), query: Client.pagination(params))
69
+ end
70
+
71
+ # PATCH /inboxes/:id/labels/:label_id — params: { name:, color: }
72
+ def update(inbox_id, label_id, params)
73
+ Client.request(:patch, Inboxes.path(inbox_id, :labels, Client.path_escape(label_id)), body: params)
74
+ end
75
+
76
+ # The label comes off every thread; the threads stay.
77
+ # DELETE /inboxes/:id/labels/:label_id
78
+ def delete(inbox_id, label_id)
79
+ Client.request(:delete, Inboxes.path(inbox_id, :labels, Client.path_escape(label_id)))
80
+ end
81
+ end
82
+ end
83
+
84
+ # SendDart::Inboxes::Threads — conversations and their emails.
85
+ module Threads
86
+ class << self
87
+ # One page of conversations, most recently active first. Filters:
88
+ # folder: ("inbox" default, "sent", "archive", "spam", "trash"),
89
+ # label: (label id), query: (dashboard search syntax), from: / to:
90
+ # (String or Array), start_date: / end_date: (YYYY-MM-DD, end
91
+ # exclusive), unread: (true/false); paging limit: / after: (`before`
92
+ # is a 422). GET /inboxes/:id/threads
93
+ def list(inbox_id, params = {})
94
+ Client.request(:get, Inboxes.path(inbox_id, :threads), query: Client.list_filters(params, *THREAD_QUERY))
95
+ end
96
+
97
+ # Search conversations — same filters and answer as `list`; looks
98
+ # across Inbox, Sent and Archive unless `folder` is spam or trash.
99
+ # GET /inboxes/:id/threads/search
100
+ def search(inbox_id, params)
101
+ Client.request(:get, Inboxes.path(inbox_id, :threads, :search),
102
+ query: Client.list_filters(params, *THREAD_QUERY))
103
+ end
104
+
105
+ # GET /inboxes/:id/threads/:thread_id
106
+ def get(inbox_id, thread_id)
107
+ Client.request(:get, thread_path(inbox_id, thread_id))
108
+ end
109
+
110
+ # Move, mark read or assign. PATCH /inboxes/:id/threads/:thread_id —
111
+ # params: { folder:, read: (or unread:), assignee: (address or nil) }
112
+ def update(inbox_id, thread_id, params)
113
+ Client.request(:patch, thread_path(inbox_id, thread_id), body: params)
114
+ end
115
+
116
+ # Moves the conversation to Trash; one already in Trash is removed for
117
+ # good. Returns { "object" => "inbox_thread", "id", "inbox_id",
118
+ # "deleted", "folder" => "trash" }. DELETE /inboxes/:id/threads/:thread_id
119
+ def delete(inbox_id, thread_id)
120
+ Client.request(:delete, thread_path(inbox_id, thread_id))
121
+ end
122
+
123
+ # Add labels; returns the thread. POST …/threads/:thread_id/labels —
124
+ # params: { labels: [label ids] }
125
+ def add_labels(inbox_id, thread_id, params)
126
+ Client.request(:post, "#{thread_path(inbox_id, thread_id)}/labels", body: params)
127
+ end
128
+
129
+ # Make these the thread's only labels ([] clears); returns the thread.
130
+ # PUT …/threads/:thread_id/labels
131
+ def set_labels(inbox_id, thread_id, params)
132
+ Client.request(:put, "#{thread_path(inbox_id, thread_id)}/labels", body: params)
133
+ end
134
+
135
+ # Take one label off; returns the thread.
136
+ # DELETE …/threads/:thread_id/labels/:label_id
137
+ def remove_label(inbox_id, thread_id, label_id)
138
+ Client.request(:delete, "#{thread_path(inbox_id, thread_id)}/labels/#{Client.path_escape(label_id)}")
139
+ end
140
+
141
+ # Every message of the conversation, oldest first (not paginated).
142
+ # GET …/threads/:thread_id/emails
143
+ def list_emails(inbox_id, thread_id)
144
+ Client.request(:get, "#{thread_path(inbox_id, thread_id)}/emails")
145
+ end
146
+
147
+ # One message ("inbox_email"). GET …/threads/:thread_id/emails/:email_id
148
+ def get_email(inbox_id, thread_id, email_id)
149
+ Client.request(:get, email_path(inbox_id, thread_id, email_id))
150
+ end
151
+
152
+ # Reply from the inbox address — to the sender, everyone with
153
+ # `reply_all: true`, or `to:`. params: { html: | text:, to:, cc:, bcc:,
154
+ # subject:, reply_all:, attachments: }. Needs a full-access key;
155
+ # `idempotency_key` is honoured. Returns { "object" => "email", "id",
156
+ # "inbox_id", "thread_id" }. POST …/emails/:email_id/reply
157
+ def reply(inbox_id, thread_id, email_id, params, options = {})
158
+ Client.request(:post, "#{email_path(inbox_id, thread_id, email_id)}/reply", body: params, options: options)
159
+ end
160
+
161
+ # Forward (`to:` required); the original is quoted and its files
162
+ # attached. Same answer and idempotency as `reply`.
163
+ # POST …/emails/:email_id/forward
164
+ def forward(inbox_id, thread_id, email_id, params, options = {})
165
+ Client.request(:post, "#{email_path(inbox_id, thread_id, email_id)}/forward", body: params, options: options)
166
+ end
167
+
168
+ private
169
+
170
+ def thread_path(inbox_id, thread_id)
171
+ Inboxes.path(inbox_id, :threads, Client.path_escape(thread_id))
172
+ end
173
+
174
+ def email_path(inbox_id, thread_id, email_id)
175
+ "#{thread_path(inbox_id, thread_id)}/emails/#{Client.path_escape(email_id)}"
176
+ end
177
+ end
178
+ end
179
+
180
+ # SendDart::Inboxes::Drafts — unsent messages.
181
+ module Drafts
182
+ class << self
183
+ # Open a draft. POST /inboxes/:id/drafts — params: { mode: ("compose"
184
+ # default, "reply", "reply_all", "forward"), email_id: (every mode but
185
+ # compose), to:, cc:, bcc:, subject:, html:, text:, attachments:
186
+ # [{ filename:, content: (base64), content_type: }] }. A message has at
187
+ # most one open answer: asking again returns it.
188
+ def create(inbox_id, params = {})
189
+ Client.request(:post, Inboxes.path(inbox_id, :drafts), body: params)
190
+ end
191
+
192
+ # Most recently edited first. GET /inboxes/:id/drafts
193
+ def list(inbox_id, params = {})
194
+ Client.request(:get, Inboxes.path(inbox_id, :drafts), query: Client.pagination(params))
195
+ end
196
+
197
+ # GET /inboxes/:id/drafts/:draft_id
198
+ def get(inbox_id, draft_id)
199
+ Client.request(:get, Inboxes.path(inbox_id, :drafts, Client.path_escape(draft_id)))
200
+ end
201
+
202
+ # PATCH /inboxes/:id/drafts/:draft_id — params: { to:, cc:, bcc:, subject:, html:, text: }
203
+ def update(inbox_id, draft_id, params)
204
+ Client.request(:patch, Inboxes.path(inbox_id, :drafts, Client.path_escape(draft_id)), body: params)
205
+ end
206
+
207
+ # Discard a draft. DELETE /inboxes/:id/drafts/:draft_id
208
+ def delete(inbox_id, draft_id)
209
+ Client.request(:delete, Inboxes.path(inbox_id, :drafts, Client.path_escape(draft_id)))
210
+ end
211
+
212
+ # Send the draft from the inbox address and file it in its
213
+ # conversation. Needs a full-access key; `idempotency_key` is honoured.
214
+ # Returns { "object" => "email", "id", "inbox_id", "thread_id" }.
215
+ # POST /inboxes/:id/drafts/:draft_id/send
216
+ def send(inbox_id, draft_id, options = {})
217
+ Client.request(:post, "#{Inboxes.path(inbox_id, :drafts, Client.path_escape(draft_id))}/send", options: options)
218
+ end
219
+ end
220
+ end
221
+
222
+ # SendDart::Inboxes::Agent — the inbox's AI agent settings.
223
+ module Agent
224
+ class << self
225
+ # { "object" => "inbox_agent", "inbox_id", "instructions", "actions",
226
+ # "tone" => { "length", "register" }, "available_actions",
227
+ # "updated_at" }. GET /inboxes/:id/agent
228
+ def get(inbox_id)
229
+ Client.request(:get, Inboxes.path(inbox_id, :agent))
230
+ end
231
+
232
+ # PATCH /inboxes/:id/agent — params: { instructions:, actions: [...],
233
+ # tone: { length: 0-100, register: 0-100 } }
234
+ def update(inbox_id, params)
235
+ Client.request(:patch, Inboxes.path(inbox_id, :agent), body: params)
236
+ end
237
+ end
238
+ end
239
+ end
240
+ end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SendDart
4
+ class << self
5
+ # Walk every page of a cursor-paginated list and yield each item, lazily:
6
+ # the next page is requested only when the enumerator gets there. Returns
7
+ # an Enumerator, so `.first(250)`, `.each_slice`, `.lazy.select` all work.
8
+ #
9
+ # Pass a list method (anything responding to #call(params)) and its params:
10
+ #
11
+ # SendDart.paginate(SendDart::Campaigns.method(:list), { limit: 100 }).each do |campaign|
12
+ # puts campaign["id"]
13
+ # end
14
+ #
15
+ # or a block, for lists that take an id first:
16
+ #
17
+ # SendDart.paginate({ limit: 100 }) { |page| SendDart::Segments.contacts(seg_id, page) }.to_a
18
+ #
19
+ # Pages forward with `after` = the last item's id until `has_more` is
20
+ # false (an `after` in params is the starting cursor). `before` is not
21
+ # supported here — it pages backwards and cannot be combined with `after`.
22
+ def paginate(fetch = nil, params = {}, &block)
23
+ if block
24
+ raise ArgumentError, "SendDart.paginate takes a list method or a block, not both" if fetch.respond_to?(:call)
25
+
26
+ params = fetch unless fetch.nil?
27
+ fetch = block
28
+ end
29
+ raise ArgumentError, "SendDart.paginate needs a list method or a block" unless fetch.respond_to?(:call)
30
+ raise ArgumentError, "SendDart.paginate params must be a Hash" unless params.is_a?(Hash)
31
+ unless Client.opt(params, :before).nil?
32
+ raise ArgumentError, "SendDart.paginate walks forward with `after`; drop `before`"
33
+ end
34
+
35
+ Enumerator.new do |yielder|
36
+ page_params = params
37
+ loop do
38
+ page = fetch.call(page_params)
39
+ data = page.is_a?(Hash) ? Array(page["data"]) : []
40
+ data.each { |item| yielder << item }
41
+
42
+ last_id = data.last.is_a?(Hash) ? data.last["id"] : nil
43
+ break unless last_id && page["has_more"] == true
44
+
45
+ page_params = Client.without(params, :after).merge(after: last_id)
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,100 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "time"
4
+
5
+ module SendDart
6
+ # The rate-limit headers of one response, parsed. Every field is nil when
7
+ # the response did not carry that header.
8
+ #
9
+ # rl = SendDart.last_response.rate_limit
10
+ # rl.limit # => 30 (RateLimit-Limit: requests allowed in the window)
11
+ # rl.remaining # => 29 (RateLimit-Remaining)
12
+ # rl.reset # => 41 (RateLimit-Reset: seconds until the window resets)
13
+ # rl.retry_after # => 2.0 (Retry-After, in seconds; also parses an HTTP-date)
14
+ RateLimit = Struct.new(:limit, :remaining, :reset, :retry_after) do
15
+ # Build from a { "lowercase-name" => "value" } header hash.
16
+ def self.from_headers(headers)
17
+ new(
18
+ integer(headers["ratelimit-limit"]),
19
+ integer(headers["ratelimit-remaining"]),
20
+ integer(headers["ratelimit-reset"]),
21
+ seconds(headers["retry-after"])
22
+ )
23
+ end
24
+
25
+ def self.integer(value)
26
+ return nil if value.nil?
27
+
28
+ Integer(value.to_s.strip, 10)
29
+ rescue ArgumentError
30
+ nil
31
+ end
32
+
33
+ # Retry-After is delta-seconds or an HTTP-date; both become seconds from
34
+ # now (never negative). Unlike the retry loop, this is NOT capped.
35
+ def self.seconds(value)
36
+ return nil if value.nil? || value.to_s.strip.empty?
37
+
38
+ str = value.to_s.strip
39
+ secs = begin
40
+ Float(str)
41
+ rescue ArgumentError
42
+ begin
43
+ Time.httpdate(str) - Time.now
44
+ rescue ArgumentError
45
+ return nil
46
+ end
47
+ end
48
+ return nil unless secs.finite?
49
+
50
+ secs.negative? ? 0.0 : secs.to_f
51
+ end
52
+ private_class_method :integer, :seconds
53
+ end
54
+
55
+ # Status and headers of one HTTP response. Read the most recent one on the
56
+ # current thread with SendDart.last_response, or from a raised error with
57
+ # SendDart::Error#response.
58
+ #
59
+ # SendDart::Emails.send(params)
60
+ # res = SendDart.last_response
61
+ # res.status_code # => 200
62
+ # res["RateLimit-Remaining"] # => "29" (case-insensitive lookup)
63
+ # res.headers # => { "ratelimit-remaining" => "29", ... }
64
+ # res.rate_limit.remaining # => 29
65
+ class Response
66
+ # The HTTP status as an Integer.
67
+ attr_reader :status_code
68
+
69
+ # Every response header, keys lower-cased, values as Strings (repeated
70
+ # headers are joined with ", "). Frozen.
71
+ attr_reader :headers
72
+
73
+ def initialize(status_code, headers = {})
74
+ @status_code = status_code
75
+ @headers = headers.each_with_object({}) { |(k, v), h| h[k.to_s.downcase] = v.to_s }.freeze
76
+ end
77
+
78
+ # Case-insensitive single-header lookup; nil when absent.
79
+ def [](name)
80
+ @headers[name.to_s.downcase]
81
+ end
82
+
83
+ # The parsed RateLimit-* and Retry-After headers (see SendDart::RateLimit).
84
+ def rate_limit
85
+ @rate_limit ||= RateLimit.from_headers(@headers)
86
+ end
87
+
88
+ # Build from a Net::HTTPResponse (or any object exposing #code and,
89
+ # optionally, #each_header).
90
+ def self.from_http(resp)
91
+ headers = {}
92
+ if resp.respond_to?(:each_header)
93
+ resp.each_header { |k, v| headers[k] = v }
94
+ elsif resp.respond_to?(:to_hash)
95
+ resp.to_hash.each { |k, v| headers[k] = Array(v).join(", ") }
96
+ end
97
+ new(resp.code.to_i, headers)
98
+ end
99
+ end
100
+ end
@@ -47,6 +47,20 @@ module SendDart
47
47
  def delete(segment_id)
48
48
  Client.request(:delete, "/segments/#{Client.path_escape(segment_id)}")
49
49
  end
50
+
51
+ # Move one contact, or every contact, from this segment to another.
52
+ # POST /segments/:id/move — params: { destination_id:, contact_id: } or
53
+ # { destination_id:, all: true } (exactly one of the two), plus optional
54
+ # `preview: true` (count only, nothing moves) and `expected_count:` (the
55
+ # count you previewed; a mismatch is a 409, as is a source that changed).
56
+ # Returns { "source_id", "destination_id", "source_name",
57
+ # "destination_name", "count", "preview", "moved" }. A 422
58
+ # validation_error covers bad input or incompatible segment rules; a 503
59
+ # application_error means the segment is busy — try again shortly.
60
+ # Segments.move("seg_1", { destination_id: "seg_2", all: true, preview: true })
61
+ def move(segment_id, params)
62
+ Client.request(:post, "/segments/#{Client.path_escape(segment_id)}/move", body: params)
63
+ end
50
64
  end
51
65
  end
52
66
  end
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SendDart
4
+ # The addresses SendDart will not send to. A suppression is
5
+ # { "object" => "suppression", "id" (a number as text), "email", "origin"
6
+ # ("bounce" | "complaint" | "manual" | "unsubscribe"), "domain" (nil for an
7
+ # account-wide row, else the sending domain), "created_at" }. Adding and
8
+ # removing raise the `suppression.added` / `suppression.removed` webhooks.
9
+ module Suppressions
10
+ class << self
11
+ # Suppress one address (origin "manual"): 201 when new, 200 with the
12
+ # existing row when already listed. POST /suppressions — params: { email: }
13
+ def create(params)
14
+ Client.request(:post, "/suppressions", body: params)
15
+ end
16
+
17
+ # Newest first. Filters origin:, search:, created_after: /
18
+ # created_before: (ISO 8601; malformed is a 422); paging limit: / after:
19
+ # / before:. GET /suppressions
20
+ def list(params = {})
21
+ query = Client.pagination(params).merge(
22
+ Client.filters(params, :origin, :search, :created_after, :created_before)
23
+ )
24
+ Client.request(:get, "/suppressions", query: query)
25
+ end
26
+
27
+ # By id or by address (the account-wide row first).
28
+ # GET /suppressions/:id_or_email
29
+ def get(id_or_email)
30
+ Client.request(:get, "/suppressions/#{Client.path_escape(id_or_email)}")
31
+ end
32
+
33
+ # By address removes every row for it. Returns { "object" =>
34
+ # "suppression", "id", "email", "deleted" => true }.
35
+ # DELETE /suppressions/:id_or_email
36
+ def delete(id_or_email)
37
+ Client.request(:delete, "/suppressions/#{Client.path_escape(id_or_email)}")
38
+ end
39
+
40
+ # Up to 1,000 addresses. Returns { "object" => "list", "data" =>
41
+ # [suppression], "skipped" => [{ "email", "reason" ("invalid" |
42
+ # "duplicate" | "already_listed") }] }.
43
+ # POST /suppressions/batch/add — params: { emails: [...] }
44
+ def batch_add(params)
45
+ Client.request(:post, "/suppressions/batch/add", body: params)
46
+ end
47
+
48
+ # Up to 1,000 ids and/or emails. Returns { "object" => "list", "data" =>
49
+ # [removed suppression] }. POST /suppressions/batch/remove — params:
50
+ # { ids: [...], emails: [...] }
51
+ def batch_remove(params)
52
+ Client.request(:post, "/suppressions/batch/remove", body: params)
53
+ end
54
+ end
55
+ end
56
+ end
@@ -8,14 +8,16 @@ module SendDart
8
8
  Client.request(:post, "/templates", body: params)
9
9
  end
10
10
 
11
- # GET /templates/:id (an alias works anywhere an id is accepted)
11
+ # GET /templates/:id (an alias works anywhere an id is accepted). Carries
12
+ # "folder_id" and "created_by".
12
13
  def get(template_id)
13
14
  Client.request(:get, "/templates/#{Client.path_escape(template_id)}")
14
15
  end
15
16
 
16
- # GET /templates
17
+ # GET /templates — paging plus folder_id: (a folder id, or "root" for
18
+ # templates in no folder). Rows carry "folder_id".
17
19
  def list(params = {})
18
- Client.request(:get, "/templates", query: Client.pagination(params))
20
+ Client.request(:get, "/templates", query: Client.pagination(params).merge(Client.filters(params, :folder_id)))
19
21
  end
20
22
 
21
23
  # PATCH /templates/:id
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SendDart
4
+ # The account's usage meters and limits.
5
+ module Usage
6
+ class << self
7
+ # GET /usage (any key that can read) — { "object" => "usage",
8
+ # "transactional" => { "plan" => { "id", "name" }, "monthly" => { "used",
9
+ # "limit", "received" }, "daily" => {...}, "webhook_endpoints" => {
10
+ # "used", "limit" } | nil }, "marketing" => { "plan", "contacts", "segments",
11
+ # "broadcasts" => "unlimited" }, "team" => { "ai_credits",
12
+ # "automation_runs", "domains", "inboxes", "retention_days" } }.
13
+ # A "limit" of nil means unlimited.
14
+ def get
15
+ Client.request(:get, "/usage")
16
+ end
17
+ end
18
+ end
19
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SendDart
4
- VERSION = "1.0.0"
4
+ VERSION = "1.1.0"
5
5
  end
@@ -59,6 +59,46 @@ module SendDart
59
59
  Client.request(:delete, "/webhooks/#{Client.path_escape(webhook_id)}")
60
60
  end
61
61
 
62
+ # What this endpoint was sent, newest first — one event per message id:
63
+ # { "object" => "webhook_event", "id" => "msg_…", "webhook_id", "type",
64
+ # "status" ("delivered" | "failed" | "retrying"), "attempts",
65
+ # "response_status", "error", "created_at", "last_attempt_at" }.
66
+ # Filters status:, type:; paging limit: (1-100, 20) and after: (no
67
+ # `before`). GET /webhooks/:id/events
68
+ def list_events(webhook_id, params = {})
69
+ query = Client.filters(params, :limit, :after, :status, :type)
70
+ Client.request(:get, "/webhooks/#{Client.path_escape(webhook_id)}/events", query: query)
71
+ end
72
+
73
+ # One event, with the "payload" that was sent.
74
+ # GET /webhooks/:id/events/:event_id
75
+ def get_event(webhook_id, event_id)
76
+ Client.request(:get, "/webhooks/#{Client.path_escape(webhook_id)}/events/#{Client.path_escape(event_id)}")
77
+ end
78
+
79
+ # Every try at delivering one event, oldest first: { "object" =>
80
+ # "webhook_event_attempt", "id", "event_id", "attempt", "status"
81
+ # ("succeeded" | "failed"), "response_status", "error", "created_at" }.
82
+ # GET /webhooks/:id/events/:event_id/attempts
83
+ def list_event_attempts(webhook_id, event_id)
84
+ Client.request(
85
+ :get,
86
+ "/webhooks/#{Client.path_escape(webhook_id)}/events/#{Client.path_escape(event_id)}/attempts"
87
+ )
88
+ end
89
+
90
+ # Send one event again now (same payload and message id, one attempt,
91
+ # no automatic retries). Needs write access. Returns { "object" =>
92
+ # "webhook_event_replay", "id", "attempt", "event" }; a disabled
93
+ # endpoint, one no longer listening for the type, or a test event is a
94
+ # 422 validation_error. POST /webhooks/:id/events/:event_id/replay
95
+ def replay_event(webhook_id, event_id)
96
+ Client.request(
97
+ :post,
98
+ "/webhooks/#{Client.path_escape(webhook_id)}/events/#{Client.path_escape(event_id)}/replay"
99
+ )
100
+ end
101
+
62
102
  # Verify a webhook delivery's Svix-style signature against your endpoint's
63
103
  # signing secret. Pure local computation (OpenSSL HMAC-SHA256) — no HTTP.
64
104
  #
data/lib/senddart.rb CHANGED
@@ -2,7 +2,9 @@
2
2
 
3
3
  require "senddart/version"
4
4
  require "senddart/error"
5
+ require "senddart/response"
5
6
  require "senddart/client"
7
+ require "senddart/pagination"
6
8
  require "senddart/emails"
7
9
  require "senddart/domains"
8
10
  require "senddart/audiences"
@@ -18,6 +20,10 @@ require "senddart/events"
18
20
  require "senddart/api_keys"
19
21
  require "senddart/logs"
20
22
  require "senddart/polls"
23
+ require "senddart/account"
24
+ require "senddart/inboxes"
25
+ require "senddart/suppressions"
26
+ require "senddart/usage"
21
27
 
22
28
  # The SendDart API client.
23
29
  #
@@ -77,5 +83,16 @@ module SendDart
77
83
  def configure
78
84
  yield self
79
85
  end
86
+
87
+ # Status and headers (a SendDart::Response) of the most recent API
88
+ # response on the CURRENT thread/fiber, success or failure; nil before
89
+ # the first call. Per-thread, so concurrent threads never see each
90
+ # other's. Read it right after the call you care about:
91
+ #
92
+ # SendDart::Emails.send(params)
93
+ # SendDart.last_response.rate_limit.remaining # => 29
94
+ def last_response
95
+ Thread.current[Client::LAST_RESPONSE_KEY]
96
+ end
80
97
  end
81
98
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: senddart
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - SendDart
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-09-29 00:00:00.000000000 Z
11
+ date: 2026-11-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -36,6 +36,7 @@ files:
36
36
  - LICENSE
37
37
  - README.md
38
38
  - lib/senddart.rb
39
+ - lib/senddart/account.rb
39
40
  - lib/senddart/api_keys.rb
40
41
  - lib/senddart/audiences.rb
41
42
  - lib/senddart/automations.rb
@@ -47,11 +48,16 @@ files:
47
48
  - lib/senddart/emails.rb
48
49
  - lib/senddart/error.rb
49
50
  - lib/senddart/events.rb
51
+ - lib/senddart/inboxes.rb
50
52
  - lib/senddart/logs.rb
53
+ - lib/senddart/pagination.rb
51
54
  - lib/senddart/polls.rb
55
+ - lib/senddart/response.rb
52
56
  - lib/senddart/segments.rb
57
+ - lib/senddart/suppressions.rb
53
58
  - lib/senddart/templates.rb
54
59
  - lib/senddart/topics.rb
60
+ - lib/senddart/usage.rb
55
61
  - lib/senddart/version.rb
56
62
  - lib/senddart/webhooks.rb
57
63
  homepage: https://www.senddart.com