Skip to content

Commit

Permalink
Merge pull request #68 from FunnelEnvy/api/smartlist-support
Browse files Browse the repository at this point in the history
Get Smart Lists
  • Loading branch information
pcothenet authored Oct 10, 2019
2 parents 94fa0bd + 2a8b1d9 commit 05f940d
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 4 deletions.
31 changes: 31 additions & 0 deletions lib/api/smartList.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
var _ = require('lodash'),
util = require('../util');

var SMARTLISTS = util.createAssetPath('smartLists.json');

function SmartList(marketo, connection) {
this._marketo = marketo;
this._connection = connection;
}

SmartList.prototype = {
find: function(options) {
var arrayFields = [];
options = _.extend({}, options, {
_method: 'GET',
});
options = util.arrayToCSV(options, arrayFields);
return this._connection.post(SMARTLISTS, {data: options});
},
byId: function(smartListId, options) {
var SMARTLISTS_ID = util.createAssetPath('smartList', `${smartListId}.json`);
var arrayFields = [];
options = _.extend({}, options, {
_method: 'GET',
});
options = util.arrayToCSV(options, arrayFields);
return this._connection.post(SMARTLISTS_ID, {data: options});
}
};

module.exports = SmartList;
3 changes: 1 addition & 2 deletions lib/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ function getNextPageFn(conn, method, args) {
/**
* This function is just a helper function that delegates everything to
* restler, but returns a Promise instead of going with the existing event
* based resposnes.
* based responses.
*/
Connection.prototype._request = function(method) {
var args = Array.prototype.slice.call(arguments, 1),
Expand Down Expand Up @@ -92,7 +92,6 @@ Connection.prototype._request = function(method) {
'Authorization': 'Bearer ' + token.access_token
});
args.push(options);

rest[method].apply(rest, args)
.on('success', function(data, resp) {
if (data.success === false && _.has(data, 'errors')) {
Expand Down
2 changes: 2 additions & 0 deletions lib/marketo.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ var _ = require('lodash'),
LandingPage = require('./api/landingPage'),
Lead = require('./api/lead'),
List = require('./api/list'),
SmartList = require('./api/smartlist'),
Stats = require('./api/stats'),
BulkLeadExtract = require('./api/bulkLeadExtract'),
BulkActivityExtract = require('./api/bulkActivityExtract'),
Expand All @@ -26,6 +27,7 @@ function Marketo(options) {
this.email = new Email(this, this._connection);
this.landingPage = new LandingPage(this, this._connection);
this.list = new List(this, this._connection);
this.smartList = new SmartList(this, this._connection);
this.lead = new Lead(this, this._connection);
this.stats = new Stats(this, this._connection);
this.activities = new Activities(this, this._connection);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node-marketo-rest",
"version": "0.7.5",
"version": "0.7.6",
"description": "marketo rest client",
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion test/activities.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var assert = require('assert'),

describe('Activities', function() {
describe('list activity types', function() {
it('lists activity types', function(done){
it('lists activity types', function(done) {
marketo.activities.getActivityTypes().then(function(resp) {
var activity = resp.result[0];
assert.equal(activity.id, 1);
Expand Down
31 changes: 31 additions & 0 deletions test/smartlists.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
var assert = require('assert'),
_ = require('lodash'),
marketo = require('./helper/connection');

describe('SmartLists', function () {
var smartListId;
describe('#find', function () {
it('displays list of smart lists', function (done) {
marketo.smartList.find({maxReturn: 100}).then(function (response) {
assert.equal(response.success, true);
assert.equal(response.errors.length, 0);
assert(_.has(response.result[0], 'name'));
assert(_.has(response.result[0], 'workspace'));
smartListId = response.result[0].id;
done();
}).catch(done);
});
});
describe('#byId', function () {
it('finds smart list by id', function (done) {
marketo.smartList.byId(smartListId, {includeRules: true}).then(function (response) {
assert.equal(response.success, true);
assert.equal(response.errors.length, 0);
assert.equal(response.result.length, 1);
assert(_.has(response.result[0], 'name'));
assert(_.has(response.result[0], 'workspace'));
done();
}).catch(done);
});
});
});

0 comments on commit 05f940d

Please sign in to comment.