This repository has been archived by the owner on Jul 27, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
FtApi.js
55 lines (42 loc) · 1.52 KB
/
FtApi.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
'use strict';
var PathMapper = require('./lib/PathMapper.js'),
Logger = require('./lib/Logger.js'),
RequestManager = require('./lib/requestManager.js'),
contentCalls = require('./lib/contentCalls.js'),
notificationsCalls = require('./lib/notificationsCalls.js');
function FtApi (options) {
options = options || {};
if (typeof options.apiKey !== 'string' || options.apiKey === '') {
throw new TypeError('The FT API constructor requires an API key, ' +
'which must be a non-empty string');
}
if(!Array.isArray(options.featureFlags)) {
options.featureFlags = [];
}
// Use v2 paths
var apiVersion = options.apiVersion ? options.apiVersion : 1;
this.pathMapper = new PathMapper(options.apiKey, {
features: options.featureFlags,
apiVersion: apiVersion
});
this.logger = new Logger();
this.requestManager = new RequestManager(options);
if (typeof options.logLevel === 'number') {
this.setLogLevel(options.logLevel);
}
contentCalls.mixInTo(this);
notificationsCalls.mixInTo(this);
}
/* LOGGING */
/* Note that this is not a per-instance level. Should instance-ise later */
FtApi.prototype.setLogLevel = function (logLevel) {
this.logger.setLogLevel(logLevel);
};
FtApi.prototype.getLogLevel = function () {
return this.logger.getLogLevel();
};
/* STATIC FLAGS */
FtApi.LOG_LEVEL_NONE = Logger.LOG_LEVEL_NONE;
FtApi.LOG_LEVEL_INFO = Logger.LOG_LEVEL_INFO;
FtApi.LOG_LEVEL_ERROR = Logger.LOG_LEVEL_ERROR;
module.exports = FtApi;