sendr_sweego

sendr_sweego — Sweego.io email backend for sendr.

Builds HTTP Request values for the Sweego send API and parses Response values returned by it.

Types

A single error detail from the Sweego API error response.

pub type ApiErrorDetail {
  ApiErrorDetail(msg: String, error_type: String)
}

Constructors

  • ApiErrorDetail(msg: String, error_type: String)

Configuration for the Sweego API backend.

pub opaque type SweegoConfig

Errors that can occur when interacting with the Sweego API.

pub type SweegoError {
  InvalidUri(String)
  InvalidResponse(statis: Int, error: json.DecodeError)
  ApiError(status: Int, details: List(ApiErrorDetail))
}

Constructors

  • InvalidUri(String)

    The base URI could not be parsed (internal error).

  • InvalidResponse(statis: Int, error: json.DecodeError)

    The API response body could not be decoded.

  • ApiError(status: Int, details: List(ApiErrorDetail))

    The API returned a non-200 status with error details.

Values

pub fn config(api_key api_key: String) -> SweegoConfig

Create a new SweegoConfig with the given API key.

pub fn dry_run(config: SweegoConfig) -> SweegoConfig

Enable dry-run mode.

When enabled, the email will not be delivered (test mode).

pub fn request(
  message message: message.Message,
  config config: SweegoConfig,
) -> Result(
  request.Request(String),
  sendr.SendrError(SweegoError),
)

Build an HTTP Request for the Sweego send API from a sendr Message.

Validates the message (from, reply-to, recipients, subject, attachments) and returns Error(SendrError(SweegoError)) on validation failure.

pub fn response(
  response response: response.Response(String),
) -> Result(String, sendr.SendrError(SweegoError))

Parse a Response from the Sweego send API.

On HTTP 200 the response body is decoded and the single swg_uid value is returned. On HTTP 422 the detail array is decoded into ApiErrorDetail entries. All other statuses are treated as generic API errors.

Search Document