From 353d3a73d97fb9e316ae7110a31cc9abd413ef46 Mon Sep 17 00:00:00 2001 From: tt1991 Date: Mon, 4 Apr 2016 13:45:38 +0200 Subject: [PATCH 1/2] feat(api): Introduce export endpoint --- api/endpoints/export/index.js | 35 ++++++++++++++++++++++++++++++ api/endpoints/export/index.spec.js | 13 +++++++++++ api/index.js | 3 +++ api/index.spec.js | 8 +++++++ 4 files changed, 59 insertions(+) create mode 100644 api/endpoints/export/index.js create mode 100644 api/endpoints/export/index.spec.js diff --git a/api/endpoints/export/index.js b/api/endpoints/export/index.js new file mode 100644 index 0000000..e783928 --- /dev/null +++ b/api/endpoints/export/index.js @@ -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', payload.export_id), + options + ); + }.bind(this)); + } + +}); + +Export.create = function(request, options) { + return new Export(request, options); +}; + +module.exports = Export; diff --git a/api/endpoints/export/index.spec.js b/api/endpoints/export/index.spec.js new file mode 100644 index 0000000..d9a4f8e --- /dev/null +++ b/api/endpoints/export/index.spec.js @@ -0,0 +1,13 @@ +'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'); + testApiMethod(ExportAPI, 'getData').withArgs().shouldThrowMissingParameterError('export_id'); + }); + +}); diff --git a/api/index.js b/api/index.js index d16e7f6..e34e716 100644 --- a/api/index.js +++ b/api/index.js @@ -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'); @@ -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); @@ -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; diff --git a/api/index.spec.js b/api/index.spec.js index 2c9431b..7f87ec0 100644 --- a/api/index.spec.js +++ b/api/index.spec.js @@ -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'); @@ -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'); @@ -240,6 +242,12 @@ describe('SuiteApi', function() { api: EmailAPI, stub: 'FromEmailEndpointStub' }, + { + endpoint: 'Export', + sdkKey: 'export', + api: ExportAPI, + stub: 'FromExportEndpointStub' + }, { endpoint: 'ExternalEvent', sdkKey: 'externalEvent', From 4df27c6f572768ab1cdc783a834e5ea0076b751c Mon Sep 17 00:00:00 2001 From: tt1991 Date: Mon, 4 Apr 2016 15:35:14 +0200 Subject: [PATCH 2/2] feat(export): Change url and add export to readme --- README.md | 6 ++++++ api/endpoints/export/index.js | 2 +- api/endpoints/export/index.spec.js | 8 +++++++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4b63122..2e8d671 100644 --- a/README.md +++ b/README.md @@ -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); diff --git a/api/endpoints/export/index.js b/api/endpoints/export/index.js index e783928..4eae235 100644 --- a/api/endpoints/export/index.js +++ b/api/endpoints/export/index.js @@ -20,7 +20,7 @@ _.extend(Export.prototype, { logger.log('get_export_data'); return this._request.get( this._getCustomerId(options), - util.format('/export/%s/data', payload.export_id), + util.format('/export/%s/data/offset=%s&limit=%s', payload.export_id, payload.offset || '', payload.limit || ''), options ); }.bind(this)); diff --git a/api/endpoints/export/index.spec.js b/api/endpoints/export/index.spec.js index d9a4f8e..2bb16f3 100644 --- a/api/endpoints/export/index.spec.js +++ b/api/endpoints/export/index.spec.js @@ -6,8 +6,14 @@ var testApiMethod = require('../_test'); describe('SuiteAPI Export endpoint', function() { describe('getData', function() { - testApiMethod(ExportAPI, 'getData').withArgs({ export_id: 1 }).shouldGetResultFromEndpoint('/export/1/data'); + 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'); }); });