wakio 0.1.0 → 0.1.1

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: 2b058707e5d5a45ba09f1ab08a918b13cd24421ff6090c957ac42e8f7ef2ddb3
4
- data.tar.gz: 90c415eb9823dfca80567242d5402d3d9a61cc3636d6b8e12ab768463c1851c0
3
+ metadata.gz: 0b10c47e80d5a8cdb7eb94e86babdcf24674b8b0563313a4b12459cbcc2ddf74
4
+ data.tar.gz: 8053fbb8ebe24f105513e04e8856ea18614b86ab25b2b34e89ad8fdadabe2462
5
5
  SHA512:
6
- metadata.gz: c011065c01a89cdffab9684e0aa88a175f657e601246c0780aa193f85b2cf900b541b1709d20e454f011b7f5876243e11cb55c29354c961e3ca628abca5baa22
7
- data.tar.gz: f53a850d624b30ccfb86a0525b88de4946d1534bd7cb2d053f983d1faf66cd70256045d4d42d4f7944272cce1479606e57235120263b04d1ecdba273b0cf1bc8
6
+ metadata.gz: d45c860e93f1c69bb3620f11dbb68179c3142bb63a8bb418e39b1c016c14d6bdba14971e3f5f3582a054dbb514f5b03c96dd8b22eeef77248058f99e8ed8ff5f
7
+ data.tar.gz: 8c6f7c5cb040922d14a6b2828775bdfe6ad103cf7c1bdf07123b2722e81bd78f281caae194a803fe0852d2b3bee3ed3fdd182124918c103a23447828f1630ddc
data/README.md CHANGED
@@ -14,6 +14,8 @@ config.action_mailer.wakio_settings = {
14
14
  }
15
15
  ```
16
16
 
17
+ `open_timeout` and `read_timeout` are optional, in seconds, and default to 5 and 10. A timeout raises `Net::OpenTimeout` or `Net::ReadTimeout`, not `Wakio::DeliveryError`. A read timeout can come after Wakio accepted the send, so a retry without an idempotency key (below) may send twice.
18
+
17
19
  Every existing mailer keeps working unchanged. Its rendered subject, its HTML and text parts, and its `from` go to Wakio as they are, with no server-side template involved. A text-only mailer sends a text-only email.
18
20
 
19
21
  The `from` domain must be one of your account's sendable sending domains, matched exactly: `hello@acme.com` needs `acme.com` itself verified, and a verified `mail.acme.com` does not cover it. A mismatch is refused with `422 no_verified_sending_domain`. A mailer with no `from` goes out as `no-reply@` your first sendable domain. `GET /v1/sending-identities` reports which domains are currently sendable.
@@ -22,6 +24,8 @@ The `from` domain must be one of your account's sendable sending domains, matche
22
24
 
23
25
  **A suppressed address raises.** Wakio suppresses addresses that have hard-bounced or complained, and accepts a send to one rather than refusing it. The response names each recipient's status, and `deliver!` raises `Wakio::Suppressed` (a `Wakio::DeliveryError`) when every recipient was suppressed, so a one-recipient mailer to a suppressed address fails loudly instead of reporting success. Retrying cannot help, so handle it rather than letting a job backend retry it: `rescue_from Wakio::Suppressed` in your mailer also catches it under `deliver_later`. A send where only some recipients were suppressed returns normally; check the returned response's `deliveries` for which ones.
24
26
 
27
+ **A refusal a retry cannot fix raises `Wakio::Rejected`.** Every 4xx except `409 request_in_flight` raises it: a revoked key, an unverified `from` domain, an idempotency key reused with a different body. It is a `Wakio::DeliveryError` carrying `status`, `code` (the response's `error`, such as `"no_verified_sending_domain"`) and the parsed `body`, so a host app can `discard_on` it or alert instead of letting a job backend retry it for weeks. A 409 and every 5xx stay a plain `Wakio::DeliveryError`, because a retry is the right response to both.
28
+
25
29
  **Fifty recipients per request.** `to`, `cc` and `bcc` are counted together, once
26
30
  case-insensitive duplicates collapse, against Wakio's own contract limit — and the
27
31
  whole request is refused past it rather than truncated. The number mirrors SES's own
@@ -6,6 +6,17 @@ module Wakio
6
6
  DeliveryError = Class.new(StandardError)
7
7
  Suppressed = Class.new(DeliveryError)
8
8
 
9
+ class Rejected < DeliveryError
10
+ attr_reader :status, :code, :body
11
+
12
+ def initialize(message, status:, body:)
13
+ super(message)
14
+ @status = status
15
+ @body = body
16
+ @code = body["error"] if body.is_a?(Hash)
17
+ end
18
+ end
19
+
9
20
  # An ActionMailer delivery method, so a host app keeps every existing mailer
10
21
  # untouched and changes only configuration.
11
22
  class DeliveryMethod
@@ -35,8 +46,12 @@ module Wakio
35
46
  # the caller can distinguish "this is a retry of one send" from "this is a
36
47
  # deliberate repeat", because the difference is intent rather than data.
37
48
  response = post(payload_for(mail), idempotency_key: mail[IDEMPOTENCY_HEADER]&.to_s)
38
- unless response.code.to_i.between?(200, 299)
39
- raise DeliveryError, "Wakio returned #{response.code}: #{response.body}"
49
+ status = response.code.to_i
50
+ unless status.between?(200, 299)
51
+ message = "Wakio returned #{status}: #{response.body}"
52
+ raise Rejected.new(message, status: status, body: parsed(response.body)) if status.between?(400, 499) && status != 409
53
+
54
+ raise DeliveryError, message
40
55
  end
41
56
 
42
57
  # A separate check from the status above, deliberately: `accepted_any?` only ever
@@ -114,6 +129,12 @@ module Wakio
114
129
  unreadable!(response)
115
130
  end
116
131
 
132
+ def parsed(body)
133
+ JSON.parse(body.to_s)
134
+ rescue JSON::ParserError
135
+ nil
136
+ end
137
+
117
138
  def unreadable!(response)
118
139
  raise DeliveryError, "Wakio returned an unreadable body: #{response.body}"
119
140
  end
@@ -128,7 +149,8 @@ module Wakio
128
149
  request["Idempotency-Key"] = idempotency_key unless idempotency_key.nil? || idempotency_key.empty?
129
150
  request.body = payload.to_json
130
151
 
131
- Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == "https") do |http|
152
+ Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == "https",
153
+ open_timeout: settings.fetch(:open_timeout, 5), read_timeout: settings.fetch(:read_timeout, 10)) do |http|
132
154
  http.request(request)
133
155
  end
134
156
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wakio
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - WorkersLab LLC