Scribe.js/static/js/services/scribeAPI.js

60 lines
1.6 KiB
JavaScript
Raw Normal View History

2014-11-11 21:20:33 +01:00
(function () {
'use strict';
2014-11-13 21:33:37 +01:00
/**
* ScribeAPI
*
* A $resource API wrapper
*/
2014-11-11 21:20:33 +01:00
window.app.factory('ScribeAPI', ['$resource', function ($resource) {
return $resource(
'api',
null,
{
logWriters : {
method : 'GET',
isArray : true
},
dateExplorer : {
method : 'GET',
url : 'api/dateExplorer',
isArray : true
},
folderExplorer : {
method : 'GET',
url : 'api/folderExplorer',
isArray : true
},
log : {
method : 'GET',
url : 'api/log',
isArray : true,
2014-11-13 21:33:37 +01:00
//As logs are lines of JSON, we want to parse each lines one by one
2014-11-11 21:20:33 +01:00
transformResponse : function (data) {
2014-11-13 21:33:37 +01:00
var lines = data.match(/[^\r\n]+/g); //cut lines
2014-11-11 21:20:33 +01:00
return lines.map(function (line) {
try {
return JSON.parse(line);
} catch (e) {
return line;
}
});
}
},
timezoneOffset : {
methof : 'GET',
url : 'api/timezoneOffset'
2014-11-11 21:20:33 +01:00
}
}
);
}]);
}());