Module: Resend::Contacts
- Defined in:
- lib/resend/contacts.rb,
lib/resend/contacts/topics.rb,
lib/resend/contacts/segments.rb
Overview
Contacts api wrapper
Defined Under Namespace
Class Method Summary collapse
- .create(params) ⇒ Object
-
.get(params = {}) ⇒ Object
Retrieves a contact.
-
.list(params = {}) ⇒ Object
List contacts.
-
.remove(params = {}) ⇒ Object
Remove a contact.
-
.update(params) ⇒ Object
Update a contact.
Class Method Details
.create(params) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/resend/contacts.rb', line 8 def create(params) if params[:audience_id] path = "audiences/#{params[:audience_id]}/contacts" # Audience-scoped contacts don't support properties payload = params.reject { |key, _| key == :properties } else path = "contacts" payload = params end Resend::Request.new(path, payload, "post").perform end |
.get(params = {}) ⇒ Object
Retrieves a contact
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/resend/contacts.rb', line 34 def get(params = {}) raise ArgumentError, "Missing `id` or `email` field" if params[:id].nil? && params[:email].nil? audience_id = params[:audience_id] contact_id = params[:id] || params[:email] path = if audience_id "audiences/#{audience_id}/contacts/#{contact_id}" else "contacts/#{contact_id}" end Resend::Request.new(path, {}, "get").perform end |
.list(params = {}) ⇒ Object
List contacts
65 66 67 68 69 70 71 72 73 |
# File 'lib/resend/contacts.rb', line 65 def list(params = {}) audience_id = params[:audience_id] path = if audience_id Resend::PaginationHelper.build_paginated_path("audiences/#{audience_id}/contacts", params) else Resend::PaginationHelper.build_paginated_path("contacts", params) end Resend::Request.new(path, {}, "get").perform end |
.remove(params = {}) ⇒ Object
Remove a contact
89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/resend/contacts.rb', line 89 def remove(params = {}) raise ArgumentError, "Missing `id` or `email` field" if params[:id].nil? && params[:email].nil? audience_id = params[:audience_id] contact_id = params[:id] || params[:email] path = if audience_id "audiences/#{audience_id}/contacts/#{contact_id}" else "contacts/#{contact_id}" end Resend::Request.new(path, {}, "delete").perform end |
.update(params) ⇒ Object
Update a contact
107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/resend/contacts.rb', line 107 def update(params) raise ArgumentError, "Missing `id` or `email` field" if params[:id].nil? && params[:email].nil? contact_id = params[:id] || params[:email] if params[:audience_id] path = "audiences/#{params[:audience_id]}/contacts/#{contact_id}" # Audience-scoped contacts don't support properties payload = params.reject { |key, _| key == :properties } else path = "contacts/#{contact_id}" payload = params end Resend::Request.new(path, payload, "patch").perform end |