Sha256: 2784361f448f83248bc6a2f56dd324c3820b4d99208f2e655432e016749a61be

Contents?: true

Size: 1.81 KB

Versions: 1

Compression:

Stored size: 1.81 KB

Contents

module Cordial
  # Wraps all interaction with the Automation Templates resource.
  # @see https://api.cordial.io/docs/v1/#!/automation_templates
  class AutomationTemplates
    include ::HTTParty
    extend Client

    # Create a new message template.
    #
    # @example Usage.
    # 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: "info@example.com",
    #     reply_email: "info@example.com",
    #     from_description: "Promotions Team"
    #   },
    #   content:{
    #     text: "<div>Hello World</div>"
    #   }
    # )
    #
    # @example successful response
    # {"success"=>true, "message"=>"record created"}
    #
    # @example failed response
    # {"error"=>true, "messages"=>"KEY must be unique"}
    #
    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
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cordial-0.1.9 lib/cordial/automation_templates.rb