Module: Resend::ContactProperties

Defined in:
lib/resend/contact_properties.rb

Overview

Module for managing contact properties

Contact properties allow you to store custom data about your contacts

Class Method Summary collapse

Class Method Details

.create(params) ⇒ Hash

Create a custom property for your contacts

Examples:

Create a string property

Resend::ContactProperties.create({
  key: 'company_name',
  type: 'string',
  fallback_value: 'Acme Corp'
})

Create a number property

Resend::ContactProperties.create({
  key: 'age',
  type: 'number',
  fallback_value: 0
})

Parameters:

  • params (Hash)

    Parameters for creating a contact property

Options Hash (params):

  • :key (String)

    The property key (max 50 characters, alphanumeric and underscores only) (required)

  • :type (String)

    The property type (‘string’ or ‘number’) (required)

  • :fallback_value (String, Integer)

    The default value when property is not set (must match type)

Returns:

  • (Hash)

    Response containing the created contact property



31
32
33
34
# File 'lib/resend/contact_properties.rb', line 31

def create(params)
  path = "contact-properties"
  Resend::Request.new(path, params, "post").perform
end

.get(contact_property_id = "") ⇒ Hash

Retrieve a contact property by its ID

Examples:

Get a contact property

Resend::ContactProperties.get('b6d24b8e-af0b-4c3c-be0c-359bbd97381e')

Parameters:

  • contact_property_id (String) (defaults to: "")

    The Contact Property ID

Returns:

  • (Hash)

    Response containing the contact property details



44
45
46
47
# File 'lib/resend/contact_properties.rb', line 44

def get(contact_property_id = "")
  path = "contact-properties/#{contact_property_id}"
  Resend::Request.new(path, {}, "get").perform
end

.list(params = {}) ⇒ Hash

Retrieve a list of contact properties

Examples:

List all contact properties

Resend::ContactProperties.list

List with pagination

Resend::ContactProperties.list({ limit: 10, after: 'cursor_123' })

Parameters:

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

    Optional query parameters

Options Hash (params):

  • :limit (Integer)

    Number of contact properties to retrieve (1-100, default: 20)

  • :after (String)

    The ID after which to retrieve more contact properties

  • :before (String)

    The ID before which to retrieve more contact properties

Returns:

  • (Hash)

    Response containing list of contact properties



63
64
65
66
# File 'lib/resend/contact_properties.rb', line 63

def list(params = {})
  path = Resend::PaginationHelper.build_paginated_path("contact-properties", params)
  Resend::Request.new(path, {}, "get").perform
end

.remove(contact_property_id = "") ⇒ Hash

Remove an existing contact property

Examples:

Delete a contact property

Resend::ContactProperties.remove('b6d24b8e-af0b-4c3c-be0c-359bbd97381e')

Parameters:

  • contact_property_id (String) (defaults to: "")

    The Contact Property ID

Returns:

  • (Hash)

    Response containing the deleted property ID and confirmation



100
101
102
103
# File 'lib/resend/contact_properties.rb', line 100

def remove(contact_property_id = "")
  path = "contact-properties/#{contact_property_id}"
  Resend::Request.new(path, {}, "delete").perform
end

.update(params) ⇒ Hash

Update an existing contact property

Note: The ‘key’ and ‘type’ fields cannot be changed after creation

Examples:

Update fallback value

Resend::ContactProperties.update({
  id: 'b6d24b8e-af0b-4c3c-be0c-359bbd97381e',
  fallback_value: 'Example Company'
})

Parameters:

  • params (Hash)

    Parameters for updating a contact property

Options Hash (params):

  • :id (String)

    The Contact Property ID (required)

  • :fallback_value (String, Integer)

    The default value when property is not set (must match property type)

Returns:

  • (Hash)

    Response containing the updated contact property

Raises:

  • (ArgumentError)


84
85
86
87
88
89
90
# File 'lib/resend/contact_properties.rb', line 84

def update(params)
  raise ArgumentError, "Missing `id` field" if params[:id].nil?

  contact_property_id = params[:id]
  path = "contact-properties/#{contact_property_id}"
  Resend::Request.new(path, params, "patch").perform
end