2017-10-20 13:30:01 -04:00
|
|
|
var angular = require('angular');
|
|
|
|
|
2018-01-14 09:24:40 -05:00
|
|
|
angular.module('ApiSvc', []).service('ApiService', ['$http', function ($http) {
|
2017-10-18 13:31:08 -04:00
|
|
|
this.getKey = function (identifier, cb) {
|
|
|
|
$http({
|
|
|
|
method: 'GET',
|
|
|
|
url: '/api/keys/get',
|
|
|
|
params: {identifier: identifier}
|
|
|
|
}).then(function (res) {
|
|
|
|
cb(res.data);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2018-01-14 10:27:05 -05:00
|
|
|
this.getAllKeys = function (cb) {
|
2017-10-18 13:31:08 -04:00
|
|
|
$http({
|
|
|
|
method: 'GET',
|
|
|
|
url: '/api/keys/get'
|
|
|
|
}).then(function (res) {
|
|
|
|
cb(res.data);
|
|
|
|
});
|
|
|
|
};
|
2017-10-21 15:10:24 -04:00
|
|
|
|
2017-10-21 17:47:55 -04:00
|
|
|
this.deleteKey = function (key, cb) {
|
2017-10-21 15:10:24 -04:00
|
|
|
$http({
|
|
|
|
method: 'POST',
|
|
|
|
url: '/api/keys/delete',
|
|
|
|
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
|
2017-10-21 17:47:55 -04:00
|
|
|
transformRequest: function (obj) {
|
2017-10-21 15:10:24 -04:00
|
|
|
var str = [];
|
|
|
|
for (var p in obj)
|
2018-01-14 09:50:54 -05:00
|
|
|
if (obj.hasOwnProperty(p))
|
|
|
|
str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
|
2017-10-21 15:10:24 -04:00
|
|
|
return str.join("&");
|
|
|
|
},
|
|
|
|
data: {key: key.key}
|
2017-10-21 17:47:55 -04:00
|
|
|
}).then(function (res) {
|
|
|
|
cb(res.data);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
this.createKey = function (key, cb) {
|
|
|
|
$http({
|
|
|
|
method: 'POST',
|
|
|
|
url: '/api/keys/create',
|
|
|
|
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
|
|
|
|
transformRequest: function (obj) {
|
|
|
|
var str = [];
|
|
|
|
for (var p in obj)
|
2018-01-14 09:50:54 -05:00
|
|
|
if (obj.hasOwnProperty(p))
|
|
|
|
str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
|
2017-10-21 17:47:55 -04:00
|
|
|
return str.join("&");
|
|
|
|
},
|
|
|
|
data: key
|
2017-10-21 15:10:24 -04:00
|
|
|
}).then(function(res) {
|
|
|
|
cb(res.data);
|
|
|
|
});
|
2017-10-21 17:47:55 -04:00
|
|
|
};
|
2017-10-18 13:31:08 -04:00
|
|
|
}]);
|