Skip to content

Commit 7ff3f4d

Browse files
committed
feat: use debug instead logger
to view debug output from API Wrapper, run your app with the debug flag as in: ``` $ DEBUG=* node index.js ```
1 parent a9a7dec commit 7ff3f4d

File tree

6 files changed

+28
-13
lines changed

6 files changed

+28
-13
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
> A high-level library for interacting with DADI API
44
55
[![npm (scoped)](https://img.shields.io/npm/v/@dadi/api-wrapper.svg?maxAge=10800&style=flat-square)](https://www.npmjs.com/package/@dadi/api-wrapper)
6-
![coverage](https://img.shields.io/badge/coverage-93%25-brightgreen.svg?style=flat-square)
6+
![coverage](https://img.shields.io/badge/coverage-91%25-brightgreen.svg?style=flat-square)
77
[![Build Status](https://travis-ci.org/dadi/api-wrapper.svg?branch=master)](https://travis-ci.org/dadi/api-wrapper)
88
[![JavaScript Style Guide](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](http://standardjs.com/)
99
[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?style=flat-square)](https://github.com/semantic-release/semantic-release)

index.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,6 @@ const APIWrapper = function (options) {
2121
path: __dirname + '/.wallet/token.' + this._slugify(options.uri + options.port) + '.' + this._slugify(options.credentials.clientId) + '.json'
2222
}
2323
}
24-
25-
// Initialise logger
26-
this.logger = require('@dadi/logger')
27-
this.logger.init({
28-
enabled: true,
29-
filename: 'api-wrapper',
30-
level: this.options.debug ? 'info' : 'warn'
31-
})
3224
}
3325

3426
APIWrapper.prototype = new APIWrapperCore()

lib/helpers.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
'use strict'
22

3+
const debug = require('debug')('api-wrapper')
34
const passport = require('@dadi/passport')
45
const request = require('request-promise')
56

67
module.exports = function (APIWrapper) {
78
/**
8-
* Logs a message. Overrides the basic log mechanism with DADI Logger
9+
* Logs a debug message to the console when running with `DEBUG=*`.
910
*
1011
* @param {String} message
1112
* @return undefined
1213
* @api private
1314
*/
1415
APIWrapper.prototype._log = function (message) {
15-
this.logger.info(message)
16+
debug(message)
1617
}
1718

1819
/**

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
"license": "GPL",
1313
"dependencies": {
1414
"@dadi/api-wrapper-core": "1.x.0",
15-
"@dadi/logger": "^1.1.3",
1615
"@dadi/passport": "^1.2.0",
16+
"debug": "^2.6.1",
1717
"query-string": "^4.1.0",
1818
"request-promise": "^2.0.1",
1919
"standard": "*"

scripts/coverage.svg

Lines changed: 1 addition & 1 deletion
Loading

test/unit/terminators.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,4 +355,26 @@ describe('Terminators', function (done) {
355355
})
356356
})
357357
})
358+
359+
describe('getCollections', function () {
360+
afterEach(function () {
361+
apiWrapper.prototype._buildURL.restore()
362+
})
363+
364+
it('should call buildUrl with {collections:true}', function() {
365+
var host = options.uri + ':' + options.port
366+
var urlPath = '/api/collections'
367+
var scope = nock(host).get(urlPath).reply(200)
368+
369+
sinon.stub(apiWrapper.prototype, '_buildURL', function() {
370+
var args = arguments[0]
371+
args.should.eql({collections:true})
372+
return this.options.uri + ':' + this.options.port + '/api/collections'
373+
})
374+
375+
return wrapper.getCollections().then().catch((err) => {
376+
throw err
377+
})
378+
})
379+
})
358380
})

0 commit comments

Comments
 (0)