loadlab
Version:
LoadLab Javascript API
1 lines • 2.9 kB
JavaScript
;var _extends=Object.assign||function(a){for(var b,c=1;c<arguments.length;c++)for(var d in b=arguments[c],b)Object.prototype.hasOwnProperty.call(b,d)&&(a[d]=b[d]);return a};Object.defineProperty(exports,'__esModule',{value:!0});function _possibleConstructorReturn(a,b){if(!a)throw new ReferenceError('this hasn\'t been initialised - super() hasn\'t been called');return b&&('object'==typeof b||'function'==typeof b)?b:a}function _inherits(a,b){if('function'!=typeof b&&null!==b)throw new TypeError('Super expression must either be null or a function, not '+typeof b);a.prototype=Object.create(b&&b.prototype,{constructor:{value:a,enumerable:!1,writable:!0,configurable:!0}}),b&&(Object.setPrototypeOf?Object.setPrototypeOf(a,b):a.__proto__=b)}function _classCallCheck(a,b){if(!(a instanceof b))throw new TypeError('Cannot call a class as a function')}function ApiError(a,b,c){var d=this,e=null,f=!1;try{e=JSON.parse(b),f=!0}catch(a){e=b}this.response=e,this.message=a,this.status=c}var Resource=function a(b){var c=this,d=1<arguments.length&&arguments[1]!==void 0?arguments[1]:{};_classCallCheck(this,a),this.PATH=null,this.BASE_URL='https://api.loadlab.co/v1',this.get=function(){var a=null,b=c.BASE_URL+c.PATH;return fetch(b,c.options).then(function(b){return a=b,401===a.status,200>a.status||300<=a.status?a.text():a.json()}).then(function(b){if(200>a.status||300<=a.status)throw b;return b}).catch(function(b){if(a)throw new ApiError('Request failed with status '+a.status+'.',b,a.status);else throw new ApiError(b.toString(),null,'REQUEST_FAILED')})};this.options=_extends({},{},d,{headers:_extends({},{Accept:'application/json',Authorization:'Token '+b},d.headers)})},Jobs=function(a){function b(){var a,c,d,e;_classCallCheck(this,b);for(var f=arguments.length,g=Array(f),h=0;h<f;h++)g[h]=arguments[h];return e=(c=(d=_possibleConstructorReturn(this,(a=b.__proto__||Object.getPrototypeOf(b)).call.apply(a,[this].concat(g))),d),d.PATH='/jobs/',c),_possibleConstructorReturn(d,e)}return _inherits(b,a),b}(Resource),Plans=function(a){function b(){var a,c,d,e;_classCallCheck(this,b);for(var f=arguments.length,g=Array(f),h=0;h<f;h++)g[h]=arguments[h];return e=(c=(d=_possibleConstructorReturn(this,(a=b.__proto__||Object.getPrototypeOf(b)).call.apply(a,[this].concat(g))),d),d.PATH='/plans/',c),_possibleConstructorReturn(d,e)}return _inherits(b,a),b}(Resource),Sites=function(a){function b(){var a,c,d,e;_classCallCheck(this,b);for(var f=arguments.length,g=Array(f),h=0;h<f;h++)g[h]=arguments[h];return e=(c=(d=_possibleConstructorReturn(this,(a=b.__proto__||Object.getPrototypeOf(b)).call.apply(a,[this].concat(g))),d),d.PATH='/sites/',c),_possibleConstructorReturn(d,e)}return _inherits(b,a),b}(Resource),LoadLab=function a(b){_classCallCheck(this,a),this.jobs=new Jobs(b),this.plans=new Plans(b),this.sites=new Sites(b)};exports.default=LoadLab,module.exports=exports['default'];