guerrilla-api
v0.2.1
Published
Guerrilla-api is a node module that wraps the guerrilla api (I have chosen an amazing and creative name, don't you think so?) to smooth the comunication of your app/module with their service.
Downloads
9
Readme
guerrilla-api
Guerrilla API module for Node
npm install guerrilla-api
why
Well, I first wrote this module to enable automated tests that depend on e-mail. For example, I'm design a software where the user can create an account, and it is expected that this user receive an e-mail to validate his/her account. Since I use Guerrilla Mail a lot and they have a not so bad api, I have decided to write this module to use it in my automated tests.
why not
You might ask why haven't I used another pre-existing module. You would receive a short an easy answer: I haven't find any module with a good documentation and interface.
usage
First things first. Guerrilla Mail api expects you to pass an ip address that is the origin of your requests. Besides that, it also expects you to provide an user agent. So there we go:
var Guerrilla = require('guerrilla-api');
var guerrillaApi = new Guerrilla('127.0.0.1', 'automated-test-agent');
From that, we are now ready to make our first call to Guerrilla api. Let's see what e-mail address they give us.
guerrillaApi.getEmailAddress(function(err, address) {
if (err) {
console.log('Holly crap, something went wrong!' + err);
} else {
console.log('As I expected. My new temp e-mail is: ' + address);
}
});
Well, maybe you don't like the e-mail address randomly provided by Guerrilla. So, lets create one of our own.
guerrillaApi.setEmailAddress(desiredUsernameEmail, function (err, address) {
if (err) {
console.log('Weirdooo, something went wrong!' + err);
} else {
console.log('Nice, I have a new e-mail address. Check it out: '
+ address);
}
});
Now that we have a nice e-mail address, let's check what do we have in our inbox:
guerrillaApi.checkEmail(function (err, emails) {
if (err) {
console.log('Noooooo, an error? It must be a solar storm. Let\'s see: '
+ err);
} else {
emails.forEach(function(email) {
console.log(email.mail_from +
' sent me an e-mail with the following subject: '
+ mail.mail_subject);
});
}
});