Skip to content

Commit

Permalink
feat: add code samples for storages
Browse files Browse the repository at this point in the history
  • Loading branch information
m-murasovs committed Dec 12, 2024
1 parent 7490d31 commit 0588349
Show file tree
Hide file tree
Showing 32 changed files with 344 additions and 0 deletions.
8 changes: 8 additions & 0 deletions apify-api/openapi/code_samples/javascript/dataset_delete.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { ApifyClient } from 'apify-client';

const apifyClient = new ApifyClient({
token: '<TOKEN>',
});
await apifyClient
.dataset('<DATASET ID>')
.delete();
10 changes: 10 additions & 0 deletions apify-api/openapi/code_samples/javascript/dataset_get.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { ApifyClient } from 'apify-client';

const apifyClient = new ApifyClient({
token: '<TOKEN>',
});
const dataset = await apifyClient
.dataset('<DATASET ID>')
.get();

console.log(dataset);
10 changes: 10 additions & 0 deletions apify-api/openapi/code_samples/javascript/dataset_items_get.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { ApifyClient } from 'apify-client';

const apifyClient = new ApifyClient({
token: '<TOKEN>',
});
const { items } = await apifyClient
.dataset('<DATASET ID>')
.listItems();

console.log(items);
11 changes: 11 additions & 0 deletions apify-api/openapi/code_samples/javascript/dataset_items_post.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { ApifyClient } from 'apify-client';

const apifyClient = new ApifyClient({
token: '<TOKEN>',
});
await apifyClient
.dataset('<DATASET ID>')
.pushItems([
{ foo: 'bar' },
{ fizz: 'buzz' },
]);
12 changes: 12 additions & 0 deletions apify-api/openapi/code_samples/javascript/dataset_put.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { ApifyClient } from 'apify-client';

const apifyClient = new ApifyClient({
token: '<TOKEN>',
});
const updatedDataset = await apifyClient
.dataset('<DATASET ID>')
.update({
title: 'New title',
});

console.log(updatedDataset);
10 changes: 10 additions & 0 deletions apify-api/openapi/code_samples/javascript/datasets_get.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { ApifyClient } from 'apify-client';

const apifyClient = new ApifyClient({
token: '<TOKEN>',
});
const { items } = await apifyClient
.datasets()
.list();

console.log(items);
10 changes: 10 additions & 0 deletions apify-api/openapi/code_samples/javascript/datasets_post.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { ApifyClient } from 'apify-client';

const apifyClient = new ApifyClient({
token: '<TOKEN>',
});
const dataset = await apifyClient
.datasets()
.getOrCreate('<DATASET NAME>');

console.log(dataset);
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { ApifyClient } from 'apify-client';

const apifyClient = new ApifyClient({
token: '<TOKEN>',
});
await apifyClient
.keyValueStore('<STORE ID>')
.delete();
10 changes: 10 additions & 0 deletions apify-api/openapi/code_samples/javascript/keyValueStore_get.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { ApifyClient } from 'apify-client';

const apifyClient = new ApifyClient({
token: '<TOKEN>',
});
const store = await apifyClient
.keyValueStore('<STORE ID>')
.get();

console.log(store);
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { ApifyClient } from 'apify-client';

const apifyClient = new ApifyClient({
token: '<TOKEN>',
});
const { items } = await apifyClient
.keyValueStore('<STORE ID>')
.listKeys();

console.log(items);
12 changes: 12 additions & 0 deletions apify-api/openapi/code_samples/javascript/keyValueStore_put.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { ApifyClient } from 'apify-client';

const apifyClient = new ApifyClient({
token: '<TOKEN>',
});
const updatedStore = await apifyClient
.keyValueStore('<STORE ID>')
.update({
title: 'New title',
});

console.log(updatedStore);
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { ApifyClient } from 'apify-client';

const apifyClient = new ApifyClient({
token: '<TOKEN>',
});
await apifyClient
.keyValueStore('<STORE ID>')
.deleteRecord('<RECORD KEY>');
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { ApifyClient } from 'apify-client';

const apifyClient = new ApifyClient({
token: '<TOKEN>',
});
const record = await apifyClient
.keyValueStore('<STORE ID>')
.getRecord('<RECORD KEY>');

console.log(record);
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { ApifyClient } from 'apify-client';

const apifyClient = new ApifyClient({
token: '<TOKEN>',
});
await apifyClient
.keyValueStore('<STORE ID>')
.setRecord({
key: '<RECORD KEY>',
value: 'my value',
});
10 changes: 10 additions & 0 deletions apify-api/openapi/code_samples/javascript/keyValueStores_get.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { ApifyClient } from 'apify-client';

const apifyClient = new ApifyClient({
token: '<TOKEN>',
});
const { items } = await apifyClient
.keyValueStores()
.list();

console.log(items);
10 changes: 10 additions & 0 deletions apify-api/openapi/code_samples/javascript/keyValueStores_post.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { ApifyClient } from 'apify-client';

