Class: PostmarkClient::Resources::Emails
- Inherits:
-
Client::Base
- Object
- Client::Base
- PostmarkClient::Resources::Emails
- Defined in:
- lib/postmark_client/resources/emails.rb
Overview
Email resource client for sending emails via the Postmark API.
Constant Summary
Constants inherited from Client::Base
Instance Attribute Summary
Attributes inherited from Client::Base
Instance Method Summary collapse
-
#send(email) ⇒ EmailResponse
Send a single email.
-
#send_batch(emails) ⇒ Array<EmailResponse>
Send a batch of emails (up to 500).
-
#send_email(from:, to:, subject:, **kwargs) ⇒ EmailResponse
Convenience method to send an email with parameters.
Methods inherited from Client::Base
Constructor Details
This class inherits a constructor from PostmarkClient::Client::Base
Instance Method Details
#send(email) ⇒ EmailResponse
Send a single email
47 48 49 50 51 52 53 |
# File 'lib/postmark_client/resources/emails.rb', line 47 def send(email) email = normalize_email(email) email.validate! response = post("/email", email.to_h) EmailResponse.new(response) end |
#send_batch(emails) ⇒ Array<EmailResponse>
Send a batch of emails (up to 500)
106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/postmark_client/resources/emails.rb', line 106 def send_batch(emails) raise ArgumentError, "Batch cannot exceed 500 emails" if emails.length > 500 normalized = emails.map { |e| normalize_email(e) } normalized.each(&:validate!) payload = normalized.map(&:to_h) responses = post("/email/batch", payload) responses.map { |r| EmailResponse.new(r) } end |
#send_email(from:, to:, subject:, **kwargs) ⇒ EmailResponse
Convenience method to send an email with parameters
81 82 83 84 85 86 87 88 89 |
# File 'lib/postmark_client/resources/emails.rb', line 81 def send_email(from:, to:, subject:, **kwargs) email = Email.new( from: from, to: to, subject: subject, **kwargs ) send(email) end |