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

Retrieves a contact from an audience

resend.com/docs/api-reference/contacts/get-contact

Parameters:

  • audience_id (String)

    the audience id

  • id (String)

    either the contact id or contact’s email



20
21
22
23
# File 'lib/resend/contacts.rb', line 20

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



30
31
32
33
# File 'lib/resend/contacts.rb', line 30

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



42
43
44
45
# File 'lib/resend/contacts.rb', line 42

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)


52
53
54
55
56
57
# File 'lib/resend/contacts.rb', line 52

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