Skip to content

Commit

Permalink
Adding update method for all storage types
Browse files Browse the repository at this point in the history
  • Loading branch information
mtrunkat committed Oct 15, 2019
1 parent a1a1649 commit eb72445
Show file tree
Hide file tree
Showing 8 changed files with 163 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
0.5.26 / 2019/07/24
===================
- Added update method for request queues, datasets and key-value stores.

0.5.23 / 2019/07/24
===================
- Added new method `client.acts.resurrectRun()` that resurrects finished (even failed) actor run.
Expand Down
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.5.25",
"version": "0.5.26",
"description": "Apify API client for JavaScript",
"main": "build/index.js",
"keywords": [
Expand Down
31 changes: 31 additions & 0 deletions src/datasets.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,37 @@ export default {
.catch(catchNotFoundOrThrow);
},

/**
* Updates dataset.
*
* @memberof ApifyClient.datasets
* @instance
* @param {Object} options
* @param options.token
* @param {String} options.datasetId - Unique dataset ID
* @param {Object} options.dataset
* @param callback
* @returns {Dataset}
*/
updateDataset: (requestPromise, options) => {
const { baseUrl, token, datasetId, dataset } = options;

checkParamOrThrow(baseUrl, 'baseUrl', 'String');
checkParamOrThrow(token, 'token', 'String');
checkParamOrThrow(datasetId, 'datasetId', 'String');
checkParamOrThrow(dataset, 'dataset', 'Object');

return requestPromise({
url: `${baseUrl}${BASE_PATH}/${datasetId}`,
json: true,
method: 'PUT',
qs: { token },
body: _.omit(dataset, 'id'),
})
.then(pluckData)
.then(parseDateFields);
},

/**
* Deletes given dataset.
*
Expand Down
32 changes: 32 additions & 0 deletions src/key_value_stores.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import _ from 'underscore';
import { checkParamOrThrow, gzipPromise, pluckData, catchNotFoundOrThrow, parseBody, parseDateFields } from './utils';

/**
Expand Down Expand Up @@ -164,6 +165,37 @@ export default {
.catch(catchNotFoundOrThrow);
},

/**
* Updates key-value store.
*
* @memberof ApifyClient.stores
* @instance
* @param {Object} options
* @param options.token
* @param {String} options.storeId - Unique store ID
* @param {Object} options.store
* @param callback
* @returns {KeyValueStore}
*/
updateStore: (requestPromise, options) => {
const { baseUrl, token, storeId, store } = options;

checkParamOrThrow(baseUrl, 'baseUrl', 'String');
checkParamOrThrow(token, 'token', 'String');
checkParamOrThrow(storeId, 'storeId', 'String');
checkParamOrThrow(store, 'store', 'Object');

return requestPromise({
url: `${baseUrl}${BASE_PATH}/${storeId}`,
json: true,
method: 'PUT',
qs: { token },
body: _.omit(store, 'id'),
})
.then(pluckData)
.then(parseDateFields);
},

/**
* Deletes key-value store.
*
Expand Down
32 changes: 32 additions & 0 deletions src/request_queues.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import _ from 'underscore';
import { checkParamOrThrow, pluckData, catchNotFoundOrThrow, parseDateFields } from './utils';

// 256s - we use more for queries pointing to DynamoDB as it may sometimes need more time to scale up.
Expand Down Expand Up @@ -187,6 +188,37 @@ export default {
.catch(catchNotFoundOrThrow);
},

/**
* Updates request queue.
*
* @memberof ApifyClient.queues
* @instance
* @param {Object} options
* @param options.token
* @param {String} options.queueId - Unique queue ID
* @param {Object} options.queue
* @param callback
* @returns {RequestQueue}
*/
updateQueue: (requestPromise, options) => {
const { baseUrl, token, queueId, queue } = options;

checkParamOrThrow(baseUrl, 'baseUrl', 'String');
checkParamOrThrow(token, 'token', 'String');
checkParamOrThrow(queueId, 'queueId', 'String');
checkParamOrThrow(queue, 'queue', 'Object');

return requestPromise({
url: `${baseUrl}${BASE_PATH}/${queueId}`,
json: true,
method: 'PUT',
qs: { token },
body: _.omit(queue, 'id'),
})
.then(pluckData)
.then(parseDateFields);
},

/**
* Deletes request queue.
*
Expand Down
21 changes: 21 additions & 0 deletions test/datasets.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import _ from 'underscore';
import { expect } from 'chai';
import { gzipSync } from 'zlib';
import sinon from 'sinon';
Expand Down Expand Up @@ -174,6 +175,26 @@ describe('Dataset', () => {
.then(given => expect(given).to.be.eql(null));
});

it('updateDataset() works', () => {
const datasetId = 'some-id';
const token = 'my-token';
const dataset = { id: datasetId, name: 'my-name' };

requestExpectCall({
json: true,
method: 'PUT',
url: `${BASE_URL}${BASE_PATH}/${datasetId}`,
qs: { token },
body: _.omit(dataset, 'id'),
});

const apifyClient = new ApifyClient(OPTIONS);

return apifyClient
.datasets
.updateDataset({ datasetId, dataset, token });
});

it('deleteDataset() works', () => {
const datasetId = 'some-id';
const token = 'my-token';
Expand Down
21 changes: 21 additions & 0 deletions test/key_value_stores.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import _ from 'underscore';
import { expect } from 'chai';
import { gzipSync } from 'zlib';
import { randomBytes } from 'crypto';
Expand Down Expand Up @@ -171,6 +172,26 @@ describe('Key value store', () => {
.then(given => expect(given).to.be.eql(null));
});

it('updateStore() works', () => {
const storeId = 'some-id';
const token = 'my-token';
const store = { id: storeId, name: 'my-name' };

requestExpectCall({
json: true,
method: 'PUT',
url: `${BASE_URL}${BASE_PATH}/${storeId}`,
qs: { token },
body: _.omit(store, 'id'),
});

const apifyClient = new ApifyClient(OPTIONS);

return apifyClient
.keyValueStores
.updateStore({ storeId, store, token });
});

it('deleteStore() works', () => {
const storeId = 'some-id';
const token = 'my-token';
Expand Down
21 changes: 21 additions & 0 deletions test/request_queues.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import _ from 'underscore';
import { expect } from 'chai';
import ApifyClient from '../build';
import { BASE_PATH, REQUEST_ENDPOINTS_EXP_BACKOFF_MAX_REPEATS } from '../build/request_queues';
Expand Down Expand Up @@ -169,6 +170,26 @@ describe('Request queue', () => {
.then(given => expect(given).to.be.eql(null));
});

it('updateQueue() works', () => {
const queueId = 'some-id';
const token = 'my-token';
const queue = { id: queueId, name: 'my-name' };

requestExpectCall({
json: true,
method: 'PUT',
url: `${BASE_URL}${BASE_PATH}/${queueId}`,
qs: { token },
body: _.omit(queue, 'id'),
});

const apifyClient = new ApifyClient(OPTIONS);

return apifyClient
.requestQueues
.updateQueue({ queueId, queue, token });
});

it('deleteQueue() works', () => {
const queueId = 'some-id';
const token = 'my-token';
Expand Down

0 comments on commit eb72445

Please sign in to comment.