mrprompt/mandrill-migration

View on GitHub
src/mandrill.js

Summary

Maintainability
A
0 mins
Test Coverage
'use strict';

const mandrill = require('mandrill-api/mandrill');

class Mandrill {
    constructor(apiKey) {
        this.client = new mandrill.Mandrill(apiKey);
    }

    templates(callback) {
        this.client.templates.list({}, (result) => {
            callback(null, result);
        }, (error) => {
            callback(error);
        });
    }

    cleanup(templates) {
        const result = [];

        templates.forEach((row) => {
            const template = {
                slug: row.slug,
                name: row.name,
                updated_at: row.updated_at,
                created_at: row.created_at,
                published_at: row.published_at
            };

            result.push(template);
        });
        
        return result;
    }

    publish(name, callback) {
        this.client.templates.publish({name}, (result) => {
            callback(null, result);
        }, (error) => {
            callback(error);
        });
    }
}

module.exports = Mandrill;