2016-06-18 21:53:18 +02:00
|
|
|
'use strict';
|
|
|
|
const reqwest = require('reqwest');
|
2015-03-17 22:01:46 +01:00
|
|
|
|
2016-06-18 21:53:18 +02:00
|
|
|
const TYPE = 'json';
|
|
|
|
const CONTENT_TYPE = 'application/json';
|
2015-03-17 22:01:46 +01:00
|
|
|
|
2016-06-18 21:53:18 +02:00
|
|
|
const StrategyAPI = {
|
2016-07-02 11:54:50 +02:00
|
|
|
createStrategy (strategy, cb) {
|
2015-03-17 22:01:46 +01:00
|
|
|
reqwest({
|
|
|
|
url: 'strategies',
|
|
|
|
method: 'post',
|
|
|
|
type: TYPE,
|
|
|
|
contentType: CONTENT_TYPE,
|
|
|
|
data: JSON.stringify(strategy),
|
2016-07-02 11:54:50 +02:00
|
|
|
error (error) {
|
2016-04-24 22:41:37 +02:00
|
|
|
cb(error);
|
2015-03-17 22:01:46 +01:00
|
|
|
},
|
2016-07-02 11:54:50 +02:00
|
|
|
success () {
|
2016-04-24 22:41:37 +02:00
|
|
|
cb(null, strategy);
|
2016-06-18 21:55:46 +02:00
|
|
|
},
|
2015-03-17 22:01:46 +01:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2016-07-02 11:54:50 +02:00
|
|
|
removeStrategy (strategy, cb) {
|
2015-03-17 22:01:46 +01:00
|
|
|
reqwest({
|
2016-06-18 21:53:18 +02:00
|
|
|
url: `strategies/${strategy.name}`,
|
2015-03-17 22:01:46 +01:00
|
|
|
method: 'delete',
|
|
|
|
type: TYPE,
|
2016-07-02 11:54:50 +02:00
|
|
|
error (error) {
|
2016-04-24 22:41:37 +02:00
|
|
|
cb(error);
|
2015-03-17 22:01:46 +01:00
|
|
|
},
|
2016-07-02 11:54:50 +02:00
|
|
|
success () {
|
2016-04-24 22:41:37 +02:00
|
|
|
cb(null, strategy);
|
2016-06-18 21:55:46 +02:00
|
|
|
},
|
2015-03-17 22:01:46 +01:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2016-07-02 11:54:50 +02:00
|
|
|
getStrategies (cb) {
|
2015-03-17 22:01:46 +01:00
|
|
|
reqwest({
|
|
|
|
url: 'strategies',
|
|
|
|
method: 'get',
|
|
|
|
type: TYPE,
|
2016-07-02 11:54:50 +02:00
|
|
|
error (error) {
|
2016-04-24 22:41:37 +02:00
|
|
|
cb(error);
|
2015-03-17 22:01:46 +01:00
|
|
|
},
|
2016-07-02 11:54:50 +02:00
|
|
|
success (data) {
|
2016-04-24 22:41:37 +02:00
|
|
|
cb(null, data.strategies);
|
2016-06-18 21:55:46 +02:00
|
|
|
},
|
2015-03-17 22:01:46 +01:00
|
|
|
});
|
2016-06-18 21:55:46 +02:00
|
|
|
},
|
2015-03-17 22:01:46 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = StrategyAPI;
|