Module: Posthaste

Defined in:
lib/posthaste/errors.rb,
lib/posthaste/result.rb,
lib/posthaste/railtie.rb,
lib/posthaste/version.rb,
lib/posthaste/redaction.rb,
lib/posthaste/http_client.rb,
lib/posthaste/actionmailer.rb,
lib/posthaste/message_mapper.rb,
lib/posthaste/delivery_method.rb

Defined Under Namespace

Modules: ErrorMapping, MessageExtensions, Redaction Classes: APIStatusError, AttachmentError, AuthenticationError, ConfigurationError, ConflictError, ConnectionError, ContentBlockedError, DeliveryMethod, DomainNotVerifiedError, Error, HttpClient, InvalidRequestError, MappingError, MappingWarning, MessageMapper, NetHttpTransport, NotFoundError, PermissionDeniedError, QuotaExhausted, Railtie, RateLimited, Response, Result, ScheduleError, ServerError, StreamError, SuppressedError, SuppressionInfo, TemplateError, TimeoutError, UnprocessableError, UnsupportedHeaderError

Constant Summary collapse

KNOWN_ERROR_TYPES =

Every error.type the API emits, plus the ones this gem synthesises.

Kept as data rather than as a set of classes so a caller can check whether a type is one this version knows about. An unrecognised type is NOT a bug: the API is allowed to add refusal reasons, and one that arrives here unknown becomes the class its HTTP status implies instead of being mistaken for a documented one.

%w[
  unauthorized unauthenticated forbidden csrf_failed email_unverified
  invalid_request not_found conflict address_taken
  batch_too_large fanout_too_large unknown_template invalid_template
  template_in_use unknown_stream reserved_slug slug_taken invalid_address
  domain_not_found domain_not_verified suppressed
  rate_limited daily_limit_reached monthly_limit_reached platform_paused
  bulk_send_refused
  attachments_too_many attachments_too_large attachment_type_blocked
  attachment_invalid
  schedule_too_far not_scheduled
  content_blocked
  domain_limit_reached domain_in_use token_required
  cloudflare_token_invalid cloudflare_zone_not_found cloudflare_write_failed
  suppression_protected suppression_platform suppression_hard_bounce
  not_configured provider_error already_subscribed
  internal
  unknown_error connection_error timeout
  configuration_error unmappable_message
].freeze
VERSION =

Kept in step with the gemspec, which reads it from here rather than restating it — a version stated twice is a version that disagrees with itself the first time somebody bumps one of them.

'0.1.0'
DEFAULT_BASE_URL =

The default host. Override it with base_url: when self-hosting.

'https://api.posthastemail.dev'

Class Method Summary collapse

Class Method Details

.extend_mail_message!(klass = ::Mail::Message) ⇒ Object

Add Mail::Message#posthaste_result, once Mail is loaded.



48
49
50
51
52
53
# File 'lib/posthaste/actionmailer.rb', line 48

def self.extend_mail_message!(klass = ::Mail::Message)
  return false if klass.include?(MessageExtensions)

  klass.include(MessageExtensions)
  true
end

.register_delivery_method!(base = ::ActionMailer::Base) ⇒ Boolean

Register :posthaste with ActionMailer.

Idempotent, and it has to be: add_delivery_method resets posthaste_settings to the default options, so calling it a second time after the application has configured its key would silently blank the key. The guard is respond_to?, because that accessor is exactly what add_delivery_method defines.

Returns:

  • (Boolean)

    true if this call did the registering



40
41
42
43
44
45
# File 'lib/posthaste/actionmailer.rb', line 40

def self.register_delivery_method!(base = ::ActionMailer::Base)
  return false if base.respond_to?(:posthaste_settings)

  base.add_delivery_method(:posthaste, DeliveryMethod)
  true
end