diff --git a/Readme.md b/Readme.md index 4435555..4788bad 100644 --- a/Readme.md +++ b/Readme.md @@ -39,6 +39,7 @@ You can also work with all the other resources authenticated with a secret API K - [Cards](https://developers.getmango.com/en/api/cards/?platform=node) - [Queue](https://developers.getmango.com/en/api/queue/?platform=node) - [Installments](https://developers.getmango.com/en/api/installments/?platform=node) +- [Promotions](https://developers.getmango.com/en/api/promotions/?platform=node) ## Tests diff --git a/lib/index.js b/lib/index.js index 0245c49..d896295 100644 --- a/lib/index.js +++ b/lib/index.js @@ -16,6 +16,7 @@ var Charges = require('./resources/charges'); var Refunds = require('./resources/refunds'); var Queue = require('./resources/queue'); var Installments = require('./resources/installments'); +var Promotions = require('./resources/promotions'); /** * Expose constructor @@ -49,6 +50,7 @@ function Mango(options) { this.Refunds = new Refunds(this); this.Queue = new Queue(this); this.Installments = new Installments(this); + this.Promotions = new Promotions(this); debug('Client intialized'); } diff --git a/lib/resources/promotions.js b/lib/resources/promotions.js new file mode 100644 index 0000000..ce187b7 --- /dev/null +++ b/lib/resources/promotions.js @@ -0,0 +1,48 @@ + +/** + * Module dependencies + */ + +var util = require('util'); +var Resource = require('./'); + +/** + * Expose constructor + */ + +module.exports = Promotions; + +/** + * Promotions constructor + */ + +function Promotions(mango) { + Resource.call(this, mango); +} + +util.inherits(Promotions, Resource); + +/** + * Get promotion + * + * @param {String} uid + * @param {Function} callback + * @api public + */ + +Promotions.prototype.get = function(uid, fn) { + return this.request('get', '/promotions/' + uid + '/', fn); +}; + +/** + * List promotions + * + * @param {Object} options + * @param {Function} callback + * @api public + */ + +Promotions.prototype.list = function(options, fn) { + return this.request('get', '/promotions/', options, fn); +}; + diff --git a/package.json b/package.json index 2f0bb30..ac5671b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "mango", - "version": "0.0.0", + "version": "0.0.1", "description": "Mango API client for node.js", "main": "lib/index.js", "scripts": { @@ -15,7 +15,12 @@ "Mango", "API" ], - "author": "Dan Zajdband ", + "author": "Mango (https://getmango.com)", + "contributors": [ + "Dan Zajdband ", + "Guillermo Paz ", + "Juan Rossi " + ], "license": "MIT", "dependencies": { "debug": "2.1.0", diff --git a/test/promotions.js b/test/promotions.js new file mode 100644 index 0000000..f1ab010 --- /dev/null +++ b/test/promotions.js @@ -0,0 +1,51 @@ + +/** + * Module dependencies + */ + +var request = require('superagent'); + +/** + * Aux function to create promotions generation requirements + */ + +describe('Promotions', function(){ + + describe('base', function(){ + it('Inherits from Resource', function(){ + assert(mango.Promotions instanceof require('../lib/resources')); + }); + + it('Has all required methods', function(){ + ['get', 'list'].forEach(function(method){ + assert('function' == typeof mango.Promotions[method]); + }); + }); + }); + + describe('#get', function(){ + it('Get a promotion', function(done){ + mango.Promotions.list({'status': 'active'}, function(err, data){ + mango.Promotions.get(data[0].uid, function(err, promotion){ + assert('object' == typeof promotion); + assert(promotion.status === 'active'); + assert(promotion.live === false); + done(err); + }); + }); + }); + }); + + describe('#list', function(){ + it('List promotions', function(done){ + mango.Promotions.list({'status': 'active'}, function(err, data){ + assert(Array.isArray(data)); + assert(data.length); + assert(data[0].status === 'active'); + assert(!data[0].live); + done(err); + }); + }); + }); + +});