Skip to content

Commit

Permalink
feat: add code samples for Runs and Builds (#1340)
Browse files Browse the repository at this point in the history
  • Loading branch information
m-murasovs authored Dec 20, 2024
1 parent 54fe91e commit 98ce77a
Show file tree
Hide file tree
Showing 16 changed files with 132 additions and 3 deletions.
2 changes: 1 addition & 1 deletion apify-api/openapi/code_samples/javascript/act_runs_post.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ const apifyClient = new ApifyClient({
});
const run = await apifyClient
.actor('<ACTOR ID>')
.start({ 'foo': 'bar' });
.start({ foo: 'bar' });

console.log(run);

Check warning on line 10 in apify-api/openapi/code_samples/javascript/act_runs_post.js

View workflow job for this annotation

GitHub Actions / Lint app code

Unexpected console statement
10 changes: 10 additions & 0 deletions apify-api/openapi/code_samples/javascript/actorBuild_abort_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 abortedBuild = await apifyClient
.build('<BUILD ID>')
.abort();

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

const apifyClient = new ApifyClient({
token: '<TOKEN>',
});
await apifyClient.build('<BUILD ID>').delete();
10 changes: 10 additions & 0 deletions apify-api/openapi/code_samples/javascript/actorBuild_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 build = await apifyClient
.build('<BUILD ID>')
.get();

console.log(build);
11 changes: 11 additions & 0 deletions apify-api/openapi/code_samples/javascript/actorBuild_log_get.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>',
});
const buildLog = await apifyClient
.build('<BUILD ID>')
.log()
.get();

console.log(buildLog);
10 changes: 10 additions & 0 deletions apify-api/openapi/code_samples/javascript/actorBuilds_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
.builds()
.list();

console.log(items);
10 changes: 10 additions & 0 deletions apify-api/openapi/code_samples/javascript/actorRun_abort_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 abortedRun = await apifyClient
.run('<RUN ID>')
.abort();

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

const apifyClient = new ApifyClient({
token: '<TOKEN>',
});
await apifyClient.run('<RUN ID>').delete();
10 changes: 10 additions & 0 deletions apify-api/openapi/code_samples/javascript/actorRun_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 run = await apifyClient
.run('<RUN ID>')
.get();

console.log(run);
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 metamorphedRun = await apifyClient
.run('<RUN ID>')
.metamorph('<ACTOR ID>');

console.log(metamorphedRun);
12 changes: 12 additions & 0 deletions apify-api/openapi/code_samples/javascript/actorRun_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 updatedRun = await apifyClient
.run('<RUN ID>')
.update({
statusMessage: 'Actor has finished',
});

console.log(updatedRun);
10 changes: 10 additions & 0 deletions apify-api/openapi/code_samples/javascript/actorRun_reboot_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 rebootedRun = await apifyClient
.run('<RUN ID>')
.reboot();

console.log(rebootedRun);
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 resurrectedRun = await apifyClient
.run('<RUN ID>')
.resurrect();

console.log(resurrectedRun);
10 changes: 10 additions & 0 deletions apify-api/openapi/code_samples/javascript/actorRuns_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
.runs()
.list();

console.log(items);
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ const apifyClient = new ApifyClient({
});
const updatedInput = await apifyClient
.task('<TASK ID>')
.updateInput({ 'foo': 'baz' });
.updateInput({ foo: 'baz' });

console.log(updatedInput);
6 changes: 5 additions & 1 deletion apify-api/plugins/decorators/code-samples-decorator.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,12 @@ function CodeSamplesDecorator(target) {

const codeSamples = [];

// For some reason, the operationId for resurrect run is PostResurrectRun,
// so we change it here to keep the file names consistent
const operationId = target.operationId === 'PostResurrectRun' ? 'actorRun_resurrect_post' : target.operationId;

for (const { lang, label } of LANGUAGES) {
const codeSamplePath = path.join(__dirname, `../../openapi/code_samples/${lang.toLowerCase()}/${target.operationId}.js`);
const codeSamplePath = path.join(__dirname, `../../openapi/code_samples/${lang.toLowerCase()}/${operationId}.js`);

if (!existsSync(codeSamplePath)) {
// Just use this console log in development to see which operations are missing a code sample.
Expand Down

0 comments on commit 98ce77a

Please sign in to comment.