Class: Cordial::Contacts
- Inherits:
-
Object
- Object
- Cordial::Contacts
- Extended by:
- Client
- Includes:
- HTTParty
- Defined in:
- lib/cordial/contacts.rb
Overview
Wraps all interaction with the Contact resource.
Class Method Summary collapse
-
.create(email:, attribute_list: {}, subscribe_status: nil) ⇒ Object
Create a new contact.
-
.create_cart(email, options) ⇒ {"success"=>true}, {"error"=>true, "messages"=>"..."}
Create a new contact cart.
-
.find(email:) ⇒ Object
Find a contact.
-
.unsubscribe(email:, channel: '', mc_id: '') ⇒ Object
Unsubscribe a contact.
Methods included from Client
Class Method Details
.create(email:, attribute_list: {}, subscribe_status: nil) ⇒ Object
Create a new contact.
If the contact already exists it will be updated.
52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/cordial/contacts.rb', line 52 def self.create(email:, attribute_list: {}, subscribe_status: nil) client.post('/contacts', body: { channels: { email: { address: email, subscribeStatus: subscribe_status }.compact }, forceSubscribe: subscribe_status == 'subscribed' || nil }.compact.merge(attribute_list).to_json) end |
.create_cart(email, options) ⇒ {"success"=>true}, {"error"=>true, "messages"=>"..."}
Create a new contact cart.
107 108 109 110 |
# File 'lib/cordial/contacts.rb', line 107 def self.create_cart(email, ) cart = Cordial::Cart.new() client.post("/contacts/#{email}/cart", body: cart.to_json) end |
.find(email:) ⇒ Object
Find a contact.
37 38 39 |
# File 'lib/cordial/contacts.rb', line 37 def self.find(email:) client.get("/contacts/#{email}") end |
.unsubscribe(email:, channel: '', mc_id: '') ⇒ Object
Unsubscribe a contact.
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/cordial/contacts.rb', line 81 def self.unsubscribe(email:, channel: '', mc_id: '') if channel.empty? && mc_id.empty? url = "/contacts/#{email}" body = { channels: { email: { address: email, subscribeStatus: 'unsubscribed' } } } else url = "/contacts/#{email}/unsubscribe/#{channel}" body = { mcID: mc_id } end client.put(url, body: body.to_json) end |