Module: Millionsend::Contacts

Defined in:
lib/millionsend/contacts.rb

Overview

Contacts are team-global and addressable by id or by email (email wins when an update hash carries both).

Class Method Summary collapse

Class Method Details

.create(params) ⇒ Object

POST /contacts



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

def create(params)
  Millionsend::Request.new(method: :post, path: "/contacts", body: params).perform
end

.get(id_or_email) ⇒ Object

GET a single contact by id or email.



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

def get(id_or_email)
  Millionsend::Request.new(method: :get, path: member_path(id_or_email)).perform
end

.list(options = {}) ⇒ Object

GET /contacts — accepts limit:/after:/before:.



33
34
35
36
37
# File 'lib/millionsend/contacts.rb', line 33

def list(options = {})
  Millionsend::Request.new(
    method: :get, path: "/contacts", query: Millionsend::Util.list_query(options)
  ).perform
end

.remove(id_or_email) ⇒ Object

DELETE a contact by id or email.



28
29
30
# File 'lib/millionsend/contacts.rb', line 28

def remove(id_or_email)
  Millionsend::Request.new(method: :delete, path: member_path(id_or_email)).perform
end

.topics_update(id_or_email, topics) ⇒ Object

PATCH /contacts/:id_or_email/topics with a bare array of { id:, subscription: }. Mirrors resend-ruby's contacts.topics.update.



41
42
43
# File 'lib/millionsend/contacts.rb', line 41

def topics_update(id_or_email, topics)
  Millionsend::Request.new(method: :patch, path: "#{member_path(id_or_email)}/topics", body: topics).perform
end

.update(params) ⇒ Object

PATCH a contact. Addressing keys (:id, :email) are pulled out; everything else is the body. A nil value clears a field; omit a key to leave it unchanged.



21
22
23
24
25
# File 'lib/millionsend/contacts.rb', line 21

def update(params)
  key = params[:email] || params[:id]
  body = params.reject { |k, _| [:id, :email].include?(k) }
  Millionsend::Request.new(method: :patch, path: member_path(key), body: body).perform
end