Module: PostmarkClient

Defined in:
lib/postmark_client.rb,
lib/postmark_client/errors.rb,
lib/postmark_client/version.rb,
lib/postmark_client/client/base.rb,
lib/postmark_client/models/email.rb,
lib/postmark_client/configuration.rb,
lib/postmark_client/resources/emails.rb,
lib/postmark_client/models/attachment.rb,
lib/postmark_client/models/email_response.rb

Overview

PostmarkClient is a Ruby gem for interacting with the Postmark transactional email API. It provides a clean, extensible interface for sending emails via Postmark.

Examples:

Basic configuration

PostmarkClient.configure do |config|
  config.api_token = ENV["POSTMARK_API_TOKEN"]
end

Sending an email

email = PostmarkClient::Email.new(
  from: "[email protected]",
  to: "[email protected]",
  subject: "Hello!",
  text_body: "Hello, World!"
)

client = PostmarkClient::Resources::Emails.new
response = client.send(email)
puts response.message_id if response.success?

Using the convenience method

client = PostmarkClient::Resources::Emails.new
response = client.send_email(
  from: "[email protected]",
  to: "[email protected]",
  subject: "Hello!",
  text_body: "Hello, World!"
)

See Also:

Defined Under Namespace

Modules: Client, Resources Classes: ApiError, Attachment, Configuration, ConfigurationError, ConnectionError, Email, EmailResponse, Error, ValidationError

Constant Summary collapse

VERSION =

Current version of the PostmarkClient gem

Returns:

  • (String)

    the semantic version number

"0.1.0"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configurationConfiguration

Get the current configuration, initializing if necessary

Returns:



55
56
57
# File 'lib/postmark_client/configuration.rb', line 55

def configuration
  @configuration ||= Configuration.new
end

Class Method Details

.configure {|Configuration| ... } ⇒ void

This method returns an undefined value.

Configure the gem using a block

Examples:

PostmarkClient.configure do |config|
  config.api_token = "your-token"
end

Yields:



68
69
70
# File 'lib/postmark_client/configuration.rb', line 68

def configure
  yield(configuration)
end

.deliver(email) ⇒ EmailResponse

Send an email using the default configuration

Examples:

PostmarkClient.deliver(
  from: "[email protected]",
  to: "[email protected]",
  subject: "Hello!",
  text_body: "Hello, World!"
)

Parameters:

  • email (Email, Hash)

    the email to send

Returns:



74
75
76
# File 'lib/postmark_client.rb', line 74

def deliver(email)
  emails.send(email.is_a?(Hash) ? Email.new(**email) : email)
end

.emails(api_token: nil) ⇒ Resources::Emails

Convenience method to create an Emails client

Examples:

response = PostmarkClient.emails.send_email(
  from: "[email protected]",
  to: "[email protected]",
  subject: "Hello!",
  text_body: "Hello, World!"
)

Parameters:

  • api_token (String, nil) (defaults to: nil)

    optional API token override

Returns:



58
59
60
# File 'lib/postmark_client.rb', line 58

def emails(api_token: nil)
  Resources::Emails.new(api_token: api_token)
end

.reset_configuration!void

This method returns an undefined value.

Reset the configuration to defaults



75
76
77
# File 'lib/postmark_client/configuration.rb', line 75

def reset_configuration!
  @configuration = Configuration.new
end