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.
-
.update(email:, attribute_list: {}, subscribe_status: nil) ⇒ Object
Update an existing 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 fail.
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.
130 131 132 133 |
# File 'lib/cordial/contacts.rb', line 130 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.
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/cordial/contacts.rb', line 104 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 |
.update(email:, attribute_list: {}, subscribe_status: nil) ⇒ Object
Update an existing contact.
If the contact doesn’t exist it will fail.
75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/cordial/contacts.rb', line 75 def self.update(email:, attribute_list: {}, subscribe_status: nil) client.put("/contacts/email:#{email}", body: { channels: { email: { address: email, subscribeStatus: subscribe_status }.compact }, forceSubscribe: subscribe_status == 'subscribed' || nil }.compact.merge(attribute_list).to_json) end |