diff --git a/lib/resend/batch.rb b/lib/resend/batch.rb index 554e2e8..addfdcf 100644 --- a/lib/resend/batch.rb +++ b/lib/resend/batch.rb @@ -6,7 +6,12 @@ module Batch class << self # Send a batch of emails # - # @param params [Array] Array of email parameters (max 100 emails) + # Each email in +params+ accepts the same fields as {Resend::Emails.send}, + # including +tags+ per email. + # + # @param params [Array] Array of email parameters (max 100 emails). + # Each hash accepts the same fields as {Resend::Emails.send}, including: + # - +tags+ [Array] Key/value tags, e.g. [{ name: "category", value: "welcome" }] # @param options [Hash] Additional options for the request # @option options [String] :idempotency_key Optional idempotency key # @option options [String] :batch_validation Batch validation mode: "strict" (default) or "permissive" diff --git a/spec/batch_spec.rb b/spec/batch_spec.rb index 9312499..cd1be7b 100644 --- a/spec/batch_spec.rb +++ b/spec/batch_spec.rb @@ -266,6 +266,45 @@ expect(result[:errors][0][:message]).to include("valid email address") end + it "passes tags in the request body" do + resp = { + "data": [ + { "id": "ae2014de-c168-4c61-8267-70d2662a1ce1" } + ] + } + + params = [ + { + from: "from@e.io", + to: ["email1@email.com"], + subject: "Tagged email", + html: "

Hello

", + tags: [ + { name: "category", value: "welcome" } + ] + } + ] + + allow(resp).to receive(:body).and_return(resp) + allow(HTTParty).to receive(:send).and_return(resp) + + Resend::Batch.send(params) + + expect(HTTParty).to have_received(:send).with( + :post, + "#{Resend::Request::BASE_URL}emails/batch", + { + headers: { + "Content-Type" => "application/json", + "Accept" => "application/json", + "Authorization" => "Bearer re_123", + "User-Agent" => "resend-ruby:#{Resend::VERSION}", + }, + body: params.to_json + } + ) + end + it "sends batch email with templates" do resp = { "data": [