Skip to content

Commit

Permalink
feat: add code samples for Apify CLI (#1359)
Browse files Browse the repository at this point in the history
Adds Apify CLI code samples. These are currently under CURL, since
custom languages aren't supported.

Some of the commands are still in development, I guess. E.g. the request
queues are missing from the CLI.

# NOTE 
when this is merged, you'll need to go to Actor `X8D0L4wfpO8fCL1uL` and
un-comment `curl` in the `LANGUAGES` const in `main.js`

---------

Co-authored-by: Martin Adámek <[email protected]>
  • Loading branch information
m-murasovs and B4nan authored Jan 16, 2025
1 parent c0b836d commit 9b4bf65
Show file tree
Hide file tree
Showing 34 changed files with 46 additions and 11 deletions.
1 change: 1 addition & 0 deletions apify-api/openapi/code_samples/curl/act_builds_get.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
apify builds ls
1 change: 1 addition & 0 deletions apify-api/openapi/code_samples/curl/act_builds_post.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
apify actors build <ACTOR ID>
1 change: 1 addition & 0 deletions apify-api/openapi/code_samples/curl/act_delete.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
apify actors rm <ACTOR ID>
1 change: 1 addition & 0 deletions apify-api/openapi/code_samples/curl/act_get.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
apify actors info <ACTOR ID>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
apify runs resurrect <RUN ID>
1 change: 1 addition & 0 deletions apify-api/openapi/code_samples/curl/act_runs_get.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
apify runs ls <ACTOR ID>
1 change: 1 addition & 0 deletions apify-api/openapi/code_samples/curl/act_runs_post.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
apify actors start <ACTOR ID>
1 change: 1 addition & 0 deletions apify-api/openapi/code_samples/curl/actorBuild_delete.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
apify builds rm <BUILD ID>
1 change: 1 addition & 0 deletions apify-api/openapi/code_samples/curl/actorBuild_get.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
apify builds info <BUILD ID>
1 change: 1 addition & 0 deletions apify-api/openapi/code_samples/curl/actorBuild_log_get.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
apify builds log <BUILD ID>
1 change: 1 addition & 0 deletions apify-api/openapi/code_samples/curl/actorRun_abort_post.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
apify runs abort <RUN ID>
1 change: 1 addition & 0 deletions apify-api/openapi/code_samples/curl/actorRun_delete.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
apify runs rm <RUN ID>
1 change: 1 addition & 0 deletions apify-api/openapi/code_samples/curl/actorRun_get.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
apify runs info <RUN ID>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
apify runs resurrect <RUN ID>
1 change: 1 addition & 0 deletions apify-api/openapi/code_samples/curl/actorTask_runs_post.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
apify task run <TASK ID>
1 change: 1 addition & 0 deletions apify-api/openapi/code_samples/curl/acts_get.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
apify actors ls
1 change: 1 addition & 0 deletions apify-api/openapi/code_samples/curl/acts_post.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
apify create <ACTOR NAME>
1 change: 1 addition & 0 deletions apify-api/openapi/code_samples/curl/dataset_delete.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
apify datasets rm <DATASET ID>
1 change: 1 addition & 0 deletions apify-api/openapi/code_samples/curl/dataset_items_post.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
apify datasets push-items <DATASET ID> '{ "foo": "bar" }'
1 change: 1 addition & 0 deletions apify-api/openapi/code_samples/curl/dataset_put.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
apify datasets rename <DATASET ID> <DATASET NAME>
1 change: 1 addition & 0 deletions apify-api/openapi/code_samples/curl/datasets_get.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
apify datasets ls
1 change: 1 addition & 0 deletions apify-api/openapi/code_samples/curl/datasets_post.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
apify datasets create <DATASET NAME>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
apify key-value-stores rm <STORE ID>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
apify key-value-stores keys <STORE ID>
1 change: 1 addition & 0 deletions apify-api/openapi/code_samples/curl/keyValueStore_put.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
apify key-value-stores rename <STORE ID> <STORE NAME>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
apify key-value-stores delete-value <STORE ID> INPUT
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
apify key-value-stores get-value <STORE ID> INPUT
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
apify key-value-stores set-value <STORE ID> INPUT '{"new": "value"}'
1 change: 1 addition & 0 deletions apify-api/openapi/code_samples/curl/keyValueStores_get.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
apify key-value-stores ls
1 change: 1 addition & 0 deletions apify-api/openapi/code_samples/curl/keyValueStores_post.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
apify key-value-stores create <STORE NAME>
1 change: 1 addition & 0 deletions apify-api/openapi/code_samples/curl/users_me_get.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
apify info
12 changes: 8 additions & 4 deletions apify-api/plugins/decorators/code-samples-decorator.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ const path = require('path');
const X_CODE_SAMPLES_PROPERTY = 'x-codeSamples';

const LANGUAGES = [
{ lang: 'JavaScript', label: 'JS client' },
{ lang: 'JavaScript', label: 'JS client', langSuffix: 'js' },
{ lang: 'cURL', label: 'Apify CLI', langSuffix: 'sh' },
];

/**
Expand All @@ -28,12 +29,15 @@ function CodeSamplesDecorator(target) {
// 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()}/${operationId}.js`);
for (const { lang, label, langSuffix } of LANGUAGES) {
const codeSamplePath = path.join(
__dirname,
`../../openapi/code_samples/${lang.toLowerCase()}/${operationId}.${langSuffix}`,
);

if (!existsSync(codeSamplePath)) {
// Just use this console log in development to see which operations are missing a code sample.
// console.log(`Missing code sample for operation ${target.operationId}`);
// console.log(`Missing code sample for operation ${target.operationId}.${langSuffix}`);
return;
}

Expand Down
12 changes: 6 additions & 6 deletions docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,12 @@ module.exports = {
],
},
languageTabs: [
{
highlight: 'bash',
label: 'CLI',
language: 'curl',
logoClass: 'curl',
},
{
highlight: 'javascript',
label: 'JavaScript',
Expand All @@ -334,12 +340,6 @@ module.exports = {
language: 'python',
logoClass: 'python',
},
{
highlight: 'bash',
label: 'cURL',
language: 'curl',
logoClass: 'curl',
},
{
highlight: 'php',
label: 'PHP',
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9b4bf65

Please sign in to comment.