RESTful API added to Dada Mail for subscribing

 
From: "Justin J" <justin@PROTECTED>
Date: August 30th 2013
Hello Everyone, 

I've added a very simple RESTful API to Dada Mail, allowing you to mimic a subscription form, without having to - you know, use the subscription form. This will hopefully be useful for people who want to add Dada Mail subscription capabilities to other types of workflows. For example, shopping cart checkout screens, with a, "check this box to subscribe to our mailing list!" With this API, you won't have to know much of anything about Dada Mail, and certainly nothing Perl - just pass a simple JSON data structure, and you'll get your results back in another, simple JSON data structure. 

I'll have docs to guide people along, as well as a working demo showing how to interact with this API using jQuery (already made) and Colorbox [0]. Here's what it currently looks like to make a subscription request, and report back to the user the results of that request - you'll notice a little bit less than half of the code is just building up the results to show: 


/* We're in control, now: */
$("body").on("submit", "#ajax_subscribe_form_demo", function(event) {
event.preventDefault();
});
$("submit", "#ajax_subscribe_form_demo").bind("keypress", function (e) {
    if (e.keyCode == 13) {
        return false;
    }
});

$('body').on('click', '#subscribe_button', function(event) {

var fields = {};
$("#subscriber_fields :input").each(function() {
fields[this.name] = this.value;
}); 

$.ajax({
url: $("#ajax_subscribe_form_demo").attr("action") + '/json/subscribe/',
type: "POST",
dataType: "json",
cache: false,
data: JSON.stringify(

list:  $("#list").val(),
email: $("#email").val(),
fields: fields
 }
),
    contentType: "application/json; charset=utf-8",
success: function(data) {
console.log('data:' + JSON.stringify(data)); 
var html = ''; 
if(data.status === 0){ 
/* Uh uh.*/
html += '<h1>Problems with your request:</h1>'; 
html += '<ul>'; 
$.each(data.errors, function(index, value) {
console.log(index + ': ' + value);
});
$.each(data.error_descriptions, function(index, value) {
html += '<li>' + value + '</li>';
});
html += '</ul>'; 
}
else { 
html += '<h1>Request Successful!:</h1>'; 
html += '<p>Your Subscription Request was Successful!</p>'; 
}

/* html += '<code>' + JSON.stringify(data) + '</code>' */

$.colorbox({
html: html,
opacity: 0.50
});
},
error: function(xhr, ajaxOptions, thrownError) {
console.log('status: ' + xhr.status);
console.log('thrownError:' + thrownError);
}
}); 
}); 


This demo will also have a complete fallback to the "normal" way of doing things, if, for some reason, JavaScript is disabled. 

This work will supersede the SOAP and REST(ish) demo scripts you can find in, dada/extras/scripts/subscribe - this'll work exactly like if you made a request from a, "regular" subscription form - I'm not duplicating any functionality, here - the subscription process now just supports multiple ways of returning its information (HTML, JSON) - so all those scripts will be removed - THIS functionality will live in the mail.cgi script, so no need to install anything new. 


-- 

Justin J: Lead Dadaist. 
url:         http://dadamailproject.com
email:    justin@PROTECTED
skype:   leaddadaist




Post: mailto:dadadev@PROTECTED

Unsubscribe »

  • This mailing list is a public mailing list - anyone may join or leave, at any time.
  • This mailing list is a group discussion list (unmoderated)
  • Start a new thread, email: dadadev@dadamailproject.com

This is the developer discussion mailing list for Dada Mail.

If you are just looking for support Dada Mail, consult the message boards at:

https://forum.dadamailproject.com

Documentation for Dada Mail:

https://dadamailproject.com/d

Specifically, see the Error FAQ:

https://dadamailproject.com/d/FAQ-errors.pod.html

To post to this list, send a message to:

mailto:dadadev@dadamailproject.com

All subscribers of this list may post to the list itself.

Topics that are welcome:

  • Constructive critiques on the program (I like, "x", but, "y" needs some work - here's an idea on how to make this better...)
  • Bug/Error reports
  • Bug fixes
  • Request For Comments on any changes to the program
  • Help customizing Dada Mail for your own needs
  • Patches
  • Language Translations
  • Support Documentation/Doc editing, FAQ's, etc.
  • Discussion of any changes that you would like to be committed to the next version of Dada Mail -

Dada Mail is on Github:

https://github.com/justingit/dada-mail/

If you would like to fork, branch, send over PRs, open up issues, etc.

Privacy Policy:

This Privacy Policy is for this mailing list, and this mailing list only.

Email addresses collection through this mailing list are used explicitly to work within this email discussion list.

We only collect email addresses through our Closed-Loop Opt-In system.

We don't use your email address for any other purpose.

We won't be sharing your email address with any other entity.

Unsubscription can be done at any time. Please contact us at: justin@dadamailproject.com for any help regarding your subscription, including removal from the mailing list.

All mailing list messages sent from us will include a subscription removal link, which will allow you to remove yourself from this mailing list automatically, and permanently.

All consent to use your email address for any other purpose stated at the time of the mailing list subscription will also be revoked upon mailing list removal.