Skip to content

Commit

Permalink
Merge pull request apify#69 from apifytech/feature/abort-run-build
Browse files Browse the repository at this point in the history
Abort act run or build
  • Loading branch information
gippy authored Jun 6, 2018
2 parents 0f5bd81 + a3df32d commit 4837f9f
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "apify-client",
"version": "0.2.10",
"version": "0.2.11",
"description": "Apify API client for JavaScript",
"main": "build/index.js",
"keywords": [
Expand Down
67 changes: 67 additions & 0 deletions src/acts.js
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,41 @@ export default {
.catch(catchNotFoundOrThrow);
},

/**
* Abort act run.
*
* @memberof ApifyClient.acts
* @instance
* @param {Object} options
* @param {String} options.actId - Unique act ID
* @param {String} options.runId - Unique run ID
* @param [options.token]
* @param callback
* @returns {ActRun}
*/
abortRun: (requestPromise, options) => {
const { baseUrl, token, actId, runId } = options;

checkParamOrThrow(baseUrl, 'baseUrl', 'String');
checkParamOrThrow(actId, 'actId', 'String');
checkParamOrThrow(runId, 'runId', 'String');
checkParamOrThrow(token, 'token', 'Maybe String');

const safeActId = replaceSlashWithTilde(actId);
const query = {};

if (token) query.token = token;

return requestPromise({
url: `${baseUrl}${BASE_PATH}/${safeActId}/runs/${runId}/abort`,
json: true,
method: 'POST',
qs: query,
})
.then(pluckData)
.then(parseDateFields);
},

/**
* Gets list of act builds.
*
Expand Down Expand Up @@ -491,4 +526,36 @@ export default {
.catch(catchNotFoundOrThrow);
},

/**
* Abort act build.
*
* @memberof ApifyClient.acts
* @instance
* @param {Object} options
* @param options.token
* @param {String} options.actId - Unique act ID
* @param {String} options.buildId - Unique build ID
* @param callback
* @returns {ActBuild}
*/
abortBuild: (requestPromise, options) => {
const { baseUrl, token, actId, buildId } = options;

checkParamOrThrow(baseUrl, 'baseUrl', 'String');
checkParamOrThrow(actId, 'actId', 'String');
checkParamOrThrow(token, 'token', 'String');
checkParamOrThrow(buildId, 'buildId', 'String');

const safeActId = replaceSlashWithTilde(actId);
const query = { token };

return requestPromise({
url: `${baseUrl}${BASE_PATH}/${safeActId}/builds/${buildId}/abort`,
json: true,
method: 'POST',
qs: query,
})
.then(pluckData)
.then(parseDateFields);
},
};
46 changes: 46 additions & 0 deletions test/acts.js
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,29 @@ describe('Act method', () => {
.then(response => expect(response).to.be.eql(run));
});

it('abortRun() works', () => {
const actId = 'some-act-id';
const runId = 'some-run-id';
const token = 'some-token';
const run = { foo: 'bar' };

requestExpectCall({
json: true,
method: 'POST',
url: `${BASE_URL}${BASE_PATH}/${actId}/runs/${runId}/abort`,
qs: { token },
}, {
data: run,
});

const apifyClient = new ApifyClient(OPTIONS);

return apifyClient
.acts
.abortRun({ actId, token, runId })
.then(response => expect(response).to.be.eql(run));
});

it('getRun() works without token', () => {
const actId = 'some-act-id';
const runId = 'some-run-id';
Expand Down Expand Up @@ -474,4 +497,27 @@ describe('Act method', () => {
.getBuild({ actId, buildId, token })
.then(given => expect(given).to.be.eql(null));
});

it('abortBuild() works', () => {
const actId = 'some-act-id';
const buildId = 'some-build-id';
const token = 'some-token';
const build = { foo: 'bar' };

requestExpectCall({
json: true,
method: 'POST',
url: `${BASE_URL}${BASE_PATH}/${actId}/builds/${buildId}/abort`,
qs: { token },
}, {
data: build,
});

const apifyClient = new ApifyClient(OPTIONS);

return apifyClient
.acts
.abortBuild({ actId, token, buildId })
.then(response => expect(response).to.be.eql(build));
});
});

0 comments on commit 4837f9f

Please sign in to comment.