anypost 1.1.0 → 1.2.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: 626219a093ae533c0f15851744e4a6eb92a42e29f793c70ac6b219c64f74f5c2
4
- data.tar.gz: 840398e4b95ff4e1bbdb6c1d5b719865304c9f0625f7e6c8f5de5b19cafbf45c
3
+ metadata.gz: d4f2beb7843c3c48b729699c36fc03b0a839fd0a05c74384f3f0700746695c5e
4
+ data.tar.gz: 0a12d2a076b57cf00fdaa55916e24d53cb159de674df098d8fe53cd26e771a81
5
5
  SHA512:
6
- metadata.gz: caab7720e980e41910338662984bc706b2d731b01d3ebf4938f3db65c534b2b6f3ddd67efb014439030d71e4092763a05557477f3a6dffd0a0b615652e2219d7
7
- data.tar.gz: db2311ea2c576f98d120fb5e5f07c6914b3e4ee0c92a3fe64b94a7e294418a19b95529576070531f7ffb03a7f2393982a1581014ea0bcce34f6120c97da3b84f
6
+ metadata.gz: 1cfad0e0062488f04315140910e1382d0f3dac314df889cb91aac7bea2d3d596c6a8fe97668444342a44336e75beaf32251fa138f18c4d8ea3fab265a6e8bc4c
7
+ data.tar.gz: 1d8915191a1be6229cd56ae3193c42c801d845c618b6e39c955b5da897634fb90a9bc88b28593c7172746017c6c3bd4b2a68d74cf8f59cef6b968ec9687c7de8
data/README.md CHANGED
@@ -62,7 +62,7 @@ client.email.send(
62
62
  )
63
63
  ```
64
64
 
65
- Attachment `content` is the raw file bytes: pass what `File.binread` returns and the SDK base64-encodes it. Do not pre-encode it. The request body is capped at 5 MB.
65
+ Attachment `content` is the raw file bytes: pass what `File.binread` returns and the SDK base64-encodes it. When the content is already base64 at rest, pass it as `content_base64` instead — that string is sent verbatim, so nothing is decoded just to be re-encoded. Set exactly one of the two. The request body is capped at 5 MB.
66
66
 
67
67
  ```ruby
68
68
  client.email.send(
@@ -4,8 +4,12 @@ module Anypost
4
4
  module Resources
5
5
  # Operations on the `/email` endpoints.
6
6
  #
7
- # Attachment `content` is the raw file bytes (e.g. from `File.binread`); the
8
- # SDK base64-encodes it for transport. Do not pre-encode it.
7
+ # Give each attachment its content exactly one of two ways: `content` for raw
8
+ # file bytes (e.g. from `File.binread`), which the SDK base64-encodes for
9
+ # transport, or `content_base64` for content that is already base64 at rest,
10
+ # which is sent through verbatim so nothing is decoded just to be re-encoded.
11
+ # Ruby has no type-level distinction between the two — both are Strings — so
12
+ # the key you choose is the signal.
9
13
  class Email < Base
10
14
  # Send a single message.
11
15
  #
@@ -35,13 +39,30 @@ module Anypost
35
39
  return message unless attachments.is_a?(Array)
36
40
 
37
41
  message = message.dup
38
- message[:attachments] = attachments.map do |attachment|
39
- content = attachment[:content]
40
- next attachment unless content.is_a?(String)
42
+ message[:attachments] = attachments.map { |attachment| encode_attachment(attachment) }
43
+ message
44
+ end
45
+
46
+ # Collapse an attachment's two possible content keys onto the single
47
+ # base64 `content` field the API takes.
48
+ def encode_attachment(attachment)
49
+ return attachment unless attachment.is_a?(Hash)
50
+
51
+ raw = attachment[:content]
52
+ encoded = attachment[:content_base64]
41
53
 
42
- attachment.merge(content: [content].pack("m0"))
54
+ if raw && encoded
55
+ raise ArgumentError,
56
+ "attachment #{attachment[:filename].inspect} sets both :content and " \
57
+ ":content_base64; set exactly one"
43
58
  end
44
- message
59
+
60
+ return attachment.except(:content_base64).merge(content: encoded) if encoded
61
+ return attachment.merge(content: [raw].pack("m0")) if raw.is_a?(String)
62
+
63
+ raise ArgumentError,
64
+ "attachment #{attachment[:filename].inspect} has no content; set :content " \
65
+ "(raw bytes) or :content_base64"
45
66
  end
46
67
  end
47
68
  end
@@ -3,5 +3,5 @@
3
3
  module Anypost
4
4
  # The single source of truth for the gem version. Bump this, tag the commit
5
5
  # `vX.Y.Z`, and push — the release workflow builds and pushes to RubyGems.
6
- VERSION = "1.1.0"
6
+ VERSION = "1.2.0"
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: anypost
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anypost
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-07-30 00:00:00.000000000 Z
11
+ date: 2026-08-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday