### Install Resend Ruby Gem Source: https://github.com/resend/resend-ruby/blob/main/README.md Install the Resend Ruby SDK using RubyGems or add it to your Gemfile. ```bash gem install resend ``` ```ruby gem 'resend' ``` -------------------------------- ### Rails Mailer Example with Resend Source: https://github.com/resend/resend-ruby/blob/main/README.md Example of a Rails mailer using Resend for delivery, including defining a welcome email and delivering it. ```ruby #/app/mailers/user_mailer class UserMailer < ApplicationMailer default from: 'you@yourdomain.io' def welcome_email @user = params[:user] @url = 'http://example.com/login' mail(to: ["example2@mail.com", "example1@mail.com"], subject: 'Hello from Resend') end end # anywhere in the app u = User.new name: "derich" mailer = UserMailer.with(user: u).welcome_email mailer.deliver_now! # => {:id=>"b8f94710-0d84-429c-925a-22d3d8f86916", from: 'you@yourdomain.io', to: ["example2@mail.com", "example1@mail.com"]} ``` -------------------------------- ### Install Resend Ruby Gem Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/README.md Add the Resend gem to your project's Gemfile for installation. ```ruby gem 'resend' ``` -------------------------------- ### Send Email with ActionMailer and Resend Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/configuration.md Example of a Rails mailer class and how to send an email using Resend. ```ruby # app/mailers/user_mailer.rb class UserMailer < ApplicationMailer default from: 'notifications@example.com' def welcome_email @user = params[:user] mail(to: @user.email, subject: 'Welcome') end end # In your app UserMailer.with(user: user).welcome_email.deliver_now! ``` -------------------------------- ### Send Email with Resend Ruby SDK Source: https://github.com/resend/resend-ruby/blob/main/README.md Example of sending an email using the Resend Ruby SDK, including parameters for sender, recipient, subject, and HTML content. ```ruby require "resend" Resend.api_key = ENV["RESEND_API_KEY"] params = { "from": "onboarding@resend.dev", "to": ["delivered@resend.dev", "your@email.com"], "html": "
Hi
" }) ``` -------------------------------- ### create Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/api-reference-events-webhooks-logs.md Create a new automation with specified configuration. ```APIDOC ## create ### Description Create a new automation. ### Method ```ruby def create(params = {}) ``` ### Parameters #### Path Parameters - **params** (Hash) - Required - Automation config: `:name`, `:trigger`, `:actions` ### Response #### Success Response - **automation** (Resend::Response) - automation object with `:id` ### Request Example ```ruby response = Resend::Automations.create({ name: "Welcome Series", trigger: { event: "user.signed_up" }, actions: [] }) ``` ``` -------------------------------- ### Configure Resend SDK using a Block Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/api-reference-core.md Illustrates configuring the Resend SDK using the `configure` method or its alias `config` with a block. This is useful for setting configuration options like the API key. ```Ruby require "resend" Resend.configure do |config| config.api_key = ENV["RESEND_API_KEY"] end # or use the alias Resend.config do |config| config.api_key = ENV["RESEND_API_KEY"] end ``` -------------------------------- ### Get a Specific Received Email Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/api-reference-emails.md Retrieve a single received email by its ID. Optionally, specify `:html_format` to get the email in 'sanitized' or 'raw' HTML format. ```ruby response = Resend::Emails::Receiving.get( "4ef9a417-02e9-4d39-ad75-9611e0fcc33c", html_format: "sanitized" ) ``` -------------------------------- ### Configure Resend SDK with API Key Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/api-reference-core.md Shows how to configure the Resend SDK globally using a block, setting the API key either statically or dynamically from environment variables or application context. ```Ruby require "resend" # Static API key Resend.api_key = "re_123456" # Dynamic API key from environment Resend.api_key = -> { ENV["RESEND_API_KEY"] } # Dynamic API key from application context Resend.api_key = -> { Current.user.resend_api_key } ``` -------------------------------- ### get Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/api-reference-other-modules.md Retrieves a specific segment by its ID. ```APIDOC ## get(segment_id = "") ### Description Retrieves a specific segment by its ID. ### Method ```ruby def get(segment_id = "") ``` ### Parameters #### Path Parameters - **segment_id** (String) - Required - The segment ID ### Request Example ```ruby response = Resend::Segments.get("segment_123") ``` ### Response #### Success Response - (segment object) #### Response Example (Resend::Response object containing segment data) ``` -------------------------------- ### get Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/api-reference-other-modules.md Retrieves a specific sending domain by its ID. ```APIDOC ## get(domain_id = "") ### Description Retrieves a specific sending domain. ### Method ```ruby def get(domain_id = "") ``` ### Parameters #### Path Parameters - **domain_id** (String) - Required - The domain ID ### Request Example ```ruby response = Resend::Domains.get("domain_123") ``` ### Response #### Success Response - **domain** (Resend::Response) - domain object ``` -------------------------------- ### create Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/api-reference-other-modules.md Creates a new email preference topic. Requires a hash containing the topic's name. ```APIDOC ## create ### Description Creates a new email preference topic. ### Method Ruby Method ### Signature ```ruby def create(params = {}) ``` ### Parameters #### Path Parameters - **params** (Hash) - Required - Topic data: `:name` (required) ### Request Example ```ruby response = Resend::Topics.create({ name: "Marketing Updates" }) ``` ### Response #### Success Response - **topic object** (Resend::Response) - topic object with `:id` ### Response Example ```json { "id": "topic_abc123" } ``` ``` -------------------------------- ### get Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/api-reference-emails.md Retrieve a single attachment from a received email. ```APIDOC ## get(params = {}) ### Description Retrieve a single attachment from a received email. ### Method ```ruby def get(params = {}) ``` ### Parameters #### Path Parameters - **params** (Hash) - Required - Parameters with `:id` and `:email_id` ### Request Example ```ruby response = Resend::Emails::Receiving::Attachments.get( id: "2a0c9ce0-3112-4728-976e-47ddcd16a318", email_id: "4ef9a417-02e9-4d39-ad75-9611e0fcc33c" ) ``` ### Response #### Success Response - **attachment object** (Resend::Response) - Description ``` -------------------------------- ### create Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/api-reference-other-modules.md Creates a new API key for your Resend account. Requires a name and optionally accepts permissions. ```APIDOC ## create(params) ### Description Create a new API key. ### Method ```ruby def create(params) ``` ### Parameters #### Path Parameters - **params** (Hash) - Required - API key config: `:name` (required), `:permissions` ### Request Example ```ruby response = Resend::ApiKeys.create({ name: "Production API Key" }) api_token = response[:token] ``` ### Response #### Success Response - **token** (string) - The generated API key token. #### Response Example ```json { "token": "key_..." } ``` ``` -------------------------------- ### create Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/api-reference-other-modules.md Creates a new sending domain. Requires a hash of parameters including the domain name. ```APIDOC ## create(params) ### Description Creates a new sending domain. ### Method ```ruby def create(params) ``` ### Parameters #### Path Parameters - **params** (Hash) - Required - Domain data: `:domain` (required) ### Request Example ```ruby response = Resend::Domains.create({ domain: "mail.example.com" }) ``` ### Response #### Success Response - **domain** (Resend::Response) - domain object with `:id` ``` -------------------------------- ### get Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/api-reference-other-modules.md Retrieves a specific email preference topic by its ID. ```APIDOC ## get ### Description Retrieves a specific email preference topic by its ID. ### Method Ruby Method ### Signature ```ruby def get(topic_id = "") ``` ### Parameters #### Path Parameters - **topic_id** (String) - Required - The topic ID ### Request Example ```ruby response = Resend::Topics.get("topic_123") ``` ### Response #### Success Response - **topic object** (Resend::Response) - The topic object ### Response Example ```json { "id": "topic_123", "name": "Marketing Updates" } ``` ``` -------------------------------- ### Get Response Data Values Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/api-reference-core.md Retrieves an array of all values present in the response data. ```ruby def values end ``` -------------------------------- ### Configure API Key with Block Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/configuration.md Configure the API key using a block, often loading it from an environment variable. ```ruby require "resend" Resend.configure do |config| config.api_key = ENV["RESEND_API_KEY"] end ``` -------------------------------- ### Get Response Data Keys Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/api-reference-core.md Retrieves an array of all keys present in the response data. ```ruby response = Resend::Emails.send(params) response.keys # => [:id, :from, :to, ...] ``` -------------------------------- ### get Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/api-reference-contacts.md Retrieve a single contact import by its ID. Provides status information about the import process. ```APIDOC ## GET /contacts/imports/{id} ### Description Retrieve a single contact import by its ID. Provides status information about the import process. ### Method GET ### Endpoint /contacts/imports/{id} ### Parameters #### Path Parameters - **id** (String) - Required - The contact import ID. ### Response #### Success Response (200) - **status** (String) - The status of the import (e.g., queued, in_progress, completed, failed). ``` -------------------------------- ### Configure Resend in Rails Initializer Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/configuration.md Set up the Resend API key in a Rails initializer file. ```ruby # config/initializers/resend.rb Resend.configure do |config| config.api_key = ENV["RESEND_API_KEY"] end ``` -------------------------------- ### Configure API Key (Configure Block) Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/README.md Configure the API key using a block. This provides a clear and organized way to set configuration options, including the API key. ```ruby # Using configure block Resend.configure do |config| config.api_key = ENV["RESEND_API_KEY"] end ``` -------------------------------- ### get Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/api-reference-other-modules.md Retrieves a specific contact property using its unique ID. Returns the property object upon successful retrieval. ```APIDOC ## get ### Description Retrieve a contact property. ### Method Ruby Method ### Parameters #### Path Parameters - **contact_property_id** (String) - Required - The property ID ### Request Example ```ruby response = Resend::ContactProperties.get("b6d24b8e-af0b-4c3c-be0c-359bbd97381e") ``` ### Response #### Success Response - **property object** (Resend::Response) ``` -------------------------------- ### Get Specific Automation Run Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/api-reference-events-webhooks-logs.md Retrieves the details of a specific automation run using both the automation ID and the run ID. ```APIDOC ## Get Specific Automation Run ### Description Retrieves a specific automation run by its ID and the parent automation's ID. ### Method `Resend::Automations::Runs.get` ### Parameters #### Path Parameters - **automation_id** (String) - Required - The ID of the automation. - **run_id** (String) - Required - The ID of the specific run. ### Request Example ```ruby response = Resend::Automations::Runs.get("auto_123", "run_456") ``` ### Response #### Success Response - Returns a `Resend::Response` object containing the run details. ``` -------------------------------- ### list Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/api-reference-events-webhooks-logs.md List automations with optional pagination parameters. ```APIDOC ## list ### Description List automations with pagination. ### Method ```ruby def list(params = {}) ``` ### Parameters #### Path Parameters - **params** (Hash) - Optional - Pagination: `:limit`, `:after`, `:before` ### Response #### Success Response - **automations** (Resend::Response) - paginated list ### Request Example ```ruby response = Resend::Automations.list() ``` ``` -------------------------------- ### get Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/api-reference-emails.md Retrieve a single email by its unique ID. This is useful for checking the status or details of a previously sent or scheduled email. ```APIDOC ## get ### Description Retrieve a single email by its unique ID. This is useful for checking the status or details of a previously sent or scheduled email. ### Method GET ### Endpoint /emails/{email_id} ### Parameters #### Path Parameters - **email_id** (String) - Required - The email ID to retrieve #### Query Parameters None #### Request Body None ### Request Example ```ruby Resend::Emails.get("49a3999c-0ce1-4ea6-ab68-afcd6dc2e794") ``` ### Response #### Success Response (200) - **id** (String) - The email ID. - **from** (String) - The sender's email address. #### Response Example ```json { "id": "49a3999c-0ce1-4ea6-ab68-afcd6dc2e794", "from": "onboarding@resend.dev" } ``` ``` -------------------------------- ### List Topics with Pagination Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/api-reference-other-modules.md Retrieves a paginated list of email preference topics. Optional parameters for pagination include :limit, :after, and :before. ```ruby response = Resend::Topics.list() ``` -------------------------------- ### get(params = {}) Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/api-reference-contacts.md Retrieves a single contact by either their ID or email address. An optional audience ID can be provided to filter results. ```APIDOC ## get(params = {}) ### Description Retrieves a single contact by either their ID or email address. An optional audience ID can be provided to filter results. ### Method ```ruby def get(params = {}) ``` ### Parameters #### Path Parameters - **params** (Hash) - Required - Parameters: `:id` or `:email` (required), `:audience_id` (optional) ### Request Example ```ruby response = Resend::Contacts.get(id: "contact_123") response = Resend::Contacts.get(email: "steve@apple.com") response = Resend::Contacts.get( id: "contact_123", audience_id: "audience_456" ) ``` ### Response #### Success Response - **contact object** (object) - The retrieved contact details. ``` -------------------------------- ### Resend.api_key Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/api-reference-core.md Get or set the Resend API key globally. This can be set as a static string or a Proc for dynamic loading at request time. ```APIDOC ## Resend.api_key ### Description Get or set the Resend API key globally. This can be set as a static string or a Proc for dynamic loading at request time. ### Method Accessor (getter and setter) ### Parameters #### Setter - **api_key** (String | Proc) - Required - The API key for authentication or a Proc to dynamically retrieve it. #### Getter No parameters. ### Example ```ruby require "resend" # Static API key Resend.api_key = "re_123456" # Dynamic API key from environment Resend.api_key = -> { ENV["RESEND_API_KEY"] } # Dynamic API key from application context Resend.api_key = -> { Current.user.resend_api_key } puts Resend.api_key ``` ``` -------------------------------- ### Lazy Load API Key with Proc Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/configuration.md Use a Proc to dynamically load the API key at request time, supporting environment variables or custom logic. ```ruby require "resend" # With environment variable Resend.api_key = -> { ENV["RESEND_API_KEY"] } # With application context (Rails) Resend.api_key = -> { Current.user.resend_api_key } # Custom logic Resend.api_key = -> { if Rails.env.production? ENV["PROD_API_KEY"] else ENV["DEV_API_KEY"] end } ``` -------------------------------- ### Get Specific Automation Run Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/api-reference-events-webhooks-logs.md Use this method to retrieve details of a single automation run. Requires both the automation ID and the run ID. ```ruby response = Resend::Automations::Runs.get("auto_123", "run_456") ``` -------------------------------- ### Get a Single Attachment from a Received Email (Ruby) Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/api-reference-emails.md Use this method to retrieve a specific attachment from a received email. Requires the attachment ID and the email ID. ```ruby response = Resend::Emails::Receiving::Attachments.get( id: "2a0c9ce0-3112-4728-976e-47ddcd16a318", email_id: "4ef9a417-02e9-4d39-ad75-9611e0fcc33c" ) ``` -------------------------------- ### Get a Specific Email Attachment Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/api-reference-emails.md Retrieve a single attachment from a sent email using its ID and the email's ID. Requires both `:id` and `:email_id` parameters. ```ruby response = Resend::Emails::Attachments.get( id: "2a0c9ce0-3112-4728-976e-47ddcd16a318", email_id: "4ef9a417-02e9-4d39-ad75-9611e0fcc33c" ) ``` -------------------------------- ### Configure API Key (Static) Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/README.md Set your Resend API key directly. This is suitable for static configurations where the key is known at initialization. ```ruby # Static Resend.api_key = "re..." ``` -------------------------------- ### Create a New API Key Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/api-reference-other-modules.md Use this method to generate a new API key. The `:name` parameter is required for configuration. ```ruby response = Resend::ApiKeys.create({ name: "Production API Key" }) api_token = response[:token] ``` -------------------------------- ### Resend.configure Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/api-reference-core.md Configure the Resend SDK using a block. The block receives the configuration object itself as an argument. ```APIDOC ## Resend.configure ### Description Configure the Resend SDK using a block. The block receives the configuration object itself as an argument. ### Method `configure` (or alias `config`) ### Parameters #### Block Parameter - **config** (Block) - Optional - A block that receives the configuration object (`self`) for setting options like `api_key`. ### Return Type Boolean (always true) ### Example ```ruby require "resend" Resend.configure do |config| config.api_key = ENV["RESEND_API_KEY"] end # or use the alias Resend.config do |config| config.api_key = ENV["RESEND_API_KEY"] end ``` ``` -------------------------------- ### List Logs with Pagination Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/api-reference-events-webhooks-logs.md Fetches a paginated list of logs. Optional parameters include `:limit`, `:after`, and `:before` for controlling the results. ```ruby response = Resend::Logs.list() ``` -------------------------------- ### create(params) Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/api-reference-contacts.md Creates a new contact with the provided details. Requires an email address and optionally accepts first name, last name, and properties. ```APIDOC ## create(params) ### Description Creates a new contact with the provided details. Requires an email address and optionally accepts first name, last name, and properties. ### Method ```ruby def create(params) ``` ### Parameters #### Path Parameters - **params** (Hash) - Required - Contact data: `:email` (required), `:first_name`, `:last_name`, `:properties`, `:audience_id` (deprecated, use segment_id) ### Request Example ```ruby response = Resend::Contacts.create({ email: "steve@apple.com", first_name: "Steve", last_name: "Jobs" }) contact_id = response[:id] ``` ### Response #### Success Response - **id** (string) - The ID of the created contact. ``` -------------------------------- ### API Key Parameters for Resend Ruby SDK Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/types.md Outlines the parameters for managing API keys in the Resend Ruby SDK. An API key name is required, and permissions can be optionally specified. ```ruby { name: String, # API key name (required) permissions: Array[String], # Permission scopes (optional) } ``` -------------------------------- ### Handle Invalid Request Errors in Ruby Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/errors.md Catch `Resend::Error::InvalidRequestError` to handle issues like malformed requests or validation errors. This example shows how to rescue this specific error and print its message. ```ruby begin Resend::Emails.send({ from: "invalid-email", # Invalid email format to: ["user@example.com"] }) rescue Resend::Error::InvalidRequestError => e puts "Validation error: #{e.message}" end ``` -------------------------------- ### Resend::Client.new Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/api-reference-core.md Create a new Resend client instance with a specific API key for making authenticated API calls. ```APIDOC ## Resend::Client.new ### Description Create a new Resend client instance with a specific API key for making authenticated API calls. ### Method `initialize` ### Parameters #### Path Parameters - **api_key** (String) - Required - The API key for authentication. ### Return Type `Resend::Client` instance ### Throws `ArgumentError` if `api_key` is not a String. ### Example ```ruby client = Resend::Client.new("re_123456") # Client includes Resend::Emails module response = client.send({ from: "sender@example.com", to: ["recipient@example.com"], subject: "Hello", html: "Hi
" }) ``` ``` -------------------------------- ### Create a New Topic Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/api-reference-other-modules.md Use this method to create a new email preference topic. Requires a hash containing the topic's name. ```ruby response = Resend::Topics.create({ name: "Marketing Updates" }) ``` -------------------------------- ### Resend::Error Base Class Example Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/errors.md Demonstrates how to rescue the base Resend::Error and access its attributes like message, code, and headers. This is useful for general error handling of any Resend API call. ```ruby begin Resend::Emails.send({}) rescue Resend::Error => e puts "Error: #{e.message}" puts "Code: #{e.code}" puts "Headers: #{e.headers}" end ``` -------------------------------- ### Resend Ruby Contact Property Parameters Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/types.md Parameters for Resend::ContactProperties operations like create, update, get, and remove. Requires a key and type, with optional fallback value and ID for specific operations. ```ruby { key: String, # Property key name (required, max 50 chars, alphanumeric + underscore) type: String, # 'string' or 'number' (required) fallback_value: String | Integer, # Default value when not set (optional, must match type) id: String, # Property ID (used with get/update/remove) } ``` -------------------------------- ### create Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/api-reference-other-modules.md Creates a new segment for audience targeting. Requires a hash containing at least the segment's name. ```APIDOC ## create(params) ### Description Creates a new segment for audience targeting. Requires a hash containing at least the segment's name. ### Method ```ruby def create(params) ``` ### Parameters #### Path Parameters - **params** (Hash) - Required - Segment data: `:name` (required) ### Request Example ```ruby response = Resend::Segments.create({ name: "Active Users" }) ``` ### Response #### Success Response - **id** (String) - The ID of the created segment. #### Response Example (Resend::Response object containing segment data) ``` -------------------------------- ### Rails Integration with ActionMailer Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/OVERVIEW.md The Resend Ruby SDK seamlessly integrates with Rails ActionMailer. This example shows how to configure ActionMailer to use Resend as the delivery method and send emails using standard Rails mailers. ```APIDOC ## Rails Integration The SDK integrates with Rails ActionMailer: ```ruby # config/environments/production.rb config.action_mailer.delivery_method = :resend # Then use Rails mailers normally UserMailer.with(user: user).welcome_email.deliver_now! ``` All ActionMailer headers, attachments, and features are supported. ``` -------------------------------- ### Access Client Instance API Key Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/api-reference-core.md Shows how to access the API key associated with a specific Resend client instance using the `api_key` reader method. ```Ruby client = Resend::Client.new("re_123456") puts client.api_key ``` -------------------------------- ### Create an Automation Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/api-reference-events-webhooks-logs.md Use this method to create a new automated email workflow. It requires a name, trigger event, and a list of actions. ```ruby response = Resend::Automations.create({ name: "Welcome Series", trigger: { event: "user.signed_up" }, actions: [...] }) ``` -------------------------------- ### Handle Argument Errors in Ruby Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/errors.md Catch `ArgumentError` for issues related to missing or invalid parameters passed to SDK methods. This example demonstrates rescuing `ArgumentError` when calling `Resend::Contacts.get` without required parameters. ```ruby begin Resend::Contacts.get({}) # Missing id or email rescue ArgumentError => e puts "Invalid arguments: #{e.message}" end ``` -------------------------------- ### Handle Rate Limit Exceeded Errors with Retry in Ruby Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/errors.md Implement retry logic for `Resend::Error::RateLimitExceededError` to automatically handle rate limiting. The example includes a maximum retry count and uses `e.retry_after` to determine the sleep duration. ```ruby max_retries = 3 retries = 0 begin Resend::Emails.send(params) rescue Resend::Error::RateLimitExceededError => e if retries < max_retries && e.retry_after sleep(e.retry_after) retries += 1 retry else raise end end ``` -------------------------------- ### Set Dynamic API Key with Proc Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/OVERVIEW.md Configure the Resend API key dynamically using a Proc, allowing it to be fetched from an environment variable at runtime. ```ruby Resend.api_key = -> { ENV["RESEND_API_KEY"] } ``` -------------------------------- ### Create a New Broadcast (Draft) Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/api-reference-events-webhooks-logs.md Use this to create a new broadcast as a draft. Set `send: true` to send immediately or use `scheduled_at` for scheduled delivery. `:audience_id` is deprecated. ```ruby response = Resend::Broadcasts.create({ segment_id: "seg_123", from: "sender@example.com", to: "[email]", subject: "Broadcast Title", html: "Broadcast content
" }) ``` ```ruby # Send immediately response = Resend::Broadcasts.create({ segment_id: "seg_123", from: "sender@example.com", to: "[email]", subject: "Broadcast Title", html: "Broadcast content
", send: true }) ``` -------------------------------- ### Create a New Webhook Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/api-reference-events-webhooks-logs.md Creates a new webhook subscription. Requires an `:endpoint` URL and a list of `:events` to subscribe to. The response includes the webhook's ID and signing secret. ```ruby response = Resend::Webhooks.create({ endpoint: "https://webhook.example.com/handler", events: ["email.sent", "email.delivered", "email.bounced"] }) webhook_secret = response[:signing_secret] ``` -------------------------------- ### Build Paginated API Path Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/api-reference-core.md Constructs an API path with pagination parameters like limit, after, and before. Useful for fetching data in chunks. ```ruby path = Resend::PaginationHelper.build_paginated_path("contacts", { limit: 10, after: "cursor_123" }) # => "contacts?limit=10&after=cursor_123" ``` -------------------------------- ### list Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/api-reference-other-modules.md Lists email preference topics with optional pagination parameters. ```APIDOC ## list ### Description Lists email preference topics with pagination. ### Method Ruby Method ### Signature ```ruby def list(params = {}) ``` ### Parameters #### Path Parameters - **params** (Hash) - Optional - Pagination: `:limit`, `:after`, `:before` ### Request Example ```ruby response = Resend::Topics.list() ``` ### Response #### Success Response - **paginated list** (Resend::Response) - A paginated list of topics ### Response Example ```json { "data": [ { "id": "topic_abc123", "name": "Marketing Updates" } ], "has_more": true } ``` ``` -------------------------------- ### Create a New Domain Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/api-reference-other-modules.md Use this method to create a new sending domain. Requires a hash containing the domain name. ```ruby response = Resend::Domains.create({ domain: "mail.example.com" }) ``` -------------------------------- ### Create a New Contact Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/api-reference-contacts.md Use this method to add a new contact to your audience. Ensure you provide at least the email address. ```Ruby response = Resend::Contacts.create({ email: "steve@apple.com", first_name: "Steve", last_name: "Jobs" }) contact_id = response[:id] ``` -------------------------------- ### Resend::Response#initialize Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/api-reference-core.md Initializes a new Response object with response data and headers. This object allows for hash-like access to the data and provides access to the response headers. ```APIDOC ## Resend::Response#initialize ### Description Initializes a new Response object with response data and headers. This object allows for hash-like access to the data and provides access to the response headers. ### Signature ```ruby def initialize(data, headers) ``` ### Parameters #### Parameters - **data** (Hash) - Required - The response data - **headers** (Hash) - Optional - The response headers ### Return Type `Resend::Response` instance ### Notes - Response object is Enumerable and supports hash-like access - Maintains backwards compatibility with code expecting Hash responses - Provides access to HTTP headers via the `#headers` method ### Example ```ruby response = Resend::Response.new({id: "123", from: "sender@example.com"}, {"x-ratelimit-remaining" => "50"}) # Hash-like access response[:id] response["from"] response.keys response.values # Header access response.headers["x-ratelimit-remaining"] ``` ``` -------------------------------- ### list Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/api-reference-other-modules.md Lists sending domains with optional pagination parameters. ```APIDOC ## list(params = {}) ### Description Lists sending domains with pagination. ### Method ```ruby def list(params = {}) ``` ### Parameters #### Query Parameters - **params** (Hash) - Optional - Pagination: `:limit`, `:after`, `:before` ### Request Example ```ruby response = Resend::Domains.list() ``` ### Response #### Success Response - **domains** (Resend::Response) - paginated list ``` -------------------------------- ### List API Keys Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/api-reference-other-modules.md Retrieve a paginated list of your existing API keys. Optional parameters can be used for pagination. ```ruby response = Resend::ApiKeys.list() ``` -------------------------------- ### List Automations Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/api-reference-events-webhooks-logs.md Retrieves a paginated list of all your automations. Optional parameters can be provided for controlling the pagination. ```ruby response = Resend::Automations.list() ``` -------------------------------- ### List Webhooks with Pagination Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/api-reference-events-webhooks-logs.md Retrieves a paginated list of existing webhooks. Supports pagination parameters like `:limit`, `:after`, and `:before`. ```ruby response = Resend::Webhooks.list(limit: 20) ``` -------------------------------- ### Create a New Email Template with Resend Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/api-reference-other-modules.md Use the `Resend::Templates.create` method to define and create a new email template. Requires template name, subject, and HTML or text content. ```ruby response = Resend::Templates.create({ name: "Welcome Email", subject: "Welcome {{name}}", html: "Hi
" }) ``` -------------------------------- ### List Broadcasts with Pagination Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/api-reference-events-webhooks-logs.md Use this to retrieve a paginated list of broadcasts. Optional parameters include `:limit`, `:after`, and `:before` for controlling the results. ```ruby response = Resend::Broadcasts.list() ``` -------------------------------- ### Send a Simple Email Source: https://github.com/resend/resend-ruby/blob/main/_autodocs/OVERVIEW.md Use this snippet to send a basic email. Ensure your RESEND_API_KEY environment variable is set. ```ruby require "resend" Resend.api_key = ENV["RESEND_API_KEY"] response = Resend::Emails.send({ from: "onboarding@example.com", to: ["user@example.com"], subject: "Welcome", html: "