Module: Resend::Contacts
- Defined in:
- lib/resend/contacts.rb,
lib/resend/contacts/topics.rb,
lib/resend/contacts/imports.rb,
lib/resend/contacts/segments.rb
Overview
Contacts api wrapper
Defined Under Namespace
Modules: Imports, Segments, Topics
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
68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/resend/contacts.rb', line 68 def list(params = {}) path = if params[:audience_id] audience_id = params[:audience_id] Resend::PaginationHelper.build_paginated_path("audiences/#{audience_id}/contacts", params.except(:audience_id)) elsif params[:segment_id] segment_id = params[:segment_id] Resend::PaginationHelper.build_paginated_path("segments/#{segment_id}/contacts", params.except(:segment_id)) else Resend::PaginationHelper.build_paginated_path("contacts", params) end Resend::Request.new(path, {}, "get").perform end |
.remove(params = {}) ⇒ Object
Remove a contact
https://resend.com/docs/api-reference/contacts/delete-contact
97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/resend/contacts.rb', line 97 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
https://resend.com/docs/api-reference/contacts/update-contact
115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/resend/contacts.rb', line 115 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 |