Module: Resend::Contacts::Topics

Defined in:
lib/resend/contacts/topics.rb

Overview

Module for managing contact topic subscriptions

Allows you to manage which topics contacts are subscribed to

Class Method Summary collapse

Class Method Details

.list(params = {}) ⇒ Hash

Retrieve a list of topics subscriptions for a contact

Examples:

List topics by contact ID

Resend::Contacts::Topics.list(id: 'e169aa45-1ecf-4183-9955-b1499d5701d3')

List topics by contact email

Resend::Contacts::Topics.list(email: 'steve.wozniak@gmail.com')

List topics with pagination

Resend::Contacts::Topics.list(id: 'contact-id', limit: 10, after: 'cursor_123')

Parameters:

  • params (Hash) (defaults to: {})

    Parameters for listing topics

Options Hash (params):

  • :id (String)

    The Contact ID (either :id or :email must be provided)

  • :email (String)

    The Contact Email (either :id or :email must be provided)

  • :limit (Integer)

    Number of topics to retrieve (1-100)

  • :after (String)

    The ID after which to retrieve more topics

  • :before (String)

    The ID before which to retrieve more topics

Returns:

  • (Hash)

    Response containing list of topics with subscription status

Raises:

  • (ArgumentError)


29
30
31
32
33
34
35
36
37
38
# File 'lib/resend/contacts/topics.rb', line 29

def list(params = {})
  contact_identifier = params[:id] || params[:email]
  raise ArgumentError, "Either :id or :email must be provided" if contact_identifier.nil?

  pagination_params = params.slice(:limit, :after, :before)
  base_path = "contacts/#{contact_identifier}/topics"
  path = Resend::PaginationHelper.build_paginated_path(base_path, pagination_params)

  Resend::Request.new(path, {}, "get").perform
end

.update(params) ⇒ Hash

Update topic subscriptions for a contact

Examples:

Update by contact ID

Resend::Contacts::Topics.update({
  id: 'e169aa45-1ecf-4183-9955-b1499d5701d3',
  topics: [
    { id: 'b6d24b8e-af0b-4c3c-be0c-359bbd97381e', subscription: 'opt_out' },
    { id: '07d84122-7224-4881-9c31-1c048e204602', subscription: 'opt_in' }
  ]
})

Update by contact email

Resend::Contacts::Topics.update({
  email: 'steve.wozniak@gmail.com',
  topics: [
    { id: '07d84122-7224-4881-9c31-1c048e204602', subscription: 'opt_out' }
  ]
})

Parameters:

  • params (Hash)

    Parameters for updating topics

Options Hash (params):

  • :id (String)

    The Contact ID (either :id or :email must be provided)

  • :email (String)

    The Contact Email (either :id or :email must be provided)

  • :topics (Array<Hash>)

    Array of topic subscription updates Each topic hash should contain:

    • :id [String] The Topic ID (required)

    • :subscription [String] The subscription action: ‘opt_in’ or ‘opt_out’ (required)

Returns:

  • (Hash)

    Response containing the contact ID

Raises:

  • (ArgumentError)


68
69
70
71
72
73
74
75
76
# File 'lib/resend/contacts/topics.rb', line 68

def update(params)
  contact_identifier = params[:id] || params[:email]
  raise ArgumentError, "Either :id or :email must be provided" if contact_identifier.nil?

  path = "contacts/#{contact_identifier}/topics"
  body = params[:topics]

  Resend::Request.new(path, body, "patch").perform
end