Skip to content

Commit

Permalink
Merge pull request apify#108 from apifytech/feature/tasks_list_webhooks
Browse files Browse the repository at this point in the history
Added tasks.listWebhooks()
  • Loading branch information
drobnikj authored Mar 15, 2019
2 parents 7b073ee + f8c891a commit 3c4593f
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
41 changes: 41 additions & 0 deletions src/tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,4 +330,45 @@ export default {
.then(pluckData)
.then(parseDateFields);
},

/**
* Gets list of webhooks for given actor task.
*
* @memberof ApifyClient.acts
* @instance
* @param {Object} options
* @param options.token
* @param {String} options.taskId - Unique task ID
* @param {Number} [options.offset=0] - Number of array elements that should be skipped at the start.
* @param {Number} [options.limit=1000] - Maximum number of array elements to return.
* @param {Boolean} [options.desc] - If `true` then the objects are sorted by the createdAt field in descending order.
* @param callback
* @returns {PaginationList}
*/
listWebhooks: (requestPromise, options) => {
const { baseUrl, token, taskId, offset, limit, desc } = options;

checkParamOrThrow(baseUrl, 'baseUrl', 'String');
checkParamOrThrow(taskId, 'taskId', 'String');
checkParamOrThrow(token, 'token', 'String');
checkParamOrThrow(limit, 'limit', 'Maybe Number');
checkParamOrThrow(offset, 'offset', 'Maybe Number');
checkParamOrThrow(desc, 'desc', 'Maybe Boolean');

const safeTaskId = replaceSlashWithTilde(taskId);
const query = { token };

if (limit) query.limit = limit;
if (offset) query.offset = offset;
if (desc) query.desc = 1;

return requestPromise({
url: `${baseUrl}${BASE_PATH}/${safeTaskId}/webhooks`,
json: true,
method: 'GET',
qs: query,
})
.then(pluckData)
.then(parseDateFields);
},
};
30 changes: 30 additions & 0 deletions test/tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -465,4 +465,34 @@ describe('Tasks method', () => {
.then(response => expect(response).to.be.eql(run));
});
*/

it('listWebhooks() works', () => {
const taskId = 'some-id';
const token = 'some-token';

const expected = {
limit: 5,
offset: 3,
desc: true,
count: 5,
total: 10,
items: ['webhook1', 'webhook2'],
};

requestExpectCall({
json: true,
method: 'GET',
url: `${BASE_URL}${BASE_PATH}/${taskId}/webhooks`,
qs: { token },
}, {
data: expected,
});

const apifyClient = new ApifyClient(OPTIONS);

return apifyClient
.tasks
.listWebhooks({ taskId, token })
.then(response => expect(response).to.be.eql(expected));
});
});

0 comments on commit 3c4593f

Please sign in to comment.