diff --git a/package.json b/package.json index 60b1068..b3f1505 100644 --- a/package.json +++ b/package.json @@ -22,6 +22,7 @@ "babel-core": "^6.7.2", "babel-loader": "^6.2.4", "babel-plugin-transform-runtime": "^6.6.0", + "babel-polyfill": "^6.9.1", "babel-preset-es2015": "^6.6.0", "expect.js": "~0.3.1", "form-data": "^1.0.0-rc3", diff --git a/src/api/task.js b/src/api/task.js new file mode 100644 index 0000000..1603111 --- /dev/null +++ b/src/api/task.js @@ -0,0 +1,25 @@ +export default class TaskAPI { + constructor(client) { + this.client = client; + } + + run(command, { image, token, timeLimit }) { + const payload = { command }; + + if (image) { + payload.image = image; + } + if (token) { + payload.token = token; + } + if (timeLimit) { + payload.time_limit = timeLimit; + } + + return this.client.request(`tasks/`, 'POST', payload); + } + + get(task_id) { + return this.client.request(`tasks/${task_id}/`); + } +} diff --git a/src/client.js b/src/client.js index e1940eb..0a73a27 100644 --- a/src/client.js +++ b/src/client.js @@ -1,6 +1,7 @@ import fetch from 'isomorphic-fetch'; import querystring from 'querystring'; import _ from 'lodash'; +import 'babel-polyfill'; import DocumentAPI from './api/document'; import FileAPI from './api/file'; @@ -8,6 +9,7 @@ import RoleAPI from './api/role'; import SchemaAPI from './api/schema'; import UserAPI from './api/user'; import PolicyAPI from './api/policy'; +import TaskAPI from './api/task'; export default class Client { constructor(project, token) { @@ -22,6 +24,7 @@ export default class Client { this.roles = new RoleAPI(this); this.files = new FileAPI(this); this.policy = new PolicyAPI(this); + this.tasks = new TaskAPI(this); } url(endpoint) {