Skip to content

Commit

Permalink
Merge pull request #80 from tt1991/master
Browse files Browse the repository at this point in the history
feat(api): Introduce export endpoint
  • Loading branch information
drawain committed Apr 4, 2016
2 parents 0d06d57 + 4df27c6 commit 3a32217
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 0 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -427,3 +427,9 @@ Lists the purchases of customers per day.
##### [Listing Available Fields Choices](http://documentation.emarsys.com/resource/developers/endpoints/contacts/list-field-choices/)

suiteAPI.field.getChoices(payload);

#### Export

##### [Downloading export data](http://documentation.emarsys.com/resource/developers/endpoints/exporting-data/download-data/)

suiteAPI.export.getData(payload);
35 changes: 35 additions & 0 deletions api/endpoints/export/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
'use strict';

var util = require('util');
var _ = require('lodash');
var logger = require('logentries-logformat')('suite-sdk');

var Base = require('../_base');

var Export = function(request, options) {
Base.call(this, options);
this._request = request;
};

util.inherits(Export, Base);

_.extend(Export.prototype, {

getData: function(payload, options) {
return this._requireParameters(payload, ['export_id']).then(function() {
logger.log('get_export_data');
return this._request.get(
this._getCustomerId(options),
util.format('/export/%s/data/offset=%s&limit=%s', payload.export_id, payload.offset || '', payload.limit || ''),
options
);
}.bind(this));
}

});

Export.create = function(request, options) {
return new Export(request, options);
};

module.exports = Export;
19 changes: 19 additions & 0 deletions api/endpoints/export/index.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
'use strict';

var ExportAPI = require('./');
var testApiMethod = require('../_test');

describe('SuiteAPI Export endpoint', function() {

describe('getData', function() {
testApiMethod(ExportAPI, 'getData').withArgs({ export_id: 1 }).shouldGetResultFromEndpoint('/export/1/data/offset=&limit=');
testApiMethod(ExportAPI, 'getData').withArgs({ export_id: 1, offset: 2 }).shouldGetResultFromEndpoint('/export/1/data/offset=2&limit=');
testApiMethod(ExportAPI, 'getData').withArgs({ export_id: 1, limit: 3 }).shouldGetResultFromEndpoint('/export/1/data/offset=&limit=3');
testApiMethod(ExportAPI, 'getData').withArgs({ export_id: 1, offset: 2, limit: 3 }).shouldGetResultFromEndpoint('/export/1/data/offset=2&limit=3');
testApiMethod(ExportAPI, 'getData').withArgs().shouldThrowMissingParameterError('export_id');
testApiMethod(ExportAPI, 'getData').withArgs({ limit: 3 }).shouldThrowMissingParameterError('export_id');
testApiMethod(ExportAPI, 'getData').withArgs({ offset: 2 }).shouldThrowMissingParameterError('export_id');
testApiMethod(ExportAPI, 'getData').withArgs({ offset: 2, limit: 3 }).shouldThrowMissingParameterError('export_id');
});

});
3 changes: 3 additions & 0 deletions api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ var ConditionAPI = require('./endpoints/condition');
var ContactAPI = require('./endpoints/contact');
var ContactListAPI = require('./endpoints/contactlist');
var EmailAPI = require('./endpoints/email');
var ExportAPI = require('./endpoints/export');
var ExternalEventAPI = require('./endpoints/externalevent');
var FieldAPI = require('./endpoints/field');
var FormAPI = require('./endpoints/form');
Expand All @@ -32,6 +33,7 @@ var SuiteAPI = function(options) {
this.contact = ContactAPI.create(this._apiRequest, options);
this.contactList = ContactListAPI.create(this._apiRequest, options);
this.email = EmailAPI.create(this._apiRequest, options);
this.export = ExportAPI.create(this._apiRequest, options);
this.externalEvent = ExternalEventAPI.create(this._apiRequest, options);
this.field = FieldAPI.create(this._apiRequest, options);
this.form = FormAPI.create(this._apiRequest, options);
Expand Down Expand Up @@ -110,6 +112,7 @@ module.exports.Condition = ConditionAPI;
module.exports.Contact = ContactAPI;
module.exports.ContactList = ContactListAPI;
module.exports.Email = EmailAPI;
module.exports.Export = ExportAPI;
module.exports.ExternalEvent = ExternalEventAPI;
module.exports.Field = FieldAPI;
module.exports.Form = FormAPI;
Expand Down
8 changes: 8 additions & 0 deletions api/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ var ConditionAPI = require('./endpoints/condition');
var ContactAPI = require('./endpoints/contact');
var ContactListAPI = require('./endpoints/contactlist');
var EmailAPI = require('./endpoints/email');
var ExportAPI = require('./endpoints/export');
var ExternalEventAPI = require('./endpoints/externalevent');
var FieldAPI = require('./endpoints/field');
var FormAPI = require('./endpoints/form');
Expand Down Expand Up @@ -186,6 +187,7 @@ describe('SuiteApi', function() {
this.sandbox.stub(ContactAPI, 'create').returns('FromContactEndpointStub');
this.sandbox.stub(ContactListAPI, 'create').returns('FromContactListEndpointStub');
this.sandbox.stub(EmailAPI, 'create').returns('FromEmailEndpointStub');
this.sandbox.stub(ExportAPI, 'create').returns('FromExportEndpointStub');
this.sandbox.stub(ExternalEventAPI, 'create').returns('FromExternalEventEndpointStub');
this.sandbox.stub(FieldAPI, 'create').returns('FromFieldEndpointStub');
this.sandbox.stub(FormAPI, 'create').returns('FromFormEndpointStub');
Expand Down Expand Up @@ -240,6 +242,12 @@ describe('SuiteApi', function() {
api: EmailAPI,
stub: 'FromEmailEndpointStub'
},
{
endpoint: 'Export',
sdkKey: 'export',
api: ExportAPI,
stub: 'FromExportEndpointStub'
},
{
endpoint: 'ExternalEvent',
sdkKey: 'externalEvent',
Expand Down

0 comments on commit 3a32217

Please sign in to comment.