Module: Resend::Contacts

Defined in:
lib/resend/contacts.rb

Overview

Contacts api wrapper

Class Method Summary collapse

Class Method Details

.create(params) ⇒ Object



8
9
10
11
# File 'lib/resend/contacts.rb', line 8

def create(params)
  path = "audiences/#{params[:audience_id]}/contacts"
  Resend::Request.new(path, params, "post").perform
end

.get(audience_id, id) ⇒ Object



14
15
16
17
# File 'lib/resend/contacts.rb', line 14

def get(audience_id, id)
  path = "audiences/#{audience_id}/contacts/#{id}"
  Resend::Request.new(path, {}, "get").perform
end

.list(audience_id) ⇒ Object

Parameters:

  • audience_id (String)

    the audience id



24
25
26
27
# File 'lib/resend/contacts.rb', line 24

def list(audience_id)
  path = "audiences/#{audience_id}/contacts"
  Resend::Request.new(path, {}, "get").perform
end

.remove(audience_id, contact_id) ⇒ Object

Remove a contact from an audience

see also: resend.com/docs/api-reference/contacts/delete-contact

Parameters:

  • audience_id (String)

    the audience id

  • contact_id (String)

    either the contact id or contact email



36
37
38
39
# File 'lib/resend/contacts.rb', line 36

def remove(audience_id, contact_id)
  path = "audiences/#{audience_id}/contacts/#{contact_id}"
  Resend::Request.new(path, {}, "delete").perform
end

.update(params) ⇒ Object

Parameters:

  • params (Hash)

    the contact params

Raises:

  • (ArgumentError)


46
47
48
49
50
51
# File 'lib/resend/contacts.rb', line 46

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

  path = "audiences/#{params[:audience_id]}/contacts/#{params[:id] || params[:email]}"
  Resend::Request.new(path, params, "patch").perform
end