postwire 0.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: ea8aa38f8c82563ebd1fafe4dcef4553fbbe5d6b5650a3554fe0b3f4a3cd4cf7
4
+ data.tar.gz: bc7e30a43f4b9c2b200c706d71caa2e17acf2afc5d349a6f2add4a5530b56ef1
5
+ SHA512:
6
+ metadata.gz: caa4a97d5fe8c38545f7581955c8caed4b9a5d8b7fc2991c95b49b59e450506fbb01aaee49b919dfc5e0d3594c87cbac3af97723d6e964e2dbfd48aad985b228
7
+ data.tar.gz: d7d850a6ca0fc069959576d8117409d7cc7344b4d2d40544774c3be33d4de1311bb32f1cc051418e77476c3f0205e7c8b5f0c67f1590726c79b2a465e3cd7581
data/CHANGELOG.md ADDED
@@ -0,0 +1,91 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [1.4.0] - 2026-11-25
9
+
10
+ ### Added
11
+
12
+ - Emails take optional `metadata`: up to 50 key/value pairs of your own (e.g. `metadata: { customer_id: "cus_123" }`), returned when you fetch the email and included in webhook payloads. This applies to `VoupeSend::Emails.send` and to the ActionMailer delivery method (`mail(metadata: { customer_id: "cus_123" })`).
13
+
14
+ ## [1.3.0] - 2026-11-16
15
+
16
+ ### Changed
17
+
18
+ - Emails take a single `tag` string (e.g. `tag: "password_reset"`) instead of a `tags` hash, matching the Voupe Send API. This applies to `VoupeSend::Emails.send` and to the ActionMailer delivery method (`mail(tag: "password_reset")`).
19
+
20
+ ## [1.2.0] - 2026-11-16
21
+
22
+ ### Removed
23
+
24
+ - Email scheduling, which the Voupe Send API no longer supports:
25
+ - `VoupeSend::Emails.update` (used to reschedule an email)
26
+ - `VoupeSend::Emails.cancel` (used to cancel a scheduled email)
27
+ - `examples/schedule_email.rb`
28
+
29
+ ### Added
30
+
31
+ - README docs for the Emails API: sending, attachments, idempotent sending, per-request options, responses and errors.
32
+ - README docs for webhooks, including signature verification with `VoupeSend::Webhooks.verify`.
33
+ - Tests for `VoupeSend::Webhooks.verify`.
34
+
35
+ ### Changed
36
+
37
+ - Releases are published to GitHub Packages (`rubygems.pkg.github.com/voupe`). The gemspec now sets `allowed_push_host` to that registry and links the package to `voupe/send-gem`.
38
+ - Dependabot keeps the gems and GitHub Actions up to date.
39
+ - Development dependencies updated, including Faraday 2.15.1 in the lockfile.
40
+
41
+ ## [1.1.0] - 2026-10-18
42
+
43
+ No changes to the library itself; this release is about CI and publishing.
44
+
45
+ ### Changed
46
+
47
+ - CI moved from GitHub Actions to Forgejo, then to Woodpecker, with separate test, lint and publish pipelines.
48
+ - A `v*` tag publishes the gem to the Forgejo package registry once tests and lint pass.
49
+ - Development dependencies updated, including Faraday 2.15.0 and Minitest 6 in the lockfile.
50
+
51
+ ### Removed
52
+
53
+ - The unused `Dockerfile`, `docker-compose.yml` and `sig/voupe_send.rbs`.
54
+
55
+ ## [1.0.0] - 2026-08-18
56
+
57
+ First release as **Voupe Send**. The library was previously published as `emailfuse`; this release renames it and settles the public API at 1.0.
58
+
59
+ ### ⚠️ BREAKING CHANGES
60
+
61
+ The rename is a clean break with no backwards-compatibility aliases. Everything below changes at once, so migrating means updating all of it.
62
+
63
+ - Gem name: `emailfuse` → `voupe_send`
64
+ - Require path: `require "emailfuse"` / `require "email_fuse"` → `require "voupe_send"`
65
+ - Module namespace: `EmailFuse` → `VoupeSend` (e.g. `EmailFuse::Emails.send` → `VoupeSend::Emails.send`)
66
+ - Environment variable: `EMAILFUSE_API_KEY` → `VOUPE_SEND_API_KEY`
67
+ - ActionMailer delivery method: `:emailfuse` → `:voupe_send`
68
+ - ActionMailer settings key: `config.action_mailer.emailfuse_settings` → `config.action_mailer.voupe_send_settings`
69
+ - Default API base URL: `https://api.emailfuse.net` → `https://send.voupe.com/api`
70
+ - Removed the batch email API: `VoupeSend::Batch`, the `emails/batch` endpoint wrapper, and the `:batch_validation` request option (`x-batch-validation` header)
71
+ - Replaced HTTParty with Faraday (`>= 2.0`) as the HTTP client. The public API is unchanged, but the gem now depends on `faraday` instead of `httparty`
72
+ - Errors are now raised from the real HTTP response status, falling back to a `statusCode` in the response body. Previously a 4xx/5xx response whose body carried no `statusCode` was returned as a success
73
+ - Test suite moved from RSpec to Minitest (`test/**/*_test.rb`, `rake test`). This affects contributors only, not users of the gem
74
+ - Renamed `VoupeSend::Mailer#build_resend_params` to `#build_params`
75
+ - User-Agent header is now `VoupeSend:v<version>`
76
+
77
+ **Before:**
78
+
79
+ ```ruby
80
+ require "emailfuse"
81
+ EmailFuse.api_key = ENV["EMAILFUSE_API_KEY"]
82
+ EmailFuse::Emails.send(params)
83
+ ```
84
+
85
+ **After:**
86
+
87
+ ```ruby
88
+ require "voupe_send"
89
+ VoupeSend.api_key = ENV["VOUPE_SEND_API_KEY"]
90
+ VoupeSend::Emails.send(params)
91
+ ```
data/README.md ADDED
@@ -0,0 +1,375 @@
1
+ # Postwire Ruby and Rails SDK
2
+
3
+ ---
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem "postwire"
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ ```
16
+ bundle install
17
+ ```
18
+
19
+ Or install it yourself as:
20
+
21
+ ```
22
+ gem install postwire
23
+ ```
24
+
25
+ ## Setup
26
+
27
+ ```ruby
28
+ require "postwire"
29
+ Postwire.api_key = ENV["POSTWIRE_API_KEY"]
30
+ ```
31
+
32
+ or
33
+
34
+ ```ruby
35
+ require "postwire"
36
+ Postwire.configure do |config|
37
+ config.api_key = ENV["POSTWIRE_API_KEY"]
38
+ end
39
+ ```
40
+
41
+ ## Example
42
+
43
+ ```rb
44
+ require "postwire"
45
+
46
+ Postwire.api_key = ENV["POSTWIRE_API_KEY"]
47
+
48
+ params = {
49
+ "from": "onboarding@example.com",
50
+ "to": ["delivered@example.com", "your@email.com"],
51
+ "html": "<h1>Hello World</h1>",
52
+ "subject": "Hey"
53
+ }
54
+ r = Postwire::Emails.send(params)
55
+ puts r
56
+ ```
57
+
58
+ ## Emails
59
+
60
+ ### Sending
61
+
62
+ `Postwire::Emails.send` takes a hash of email params. `:from` and `:to` are required (it raises `ArgumentError` without them). Keys can be symbols or strings.
63
+
64
+ ```rb
65
+ Postwire::Emails.send(
66
+ from: "Acme <onboarding@example.com>",
67
+ to: ["delivered@example.com"], # a string or an array
68
+ cc: ["cc@example.com"],
69
+ bcc: ["bcc@example.com"],
70
+ reply_to: "support@example.com",
71
+ subject: "Hello",
72
+ html: "<p>Hello!</p>",
73
+ text: "Hello!",
74
+ headers: { "X-Entity-Ref-ID" => "123" },
75
+ tag: "password_reset",
76
+ metadata: { customer_id: "cus_123" }
77
+ )
78
+ # => #<Postwire::Response data={id: "49a3999c-..."} ...>
79
+ ```
80
+
81
+ #### Metadata
82
+
83
+ `metadata` attaches up to 50 key/value pairs of your own to an email, such as a customer or order ID, so you can match it back to your records. It's returned when you fetch the email and included in every webhook payload for it, so a bounce tells you which customer it belongs to:
84
+
85
+ ```rb
86
+ Postwire::Emails.send(
87
+ from: "billing@example.com",
88
+ to: user.email,
89
+ subject: "Your invoice",
90
+ html: "<p>Thanks!</p>",
91
+ metadata: { customer_id: user.customer_id, invoice_id: invoice.id }
92
+ )
93
+ ```
94
+
95
+ Keys are up to 40 characters of letters, numbers, `_`, `-` and `.`. Values are strings of up to 500 characters; numbers and booleans are converted to strings, and blank values are dropped. Nested hashes or arrays are rejected with a `Postwire::Error::InvalidRequestError`.
96
+
97
+ With ActionMailer, pass it to `mail`:
98
+
99
+ ```rb
100
+ mail(to: user.email, subject: "Your invoice", metadata: { customer_id: user.customer_id })
101
+ ```
102
+
103
+ #### Attachments
104
+
105
+ Pass attachments either as file content (a byte array or a Base64 string) or as a remote `path`. Set `content_id` to reference an attachment inline from your HTML with `cid:`:
106
+
107
+ ```rb
108
+ Postwire::Emails.send(
109
+ from: "onboarding@example.com",
110
+ to: ["delivered@example.com"],
111
+ subject: "Your invoice",
112
+ html: '<p>Thanks! <img src="cid:logo" /></p>',
113
+ attachments: [
114
+ { filename: "invoice.pdf", content: File.binread("invoice.pdf").bytes },
115
+ { filename: "terms.pdf", content: Base64.strict_encode64(File.binread("terms.pdf")) },
116
+ { filename: "logo.png", path: "https://example.com/logo.png", content_id: "logo" }
117
+ ]
118
+ )
119
+ ```
120
+
121
+ Use `Postwire::Emails::Attachments.list(email_id:)` and `.get(id:, email_id:)` to fetch the attachments of an email you've sent.
122
+
123
+ ### Idempotent sending
124
+
125
+ Network failures and timeouts leave you not knowing whether an email was sent. If you retry blindly, the recipient may get it twice. To retry safely, pass an **idempotency key**:
126
+
127
+ ```rb
128
+ Postwire::Emails.send(
129
+ params,
130
+ options: { idempotency_key: "welcome-email/#{user.id}" }
131
+ )
132
+ ```
133
+
134
+ The key is sent as the `Idempotency-Key` request header. If you send the same key again, the API recognises it as a repeat of the earlier request rather than a new email.
135
+
136
+ Tips:
137
+
138
+ - **Derive the key from what the email is for**, such as `"order-confirmation/#{order.id}"` or `"password-reset/#{token.id}"`. Don't generate a random value on each attempt, because a fresh key on a retry defeats the purpose.
139
+ - **Reuse the exact same key and params when you retry.** A key identifies one specific email.
140
+ - **The gem does not retry for you.** Idempotency only matters when *your* code, or your job queue (Sidekiq, Solid Queue, etc.), retries. That's exactly where it's most useful: a job that crashes after sending, then gets retried, won't send a duplicate.
141
+ - The header is only added to `POST` requests, and only when the key is a non-empty string. `nil` or `""` sends the request without one.
142
+
143
+ ```rb
144
+ class SendOrderConfirmationJob < ApplicationJob
145
+ retry_on Postwire::Error::ServerError, Faraday::TimeoutError, wait: :polynomially_longer
146
+
147
+ def perform(order)
148
+ Postwire::Emails.send(
149
+ {
150
+ from: "shop@example.com",
151
+ to: order.email,
152
+ subject: "Order ##{order.number} confirmed",
153
+ html: OrdersController.render(:confirmation, assigns: { order: order })
154
+ },
155
+ options: { idempotency_key: "order-confirmation/#{order.id}" }
156
+ )
157
+ end
158
+ end
159
+ ```
160
+
161
+ With ActionMailer, pass the key through `options` on `mail` (see [Rails and ActionMailer support](#rails-and-actionmailer-support)):
162
+
163
+ ```rb
164
+ mail(to: user.email, subject: "Welcome!", options: { idempotency_key: "welcome/#{user.id}" })
165
+ ```
166
+
167
+ ### Per-request options
168
+
169
+ Besides `idempotency_key`, `options:` can override the global configuration for a single call:
170
+
171
+ | Option | Description |
172
+ |--------------------|----------------------------------------------------------------------------|
173
+ | `:idempotency_key` | Sent as the `Idempotency-Key` header |
174
+ | `:api_key` | Use a different API key (string or a `Proc` returning one) |
175
+ | `:base_url` | Use a different API base URL |
176
+ | `:timeout` | Request timeout in seconds (default: `Postwire.timeout`, then 30) |
177
+
178
+ ### Retrieving and listing
179
+
180
+ ```rb
181
+ email = Postwire::Emails.get("49a3999c-0ce1-4ea6-ab68-afcd6dc2e794")
182
+ email[:subject]
183
+
184
+ page = Postwire::Emails.list(limit: 20) # limit: 1–100, default 20
185
+ page[:data].each { |e| puts e["subject"] }
186
+
187
+ if page[:has_more]
188
+ Postwire::Emails.list(limit: 20, after: page[:data].last["id"])
189
+ end
190
+ ```
191
+
192
+ ### Receiving
193
+
194
+ Email sent to a domain that has receiving turned on is stored by Postwire, and each webhook subscribed to `inbound` gets an event with the email and its attachments' ids, names, types and sizes. Fetch an attachment to get its content, base64-encoded:
195
+
196
+ ```rb
197
+ Postwire::Emails::Receiving.list # most recent first
198
+ Postwire::Emails::Receiving.get("4ef9a417-...") # one received email
199
+
200
+ attachments = Postwire::Emails::Receiving::Attachments.list(email_id: "4ef9a417-...")
201
+ attachment = Postwire::Emails::Receiving::Attachments.get(id: attachments[:data].first["id"], email_id: "4ef9a417-...")
202
+ File.binwrite(attachment[:filename], Base64.decode64(attachment[:content]))
203
+ ```
204
+
205
+ An `inbound` webhook event looks like this:
206
+
207
+ ```json
208
+ {
209
+ "type": "inbound",
210
+ "inbound_email": {
211
+ "id": "4ef9a417-...",
212
+ "from": "Dean <dean@example.com>",
213
+ "to": ["receipts@in.example.com"],
214
+ "subject": "Your invoice",
215
+ "attachments": [{ "id": "42", "filename": "invoice.pdf", "content_type": "application/pdf", "size": 48213 }]
216
+ }
217
+ }
218
+ ```
219
+
220
+ ### Responses
221
+
222
+ Every call returns a `Postwire::Response`, which behaves like a symbol-keyed hash (`response[:id]`, `response.dig(...)`, `response.to_h`). It also exposes the HTTP response headers:
223
+
224
+ ```rb
225
+ response = Postwire::Emails.send(params)
226
+ response[:id]
227
+ response.headers["ratelimit-remaining"]
228
+ ```
229
+
230
+ ### Errors
231
+
232
+ API failures raise subclasses of `Postwire::Error`, which carry `#code` (the HTTP status) and `#headers`:
233
+
234
+ | Class | When |
235
+ |---------------------------------------------|-----------------------|
236
+ | `Postwire::Error::InvalidRequestError` | 400, 401, 422 |
237
+ | `Postwire::Error::NotFoundError` | 404 |
238
+ | `Postwire::Error::RateLimitExceededError` | 429 |
239
+ | `Postwire::Error::InternalServerError` | 500 or an unparseable response |
240
+ | `Postwire::Error` | any other error status |
241
+
242
+ `InvalidRequestError`, `NotFoundError` and `RateLimitExceededError` inherit from `Postwire::Error::ClientError`, and `InternalServerError` inherits from `Postwire::Error::ServerError`. Rate limit errors also expose `retry_after`, `rate_limit_limit`, `rate_limit_remaining` and `rate_limit_reset`:
243
+
244
+ ```rb
245
+ begin
246
+ Postwire::Emails.send(params, options: { idempotency_key: key })
247
+ rescue Postwire::Error::RateLimitExceededError => e
248
+ sleep(e.retry_after || 1)
249
+ retry
250
+ rescue Postwire::Error::InvalidRequestError => e
251
+ Rails.logger.error("Rejected (#{e.code}): #{e.message}")
252
+ end
253
+ ```
254
+
255
+ ## Webhooks
256
+
257
+ ### Managing webhooks
258
+
259
+ ```rb
260
+ webhook = Postwire::Webhooks.create(
261
+ endpoint: "https://example.com/webhooks/postwire",
262
+ events: ["email.sent", "email.delivered", "email.bounced"]
263
+ )
264
+
265
+ webhook[:signing_secret] # => "whsec_..." — store this securely
266
+
267
+ Postwire::Webhooks.list
268
+ Postwire::Webhooks.get(webhook[:id])
269
+ Postwire::Webhooks.update(webhook_id: webhook[:id], status: "disabled")
270
+ Postwire::Webhooks.remove(webhook[:id])
271
+ ```
272
+
273
+ ### Verifying webhook signatures
274
+
275
+ Every webhook request is signed using HMAC-SHA256 so you can confirm it came from Postwire and wasn't tampered with. Requests carry three headers: `svix-id`, `svix-timestamp` and `svix-signature`.
276
+
277
+ Call `Postwire::Webhooks.verify` with the **raw** request body (not parsed and re-serialised JSON), those headers, and the webhook's signing secret:
278
+
279
+ ```rb
280
+ Postwire::Webhooks.verify(
281
+ payload: raw_body,
282
+ headers: {
283
+ svix_id: "msg_...",
284
+ svix_timestamp: "1731715200",
285
+ svix_signature: "v1,..."
286
+ },
287
+ webhook_secret: ENV["POSTWIRE_WEBHOOK_SECRET"]
288
+ )
289
+ # => true, or raises if verification fails
290
+ ```
291
+
292
+ `verify` returns `true` when the signature matches. Otherwise it raises a `RuntimeError` describing the problem: a missing header, a bad secret, no matching signature, or a timestamp more than 5 minutes from the current time (`Postwire::WEBHOOK_TOLERANCE_SECONDS`). The timestamp check prevents replays, so make sure your server clock is in sync.
293
+
294
+ The `svix-signature` header may hold several space-separated signatures (for example during secret rotation). Verification passes if any of them matches.
295
+
296
+ #### Rails example
297
+
298
+ ```rb
299
+ class PostwireWebhooksController < ActionController::API
300
+ def create
301
+ payload = request.raw_post
302
+
303
+ Postwire::Webhooks.verify(
304
+ payload: payload,
305
+ headers: {
306
+ svix_id: request.headers["svix-id"],
307
+ svix_timestamp: request.headers["svix-timestamp"],
308
+ svix_signature: request.headers["svix-signature"]
309
+ },
310
+ webhook_secret: Rails.application.credentials.postwire_webhook_secret
311
+ )
312
+
313
+ event = JSON.parse(payload)
314
+ # handle event["type"] ...
315
+
316
+ head :ok
317
+ rescue RuntimeError => e
318
+ Rails.logger.warn("Postwire webhook rejected: #{e.message}")
319
+ head :bad_request
320
+ end
321
+ end
322
+ ```
323
+
324
+ For a standalone Sinatra version, see [`examples/webhook_receiver.rb`](examples/webhook_receiver.rb).
325
+
326
+ # Rails and ActionMailer support
327
+
328
+ This gem can be used as an ActionMailer delivery method, add this to your `config/environments/environment.rb` file.
329
+
330
+ ```ruby
331
+ config.action_mailer.delivery_method = :postwire
332
+ ```
333
+
334
+ ### Configuration Options
335
+
336
+ You can configure the API key and host in two ways:
337
+
338
+ #### Option 1: Global Configuration (Initializer)
339
+
340
+ Create or update your mailer initializer file:
341
+
342
+ ```rb
343
+ # /config/initializers/postwire.rb
344
+ Postwire.configure do |config|
345
+ config.api_key = ENV["POSTWIRE_API_KEY"]
346
+ config.base_url = "https://send.voupe.com/api" # optional, defaults to https://send.voupe.com/api
347
+ end
348
+ ```
349
+
350
+ #### Option 2: Rails Mailer Settings
351
+
352
+ Configure directly in your environment file:
353
+
354
+ ```ruby
355
+ # config/environments/production.rb
356
+ config.action_mailer.delivery_method = :postwire
357
+ config.action_mailer.postwire_settings = {
358
+ api_key: ENV["POSTWIRE_API_KEY"],
359
+ host: "https://send.voupe.com/api" # optional
360
+ }
361
+ ```
362
+
363
+ Settings configured via `postwire_settings` take precedence over the global configuration, allowing you to use different credentials per environment.
364
+
365
+ ### Sending Emails
366
+
367
+ After configuration, you can use `deliver_now!`:
368
+
369
+ ```ruby
370
+ mailer = EmailMailer.email(self)
371
+ response = mailer.deliver_now!
372
+
373
+ puts response[:id]
374
+ # => "b8f94710-0d84-429c-925a-22d3d8f86916"
375
+ ```
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ # backwards compatibility
4
+ require "postwire/emails"
5
+
6
+ module Postwire
7
+ # Client class.
8
+ class Client
9
+ include Postwire::Emails
10
+
11
+ attr_reader :api_key
12
+
13
+ def initialize(api_key)
14
+ raise ArgumentError, "API Key is not a string" unless api_key.is_a?(String)
15
+
16
+ @api_key = api_key
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,72 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Postwire
4
+ module Emails
5
+ # Module for sent email attachments API operations
6
+ module Attachments
7
+ class << self
8
+ # Retrieve a single attachment from a sent email
9
+ #
10
+ # @param params [Hash] Parameters for retrieving the attachment
11
+ # @option params [String] :id The attachment ID (required)
12
+ # @option params [String] :email_id The email ID (required)
13
+ # @return [Hash] The attachment object
14
+ #
15
+ # @example
16
+ # Postwire::Emails::Attachments.get(
17
+ # id: "2a0c9ce0-3112-4728-976e-47ddcd16a318",
18
+ # email_id: "4ef9a417-02e9-4d39-ad75-9611e0fcc33c"
19
+ # )
20
+ def get(params = {})
21
+ attachment_id = params[:id]
22
+ email_id = params[:email_id]
23
+
24
+ raise ArgumentError, ":email_id is required" if email_id.nil? || email_id.to_s.empty?
25
+ raise ArgumentError, ":id is required" if attachment_id.nil? || attachment_id.to_s.empty?
26
+
27
+ path = "emails/#{email_id}/attachments/#{attachment_id}"
28
+ Postwire::Request.new(path, {}, "get").perform
29
+ end
30
+
31
+ # List attachments from a sent email with optional pagination
32
+ #
33
+ # @param params [Hash] Parameters for listing attachments
34
+ # @option params [String] :email_id The email ID (required)
35
+ # @option params [Integer] :limit Maximum number of attachments to return (1-100)
36
+ # @option params [String] :after Cursor for pagination (newer attachments)
37
+ # @option params [String] :before Cursor for pagination (older attachments)
38
+ # @return [Hash] List of attachments with pagination info
39
+ #
40
+ # @example List all attachments
41
+ # Postwire::Emails::Attachments.list(
42
+ # email_id: "4ef9a417-02e9-4d39-ad75-9611e0fcc33c"
43
+ # )
44
+ #
45
+ # @example List with custom limit
46
+ # Postwire::Emails::Attachments.list(
47
+ # email_id: "4ef9a417-02e9-4d39-ad75-9611e0fcc33c",
48
+ # limit: 50
49
+ # )
50
+ #
51
+ # @example List with pagination
52
+ # Postwire::Emails::Attachments.list(
53
+ # email_id: "4ef9a417-02e9-4d39-ad75-9611e0fcc33c",
54
+ # limit: 20,
55
+ # after: "attachment_id_123"
56
+ # )
57
+ def list(params = {})
58
+ email_id = params[:email_id]
59
+ raise ArgumentError, ":email_id is required" if email_id.nil? || email_id.to_s.empty?
60
+
61
+ base_path = "emails/#{email_id}/attachments"
62
+
63
+ # Extract pagination parameters
64
+ pagination_params = params.slice(:limit, :after, :before)
65
+
66
+ path = Postwire::PaginationHelper.build_paginated_path(base_path, pagination_params)
67
+ Postwire::Request.new(path, {}, "get").perform
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,74 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Postwire
4
+ module Emails
5
+ module Receiving
6
+ # Module for received email attachments API operations
7
+ module Attachments
8
+ class << self
9
+ # Retrieve a single attachment from a received email
10
+ #
11
+ # @param params [Hash] Parameters for retrieving the attachment
12
+ # @option params [String] :id The attachment ID (required)
13
+ # @option params [String] :email_id The email ID (required)
14
+ # @return [Hash] The attachment object
15
+ #
16
+ # @example
17
+ # Postwire::Emails::Receiving::Attachments.get(
18
+ # id: "2a0c9ce0-3112-4728-976e-47ddcd16a318",
19
+ # email_id: "4ef9a417-02e9-4d39-ad75-9611e0fcc33c"
20
+ # )
21
+ def get(params = {})
22
+ attachment_id = params[:id]
23
+ email_id = params[:email_id]
24
+
25
+ raise ArgumentError, ":email_id is required" if email_id.nil? || email_id.to_s.empty?
26
+ raise ArgumentError, ":id is required" if attachment_id.nil? || attachment_id.to_s.empty?
27
+
28
+ path = "emails/receiving/#{email_id}/attachments/#{attachment_id}"
29
+ Postwire::Request.new(path, {}, "get").perform
30
+ end
31
+
32
+ # List attachments from a received email with optional pagination
33
+ #
34
+ # @param params [Hash] Parameters for listing attachments
35
+ # @option params [String] :email_id The email ID (required)
36
+ # @option params [Integer] :limit Maximum number of attachments to return (1-100)
37
+ # @option params [String] :after Cursor for pagination (newer attachments)
38
+ # @option params [String] :before Cursor for pagination (older attachments)
39
+ # @return [Hash] List of attachments with pagination info
40
+ #
41
+ # @example List all attachments
42
+ # Postwire::Emails::Receiving::Attachments.list(
43
+ # email_id: "4ef9a417-02e9-4d39-ad75-9611e0fcc33c"
44
+ # )
45
+ #
46
+ # @example List with custom limit
47
+ # Postwire::Emails::Receiving::Attachments.list(
48
+ # email_id: "4ef9a417-02e9-4d39-ad75-9611e0fcc33c",
49
+ # limit: 50
50
+ # )
51
+ #
52
+ # @example List with pagination
53
+ # Postwire::Emails::Receiving::Attachments.list(
54
+ # email_id: "4ef9a417-02e9-4d39-ad75-9611e0fcc33c",
55
+ # limit: 20,
56
+ # after: "attachment_id_123"
57
+ # )
58
+ def list(params = {})
59
+ email_id = params[:email_id]
60
+ raise ArgumentError, ":email_id is required" if email_id.nil? || email_id.to_s.empty?
61
+
62
+ base_path = "emails/receiving/#{email_id}/attachments"
63
+
64
+ # Extract pagination parameters
65
+ pagination_params = params.slice(:limit, :after, :before)
66
+
67
+ path = Postwire::PaginationHelper.build_paginated_path(base_path, pagination_params)
68
+ Postwire::Request.new(path, {}, "get").perform
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Postwire
4
+ module Emails
5
+ # Module for receiving emails API operations
6
+ module Receiving
7
+ class << self
8
+ # Retrieve a single received email
9
+ #
10
+ # @param email_id [String] The ID of the received email
11
+ # @return [Hash] The received email object
12
+ #
13
+ # @example
14
+ # Postwire::Emails::Receiving.get("4ef9a417-02e9-4d39-ad75-9611e0fcc33c")
15
+ def get(email_id)
16
+ raise ArgumentError, "email_id is required" if email_id.nil? || email_id.to_s.empty?
17
+
18
+ path = "emails/receiving/#{email_id}"
19
+ Postwire::Request.new(path, {}, "get").perform
20
+ end
21
+
22
+ # List received emails with optional pagination
23
+ #
24
+ # @param params [Hash] Optional parameters for pagination
25
+ # @option params [Integer] :limit Maximum number of emails to return (1-100)
26
+ # @option params [String] :after Cursor for pagination (newer emails)
27
+ # @option params [String] :before Cursor for pagination (older emails)
28
+ # @return [Hash] List of received emails with pagination info
29
+ #
30
+ # @example List all received emails
31
+ # Postwire::Emails::Receiving.list
32
+ #
33
+ # @example List with custom limit
34
+ # Postwire::Emails::Receiving.list(limit: 50)
35
+ #
36
+ # @example List with pagination
37
+ # Postwire::Emails::Receiving.list(limit: 20, after: "email_id_123")
38
+ def list(params = {})
39
+ path = Postwire::PaginationHelper.build_paginated_path("emails/receiving", params)
40
+ Postwire::Request.new(path, {}, "get").perform
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end