Giter Club home page Giter Club logo

guerrilla-api's Introduction

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);
		});
	}
});

Once we have an email, we can fetch the full mail body if we want:

guerrillaApi.fetchEmail(email.mail_id).then(
	(fullEmail) =>
		console.log(`Got full email body:\n\n${fullEmail.mail_excerpt}`));

guerrilla-api's People

Contributors

brunokrebs avatar

Watchers

 avatar

Forkers

enmand

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.