Module: Resend::Contacts::Segments

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

Overview

Contact Segments api wrapper

Class Method Summary collapse

Class Method Details

.add(params) ⇒ Object

Parameters:

  • params (Hash)

    the parameters

Options Hash (params):

  • :contact_id (String)

    the contact id (either contact_id or email is required)

  • :email (String)

    the contact email (either contact_id or email is required)

  • :segment_id (String)

    the segment id (required)

Raises:

  • (ArgumentError)


37
38
39
40
41
42
43
44
# File 'lib/resend/contacts/segments.rb', line 37

def add(params)
  raise ArgumentError, "contact_id or email is required" if params[:contact_id].nil? && params[:email].nil?
  raise ArgumentError, "segment_id is required" if params[:segment_id].nil?

  identifier = params[:contact_id] || params[:email]
  path = "contacts/#{identifier}/segments/#{params[:segment_id]}"
  Resend::Request.new(path, {}, "post").perform
end

.list(params) ⇒ Object

Parameters:

  • params (Hash)

    the parameters

Options Hash (params):

  • :contact_id (String)

    the contact id (either contact_id or email is required)

  • :email (String)

    the contact email (either contact_id or email is required)

  • :limit (Integer)

    the maximum number of results to return (optional)

  • :after (String)

    the cursor for pagination (optional)

  • :before (String)

    the cursor for pagination (optional)

Raises:

  • (ArgumentError)


19
20
21
22
23
24
25
26
# File 'lib/resend/contacts/segments.rb', line 19

def list(params)
  raise ArgumentError, "contact_id or email is required" if params[:contact_id].nil? && params[:email].nil?

  identifier = params[:contact_id] || params[:email]
  base_path = "contacts/#{identifier}/segments"
  path = Resend::PaginationHelper.build_paginated_path(base_path, params)
  Resend::Request.new(path, {}, "get").perform
end

.remove(params) ⇒ Object

Parameters:

  • params (Hash)

    the parameters

Options Hash (params):

  • :contact_id (String)

    the contact id (either contact_id or email is required)

  • :email (String)

    the contact email (either contact_id or email is required)

  • :segment_id (String)

    the segment id (required)

Raises:

  • (ArgumentError)


55
56
57
58
59
60
61
62
# File 'lib/resend/contacts/segments.rb', line 55

def remove(params)
  raise ArgumentError, "contact_id or email is required" if params[:contact_id].nil? && params[:email].nil?
  raise ArgumentError, "segment_id is required" if params[:segment_id].nil?

  identifier = params[:contact_id] || params[:email]
  path = "contacts/#{identifier}/segments/#{params[:segment_id]}"
  Resend::Request.new(path, {}, "delete").perform
end