Skip to content

Instantly share code, notes, and snippets.

@strukturedkaos
Created June 25, 2014 20:48
Show Gist options
  • Save strukturedkaos/a218acb56f4759ca7bb2 to your computer and use it in GitHub Desktop.
Save strukturedkaos/a218acb56f4759ca7bb2 to your computer and use it in GitHub Desktop.
Angular Mailchimp Controller's POST request to Mailchimp API
// Send subscriber data to MailChimp
MailChimpSubscription.save(
// Successfully sent data to MailChimp.
function (response) {
// Define message containers.
mailchimp.successMessage = '';
mailchimp.errorMessage = '';
// Store the result from MailChimp
mailchimp.result = response.result;
// Mailchimp returned an error.
if (response.result === 'error') {
if (response.msg) {
// Remove error numbers, if any.
var errorMessageParts = response.msg.split(' - ');
if (errorMessageParts.length > 1)
errorMessageParts.shift(); // Remove the error number
mailchimp.errorMessage = errorMessageParts.join(' ');
} else {
mailchimp.errorMessage = 'Sorry! An unknown error occured.';
}
}
// MailChimp returns a success.
else if (response.result === 'success') {
mailchimp.successMessage = "Thanks for subscribing! Please confirm the email you receive to complete the process.";
}
},
// Error sending data to MailChimp
function (error) {
$log.error('MailChimp Error: %o', error);
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment