Class: Cordial::AutomationTemplates

Inherits:
Object
  • Object
show all
Extended by:
Client
Includes:
HTTParty
Defined in:
lib/cordial/automation_templates.rb

Overview

Wraps all interaction with the Automation Templates resource.

Class Method Summary collapse

Methods included from Client

client

Class Method Details

.create(key:, name:, channel:, classification:, base_aggregation:, headers:, content:) ⇒ Object

Create a new message template.

Cordial::AutomationTemplates.create(

key: "promo_01_20_2018",
name: "promo_01_20_2018",
channel: "email",
classification: "promotional",
base_aggregation: "hourly",
headers:{
  subject_email: "One Day Only Sale",
  from_email: "[email protected]",
  reply_email: "[email protected]",
  from_description: "Promotions Team"
},
content:{
  text: "<div>Hello World</div>"
}

)

“message”=>“record created”

“messages”=>“KEY must be unique”

Examples:

Usage.

successful response

failed response



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/cordial/automation_templates.rb', line 34

def self.create(key:, name:, channel:, classification:, base_aggregation:, headers:, content:)
  client.post('/automationtemplates',
              body: {
                key: key,
                name: name,
                channel: channel,
                classification: classification,
                baseAggregation: base_aggregation,
                message: {
                  headers: {
                    subject: headers[:subject_email],
                    fromEmail: headers[:from_email],
                    replyEmail: headers[:reply_email],
                    fromDesc: headers[:from_description]
                  },
                  content: {
                    "text/html": content[:text]
                  }
                }
              }.to_json)
end

.send(key:, email:, **args) ⇒ Object

Sends an automation template.

Cordial::AutomationTemplates.send(

key: "promo_01_20_2018",
email: "[email protected]",
order: {
  number: "R123456789"
}

)

“message”=>“messages sent”, “messagecontacts”=>[

{"accepted"=>false, "email"=>"[email protected]", "error"=>"not-subscribed"

]}

{“success”=>true, “message”=>“messages sent”, “messagecontacts”=>

[{"accepted"=>true,
  "email"=>"[email protected]",
  "mcID"=>"h123456:1a1a1a1a1a1:787457457",
  "cID"=>"a1a1a1a1a1a1a1a1a1"}
]}

{“error”=>“‘/v1/automationtemplates//send’ is not found.”}

Examples:

Usage.

successful response with unsubscribed user

successful response with subscribed user

failed response



83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/cordial/automation_templates.rb', line 83

def self.send(key:, email:, **args)
  client.post("/automationtemplates/#{key}/send",
              body: {
                to: {
                  contact: {
                    email: email
                  },
                  extVars: {}.compact.merge(args)
                },
                identifyBy: "email"
              }.to_json)
end