Class: Mailchimp::Templates

Inherits:
Object
  • Object
show all
Defined in:
lib/mailchimp/api.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(master) ⇒ Templates

Returns a new instance of Templates.



59
60
61
# File 'lib/mailchimp/api.rb', line 59

def initialize(master)
    @master = master
end

Instance Attribute Details

#masterObject

Returns the value of attribute master.



57
58
59
# File 'lib/mailchimp/api.rb', line 57

def master
  @master
end

Instance Method Details

#add(name, html, folder_id = nil) ⇒ Hash

Create a new user template, NOT campaign content. These templates can then be applied while creating campaigns.

Parameters:

  • name (String)

    the name for the template - names must be unique and a max of 50 bytes

  • html (String)

    a string specifying the entire template to be created. This is NOT campaign content. They are intended to utilize our template language.

  • folder_id (Int) (defaults to: nil)

    the folder to put this template in.

Returns:

  • (Hash)

    with a single element:

    • [Int] template_id the new template id, otherwise an error is thrown.


69
70
71
72
# File 'lib/mailchimp/api.rb', line 69

def add(name, html, folder_id=nil)
    _params = {:name => name, :html => html, :folder_id => folder_id}
    return @master.call 'templates/add', _params
end

#del(template_id) ⇒ Hash

Delete (deactivate) a user template

Parameters:

  • template_id (Int)

    the id of the user template to delete

Returns:

  • (Hash)

    with a single entry:

    • [Bool] complete whether the call worked. reallistically this will always be true as errors will be thrown otherwise.


78
79
80
81
# File 'lib/mailchimp/api.rb', line 78

def del(template_id)
    _params = {:template_id => template_id}
    return @master.call 'templates/del', _params
end

#info(template_id, type = 'user') ⇒ Hash

Pull details for a specific template to help support editing

Parameters:

  • template_id (Int)

    the template id - get from templates/list()

  • type (String) (defaults to: 'user')

    optional the template type to load - one of 'user', 'gallery', 'base', defaults to user.

Returns:

  • (Hash)

    info to be used when editing

    • [Hash] default_content the default content broken down into the named editable sections for the template - dependant upon template, so not documented
    • [Hash] sections the valid editable section names - dependant upon template, so not documented
    • [String] source the full source of the template as if you exported it via our template editor
    • [String] preview similar to the source, but the rendered version of the source from our popup preview


91
92
93
94
# File 'lib/mailchimp/api.rb', line 91

def info(template_id, type='user')
    _params = {:template_id => template_id, :type => type}
    return @master.call 'templates/info', _params
end

#list(types = [], filters = []) ⇒ Hash

Retrieve various templates available in the system, allowing some thing similar to our template gallery to be created.

Parameters:

  • types (Hash) (defaults to: [])

    optional the types of templates to return

    • [Boolean] user Custom templates for this user account. Defaults to true.
    • [Boolean] gallery Templates from our Gallery. Note that some templates that require extra configuration are withheld. (eg, the Etsy template). Defaults to false.
    • [Boolean] base Our "start from scratch" extremely basic templates. Defaults to false. As of the 9.0 update, "base" templates are no longer available via the API because they are now all saved Drag & Drop templates.
  • filters (Hash) (defaults to: [])

    optional options to control how inactive templates are returned, if at all

    • [String] category optional for Gallery templates only, limit to a specific template category
    • [String] folder_id user templates, limit to this folder_id
    • [Boolean] include_inactive user templates are not deleted, only set inactive. defaults to false.
    • [Boolean] inactive_only only include inactive user templates. defaults to false.
    • [Boolean] include_drag_and_drop Include templates created and saved using the new Drag & Drop editor. Note: You will not be able to edit or create new drag & drop templates via this API. This is useful only for creating a new campaign based on a drag & drop template.

Returns:

  • (Hash)

    for each type

    • [Array] user matching user templates, if requested.
      • [Int] id Id of the template
      • [String] name Name of the template
      • [String] layout General description of the layout of the template
      • [String] category The category for the template, if there is one.
      • [String] preview_image If we've generated it, the url of the preview image for the template. We do out best to keep these up to date, but Preview image urls are not guaranteed to be available
      • [String] date_created The date/time the template was created
      • [Boolean] active whether or not the template is active and available for use.
      • [Boolean] edit_source Whether or not you are able to edit the source of a template.
      • [Boolean] folder_id if it's in one, the folder id
    • [Array] gallery matching gallery templates, if requested.
      • [Int] id Id of the template
      • [String] name Name of the template
      • [String] layout General description of the layout of the template
      • [String] category The category for the template, if there is one.
      • [String] preview_image If we've generated it, the url of the preview image for the template. We do out best to keep these up to date, but Preview image urls are not guaranteed to be available
      • [String] date_created The date/time the template was created
      • [Boolean] active whether or not the template is active and available for use.
      • [Boolean] edit_source Whether or not you are able to edit the source of a template.
    • [Array] base matching base templates, if requested. (Will always be empty as of 9.0)


128
129
130
131
# File 'lib/mailchimp/api.rb', line 128

def list(types=[], filters=[])
    _params = {:types => types, :filters => filters}
    return @master.call 'templates/list', _params
end

#undel(template_id) ⇒ Hash

Undelete (reactivate) a user template

Parameters:

  • template_id (Int)

    the id of the user template to reactivate

Returns:

  • (Hash)

    with a single entry:

    • [Bool] complete whether the call worked. reallistically this will always be true as errors will be thrown otherwise.


137
138
139
140
# File 'lib/mailchimp/api.rb', line 137

def undel(template_id)
    _params = {:template_id => template_id}
    return @master.call 'templates/undel', _params
end

#update(template_id, values) ⇒ Hash

Replace the content of a user template, NOT campaign content.

Parameters:

  • template_id (Int)

    the id of the user template to update

  • values (Hash)

    the values to updates - while both are optional, at least one should be provided. Both can be updated at the same time.

    • [String] name the name for the template - names must be unique and a max of 50 bytes
    • [String] html a string specifying the entire template to be created. This is NOT campaign content. They are intended to utilize our template language.
    • [Int] folder_id the folder to put this template in - 0 or a blank values will remove it from a folder.

Returns:

  • (Hash)

    with a single entry:

    • [Bool] complete whether the call worked. reallistically this will always be true as errors will be thrown otherwise.


150
151
152
153
# File 'lib/mailchimp/api.rb', line 150

def update(template_id, values)
    _params = {:template_id => template_id, :values => values}
    return @master.call 'templates/update', _params
end