const apifyClient = new ApifyClient({
token: '<TOKEN>',
});
const store = await apifyClient
.keyValueStores()
.getOrCreate('<STORE NAME>');

console.log(store);
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { ApifyClient } from 'apify-client';

const apifyClient = new ApifyClient({
token: '<TOKEN>',
});
await apifyClient
.requestQueue('<QUEUE ID>')
.delete();
10 changes: 10 additions & 0 deletions apify-api/openapi/code_samples/javascript/requestQueue_get.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { ApifyClient } from 'apify-client';

const apifyClient = new ApifyClient({
token: '<TOKEN>',
});
const queue = await apifyClient
.requestQueue('<QUEUE ID>')
.get();

console.log(queue);
10 changes: 10 additions & 0 deletions apify-api/openapi/code_samples/javascript/requestQueue_head_get.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { ApifyClient } from 'apify-client';

const apifyClient = new ApifyClient({
token: '<TOKEN>',
});
const head = await apifyClient
.requestQueue('<QUEUE ID>')
.listHead();

console.log(head);
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { ApifyClient } from 'apify-client';

const apifyClient = new ApifyClient({
token: '<TOKEN>',
});
const result = await apifyClient
.requestQueue('<QUEUE ID>')
.listAndLockHead({
lockSecs: 300,
});

console.log(result);
12 changes: 12 additions & 0 deletions apify-api/openapi/code_samples/javascript/requestQueue_put.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { ApifyClient } from 'apify-client';

const apifyClient = new ApifyClient({
token: '<TOKEN>',
});
const updatedQueue = await apifyClient
.requestQueue('<QUEUE ID>')
.update({
title: 'New title',
});

console.log(updatedQueue);
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { ApifyClient } from 'apify-client';

const apifyClient = new ApifyClient({
token: '<TOKEN>',
});
await apifyClient
.requestQueue('<QUEUE ID>')
.deleteRequest('<REQUEST ID>');
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { ApifyClient } from 'apify-client';

const apifyClient = new ApifyClient({
token: '<TOKEN>',
});
const request = await apifyClient
.requestQueue('<QUEUE ID>')
.getRequest('<REQUEST ID>');

console.log(request);
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { ApifyClient } from 'apify-client';

const apifyClient = new ApifyClient({
token: '<TOKEN>',
});
await apifyClient
.requestQueue('<QUEUE ID>')
.deleteRequestLock('<REQUEST ID>');
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { ApifyClient } from 'apify-client';

const apifyClient = new ApifyClient({
token: '<TOKEN>',
});
const result = await apifyClient
.requestQueue('<QUEUE ID>')
.prolongRequestLock(
'<REQUEST ID>',
{
lockSecs: 3600,
},
);

console.log(result);
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { ApifyClient } from 'apify-client';

const apifyClient = new ApifyClient({
token: '<TOKEN>',
});
const result = await apifyClient
.requestQueue('<QUEUE ID>')
.updateRequest({
id: '<REQUEST ID>',
url: 'http://example.com',
});

console.log(result);
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { ApifyClient } from 'apify-client';

const apifyClient = new ApifyClient({
token: '<TOKEN>',
});
const result = await apifyClient
.requestQueue('<QUEUE ID>')
.batchDeleteRequests([
{ uniqueKey: 'http://example.com' },
{ uniqueKey: 'http://example.com/2' },
]);

console.log(result);
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { ApifyClient } from 'apify-client';

const apifyClient = new ApifyClient({
token: '<TOKEN>',
});
const result = await apifyClient
.requestQueue('<QUEUE ID>')
.batchAddRequests([
{
uniqueKey: 'http://example.com',
url: 'http://example.com',
method: 'GET',
},
{
uniqueKey: 'http://example.com/2',
url: 'http://example.com/2',
method: 'GET',
},
]);

console.log(result);
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { ApifyClient } from 'apify-client';

const apifyClient = new ApifyClient({
token: '<TOKEN>',
});
const { items } = await apifyClient
.requestQueue('<QUEUE ID>')
.listRequests();

console.log(items);
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { ApifyClient } from 'apify-client';

const apifyClient = new ApifyClient({
token: '<TOKEN>',
});
const result = await apifyClient
.requestQueue('<QUEUE ID>')
.addRequest({
'uniqueKey': 'http://example.com',
'url': 'http://example.com',
'method': 'GET',
});

console.log(result);
10 changes: 10 additions & 0 deletions apify-api/openapi/code_samples/javascript/requestQueues_get.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { ApifyClient } from 'apify-client';

const apifyClient = new ApifyClient({
token: '<TOKEN>',
});
const { items } = await apifyClient
.requestQueues()
.list();

console.log(items);
10 changes: 10 additions & 0 deletions apify-api/openapi/code_samples/javascript/requestQueues_post.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { ApifyClient } from 'apify-client';

const apifyClient = new ApifyClient({
token: '<TOKEN>',
});
const queue = await apifyClient
.requestQueues()
.getOrCreate('<QUEUE NAME>');

console.log(queue);

0 comments on commit 0588349

Please sign in to comment.