Skip to content

Instantly share code, notes, and snippets.

@pablojimeno
Forked from apeckham/gibbon.rb
Created January 10, 2018 12:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pablojimeno/c1eb40d74e86e7e3ceb872932dfbfcdc to your computer and use it in GitHub Desktop.
Save pablojimeno/c1eb40d74e86e7e3ceb872932dfbfcdc to your computer and use it in GitHub Desktop.
Create and send a Mailchimp campaign with gibbon, using content sections from ActionView templates
gibbon = Gibbon::API.new
view = ActionView::Base.new('app/views/', {instance_variable_for_templates: 5324}, ActionController::Base.new)
campaign = gibbon.campaigns.create(
type: "regular",
options: {
list_id: 'xxxy',
from_email: 'you@example.com',
from_name: 'Your From',
subject: "the subject",
template_id: 128128398
},
content: {
sections: {
template_html: view.render(partial: 'mailchimp/template_html'),
footer_or_whatever: view.render(partial: 'mailchimp/footer_or_whatever')
}
}
)
gibbon.campaigns.send(cid: campaign['id'])
<!-- create a 'code your own' template -->
<!-- drag & drop / WYSIWYG templates made by mailchimp don't support adding mc:edit blocks -->
<!-- the WYSIWYG editor can only be used by campaigns created through the mailchimp.com GUI, not via the API -->
<html>
<div mc:edit='template_html'>placeholder text</div>
<div mc:edit='footer_or_whatever'>placeholder text that only appears when footer_or_whatever is not provided (or in preview mode) </div>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment