Sha256: 8a08864124876376309309a291d97b738f585a42d29a01a426a026b9cc40dbd3

Contents?: true

Size: 1.15 KB

Versions: 8

Compression:

Stored size: 1.15 KB

Contents

require 'createsend'
require 'json'

module CreateSend
  # Represents an email template and associated functionality.
  class Template
    attr_reader :template_id

    def initialize(template_id)
      @template_id = template_id
    end

    # Creates a new email template.
    def self.create(client_id, name, html_url, zip_url)
      options = { :body => { 
        :Name => name,
        :HtmlPageURL => html_url,
        :ZipFileURL => zip_url }.to_json }
      response = CreateSend.post "/templates/#{client_id}.json", options
      response.parsed_response
    end

    # Gets the details of this email template.
    def details
      response = CreateSend.get "/templates/#{template_id}.json", {}
      Hashie::Mash.new(response)
    end

    # Updates this email template.
    def update(name, html_url, zip_url)
      options = { :body => { 
        :Name => name,
        :HtmlPageURL => html_url,
        :ZipFileURL => zip_url }.to_json }
      response = CreateSend.put "/templates/#{template_id}.json", options
    end

    # Deletes this email template.
    def delete
      response = CreateSend.delete "/templates/#{template_id}.json", {}
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
createsend-1.1.1 lib/createsend/template.rb
createsend-1.1.0 lib/createsend/template.rb
createsend-1.0.4 lib/createsend/template.rb
createsend-1.0.3 lib/createsend/template.rb
createsend-1.0.2 lib/createsend/template.rb
createsend-1.0.1 lib/createsend/template.rb
createsend-1.0.0 lib/createsend/template.rb
createsend-0.3.2 lib/createsend/template.rb