-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #80 from tt1991/master
feat(api): Introduce export endpoint
- Loading branch information
Showing
5 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters