From 9b4bf654ad379fc1b43d0d12e21dba0f122d5c4d Mon Sep 17 00:00:00 2001 From: Misha Date: Thu, 16 Jan 2025 15:02:54 +0100 Subject: [PATCH] feat: add code samples for Apify CLI (#1359) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- .../openapi/code_samples/curl/act_builds_get.sh | 1 + .../openapi/code_samples/curl/act_builds_post.sh | 1 + apify-api/openapi/code_samples/curl/act_delete.sh | 1 + apify-api/openapi/code_samples/curl/act_get.sh | 1 + .../code_samples/curl/act_run_resurrect_post.sh | 1 + apify-api/openapi/code_samples/curl/act_runs_get.sh | 1 + apify-api/openapi/code_samples/curl/act_runs_post.sh | 1 + .../openapi/code_samples/curl/actorBuild_delete.sh | 1 + .../openapi/code_samples/curl/actorBuild_get.sh | 1 + .../openapi/code_samples/curl/actorBuild_log_get.sh | 1 + .../openapi/code_samples/curl/actorRun_abort_post.sh | 1 + .../openapi/code_samples/curl/actorRun_delete.sh | 1 + apify-api/openapi/code_samples/curl/actorRun_get.sh | 1 + .../code_samples/curl/actorRun_resurrect_post.sh | 1 + .../openapi/code_samples/curl/actorTask_runs_post.sh | 1 + apify-api/openapi/code_samples/curl/acts_get.sh | 1 + apify-api/openapi/code_samples/curl/acts_post.sh | 1 + .../openapi/code_samples/curl/dataset_delete.sh | 1 + .../openapi/code_samples/curl/dataset_items_post.sh | 1 + apify-api/openapi/code_samples/curl/dataset_put.sh | 1 + apify-api/openapi/code_samples/curl/datasets_get.sh | 1 + apify-api/openapi/code_samples/curl/datasets_post.sh | 1 + .../code_samples/curl/keyValueStore_delete.sh | 1 + .../code_samples/curl/keyValueStore_keys_get.sh | 1 + .../openapi/code_samples/curl/keyValueStore_put.sh | 1 + .../code_samples/curl/keyValueStore_record_delete.sh | 1 + .../code_samples/curl/keyValueStore_record_get.sh | 1 + .../code_samples/curl/keyValueStore_record_put.sh | 1 + .../openapi/code_samples/curl/keyValueStores_get.sh | 1 + .../openapi/code_samples/curl/keyValueStores_post.sh | 1 + apify-api/openapi/code_samples/curl/users_me_get.sh | 1 + .../plugins/decorators/code-samples-decorator.js | 12 ++++++++---- docusaurus.config.js | 12 ++++++------ package-lock.json | 2 +- 34 files changed, 46 insertions(+), 11 deletions(-) create mode 100644 apify-api/openapi/code_samples/curl/act_builds_get.sh create mode 100644 apify-api/openapi/code_samples/curl/act_builds_post.sh create mode 100644 apify-api/openapi/code_samples/curl/act_delete.sh create mode 100644 apify-api/openapi/code_samples/curl/act_get.sh create mode 100644 apify-api/openapi/code_samples/curl/act_run_resurrect_post.sh create mode 100644 apify-api/openapi/code_samples/curl/act_runs_get.sh create mode 100644 apify-api/openapi/code_samples/curl/act_runs_post.sh create mode 100644 apify-api/openapi/code_samples/curl/actorBuild_delete.sh create mode 100644 apify-api/openapi/code_samples/curl/actorBuild_get.sh create mode 100644 apify-api/openapi/code_samples/curl/actorBuild_log_get.sh create mode 100644 apify-api/openapi/code_samples/curl/actorRun_abort_post.sh create mode 100644 apify-api/openapi/code_samples/curl/actorRun_delete.sh create mode 100644 apify-api/openapi/code_samples/curl/actorRun_get.sh create mode 100644 apify-api/openapi/code_samples/curl/actorRun_resurrect_post.sh create mode 100644 apify-api/openapi/code_samples/curl/actorTask_runs_post.sh create mode 100644 apify-api/openapi/code_samples/curl/acts_get.sh create mode 100644 apify-api/openapi/code_samples/curl/acts_post.sh create mode 100644 apify-api/openapi/code_samples/curl/dataset_delete.sh create mode 100644 apify-api/openapi/code_samples/curl/dataset_items_post.sh create mode 100644 apify-api/openapi/code_samples/curl/dataset_put.sh create mode 100644 apify-api/openapi/code_samples/curl/datasets_get.sh create mode 100644 apify-api/openapi/code_samples/curl/datasets_post.sh create mode 100644 apify-api/openapi/code_samples/curl/keyValueStore_delete.sh create mode 100644 apify-api/openapi/code_samples/curl/keyValueStore_keys_get.sh create mode 100644 apify-api/openapi/code_samples/curl/keyValueStore_put.sh create mode 100644 apify-api/openapi/code_samples/curl/keyValueStore_record_delete.sh create mode 100644 apify-api/openapi/code_samples/curl/keyValueStore_record_get.sh create mode 100644 apify-api/openapi/code_samples/curl/keyValueStore_record_put.sh create mode 100644 apify-api/openapi/code_samples/curl/keyValueStores_get.sh create mode 100644 apify-api/openapi/code_samples/curl/keyValueStores_post.sh create mode 100644 apify-api/openapi/code_samples/curl/users_me_get.sh diff --git a/apify-api/openapi/code_samples/curl/act_builds_get.sh b/apify-api/openapi/code_samples/curl/act_builds_get.sh new file mode 100644 index 000000000..92ba2491c --- /dev/null +++ b/apify-api/openapi/code_samples/curl/act_builds_get.sh @@ -0,0 +1 @@ +apify builds ls diff --git a/apify-api/openapi/code_samples/curl/act_builds_post.sh b/apify-api/openapi/code_samples/curl/act_builds_post.sh new file mode 100644 index 000000000..b19d03cca --- /dev/null +++ b/apify-api/openapi/code_samples/curl/act_builds_post.sh @@ -0,0 +1 @@ +apify actors build diff --git a/apify-api/openapi/code_samples/curl/act_delete.sh b/apify-api/openapi/code_samples/curl/act_delete.sh new file mode 100644 index 000000000..6e573706f --- /dev/null +++ b/apify-api/openapi/code_samples/curl/act_delete.sh @@ -0,0 +1 @@ +apify actors rm diff --git a/apify-api/openapi/code_samples/curl/act_get.sh b/apify-api/openapi/code_samples/curl/act_get.sh new file mode 100644 index 000000000..9ce8295fa --- /dev/null +++ b/apify-api/openapi/code_samples/curl/act_get.sh @@ -0,0 +1 @@ +apify actors info diff --git a/apify-api/openapi/code_samples/curl/act_run_resurrect_post.sh b/apify-api/openapi/code_samples/curl/act_run_resurrect_post.sh new file mode 100644 index 000000000..406d2abe1 --- /dev/null +++ b/apify-api/openapi/code_samples/curl/act_run_resurrect_post.sh @@ -0,0 +1 @@ +apify runs resurrect diff --git a/apify-api/openapi/code_samples/curl/act_runs_get.sh b/apify-api/openapi/code_samples/curl/act_runs_get.sh new file mode 100644 index 000000000..5e3457909 --- /dev/null +++ b/apify-api/openapi/code_samples/curl/act_runs_get.sh @@ -0,0 +1 @@ +apify runs ls diff --git a/apify-api/openapi/code_samples/curl/act_runs_post.sh b/apify-api/openapi/code_samples/curl/act_runs_post.sh new file mode 100644 index 000000000..92334d78c --- /dev/null +++ b/apify-api/openapi/code_samples/curl/act_runs_post.sh @@ -0,0 +1 @@ +apify actors start diff --git a/apify-api/openapi/code_samples/curl/actorBuild_delete.sh b/apify-api/openapi/code_samples/curl/actorBuild_delete.sh new file mode 100644 index 000000000..46aca2472 --- /dev/null +++ b/apify-api/openapi/code_samples/curl/actorBuild_delete.sh @@ -0,0 +1 @@ +apify builds rm diff --git a/apify-api/openapi/code_samples/curl/actorBuild_get.sh b/apify-api/openapi/code_samples/curl/actorBuild_get.sh new file mode 100644 index 000000000..824ec1e1f --- /dev/null +++ b/apify-api/openapi/code_samples/curl/actorBuild_get.sh @@ -0,0 +1 @@ +apify builds info diff --git a/apify-api/openapi/code_samples/curl/actorBuild_log_get.sh b/apify-api/openapi/code_samples/curl/actorBuild_log_get.sh new file mode 100644 index 000000000..0acee6f57 --- /dev/null +++ b/apify-api/openapi/code_samples/curl/actorBuild_log_get.sh @@ -0,0 +1 @@ +apify builds log diff --git a/apify-api/openapi/code_samples/curl/actorRun_abort_post.sh b/apify-api/openapi/code_samples/curl/actorRun_abort_post.sh new file mode 100644 index 000000000..5929d9986 --- /dev/null +++ b/apify-api/openapi/code_samples/curl/actorRun_abort_post.sh @@ -0,0 +1 @@ +apify runs abort diff --git a/apify-api/openapi/code_samples/curl/actorRun_delete.sh b/apify-api/openapi/code_samples/curl/actorRun_delete.sh new file mode 100644 index 000000000..71fdbbdaf --- /dev/null +++ b/apify-api/openapi/code_samples/curl/actorRun_delete.sh @@ -0,0 +1 @@ +apify runs rm diff --git a/apify-api/openapi/code_samples/curl/actorRun_get.sh b/apify-api/openapi/code_samples/curl/actorRun_get.sh new file mode 100644 index 000000000..bd2957f71 --- /dev/null +++ b/apify-api/openapi/code_samples/curl/actorRun_get.sh @@ -0,0 +1 @@ +apify runs info diff --git a/apify-api/openapi/code_samples/curl/actorRun_resurrect_post.sh b/apify-api/openapi/code_samples/curl/actorRun_resurrect_post.sh new file mode 100644 index 000000000..406d2abe1 --- /dev/null +++ b/apify-api/openapi/code_samples/curl/actorRun_resurrect_post.sh @@ -0,0 +1 @@ +apify runs resurrect diff --git a/apify-api/openapi/code_samples/curl/actorTask_runs_post.sh b/apify-api/openapi/code_samples/curl/actorTask_runs_post.sh new file mode 100644 index 000000000..cbc1173c0 --- /dev/null +++ b/apify-api/openapi/code_samples/curl/actorTask_runs_post.sh @@ -0,0 +1 @@ +apify task run diff --git a/apify-api/openapi/code_samples/curl/acts_get.sh b/apify-api/openapi/code_samples/curl/acts_get.sh new file mode 100644 index 000000000..c90025d47 --- /dev/null +++ b/apify-api/openapi/code_samples/curl/acts_get.sh @@ -0,0 +1 @@ +apify actors ls diff --git a/apify-api/openapi/code_samples/curl/acts_post.sh b/apify-api/openapi/code_samples/curl/acts_post.sh new file mode 100644 index 000000000..eff3e5e1d --- /dev/null +++ b/apify-api/openapi/code_samples/curl/acts_post.sh @@ -0,0 +1 @@ +apify create diff --git a/apify-api/openapi/code_samples/curl/dataset_delete.sh b/apify-api/openapi/code_samples/curl/dataset_delete.sh new file mode 100644 index 000000000..d0cd8c628 --- /dev/null +++ b/apify-api/openapi/code_samples/curl/dataset_delete.sh @@ -0,0 +1 @@ +apify datasets rm diff --git a/apify-api/openapi/code_samples/curl/dataset_items_post.sh b/apify-api/openapi/code_samples/curl/dataset_items_post.sh new file mode 100644 index 000000000..0190df5a1 --- /dev/null +++ b/apify-api/openapi/code_samples/curl/dataset_items_post.sh @@ -0,0 +1 @@ +apify datasets push-items '{ "foo": "bar" }' diff --git a/apify-api/openapi/code_samples/curl/dataset_put.sh b/apify-api/openapi/code_samples/curl/dataset_put.sh new file mode 100644 index 000000000..505c10bab --- /dev/null +++ b/apify-api/openapi/code_samples/curl/dataset_put.sh @@ -0,0 +1 @@ +apify datasets rename diff --git a/apify-api/openapi/code_samples/curl/datasets_get.sh b/apify-api/openapi/code_samples/curl/datasets_get.sh new file mode 100644 index 000000000..ce3089baf --- /dev/null +++ b/apify-api/openapi/code_samples/curl/datasets_get.sh @@ -0,0 +1 @@ +apify datasets ls diff --git a/apify-api/openapi/code_samples/curl/datasets_post.sh b/apify-api/openapi/code_samples/curl/datasets_post.sh new file mode 100644 index 000000000..cf7a46476 --- /dev/null +++ b/apify-api/openapi/code_samples/curl/datasets_post.sh @@ -0,0 +1 @@ +apify datasets create diff --git a/apify-api/openapi/code_samples/curl/keyValueStore_delete.sh b/apify-api/openapi/code_samples/curl/keyValueStore_delete.sh new file mode 100644 index 000000000..898148bdf --- /dev/null +++ b/apify-api/openapi/code_samples/curl/keyValueStore_delete.sh @@ -0,0 +1 @@ +apify key-value-stores rm diff --git a/apify-api/openapi/code_samples/curl/keyValueStore_keys_get.sh b/apify-api/openapi/code_samples/curl/keyValueStore_keys_get.sh new file mode 100644 index 000000000..cc0e46841 --- /dev/null +++ b/apify-api/openapi/code_samples/curl/keyValueStore_keys_get.sh @@ -0,0 +1 @@ +apify key-value-stores keys diff --git a/apify-api/openapi/code_samples/curl/keyValueStore_put.sh b/apify-api/openapi/code_samples/curl/keyValueStore_put.sh new file mode 100644 index 000000000..0ffe964fa --- /dev/null +++ b/apify-api/openapi/code_samples/curl/keyValueStore_put.sh @@ -0,0 +1 @@ +apify key-value-stores rename diff --git a/apify-api/openapi/code_samples/curl/keyValueStore_record_delete.sh b/apify-api/openapi/code_samples/curl/keyValueStore_record_delete.sh new file mode 100644 index 000000000..3ed2927b8 --- /dev/null +++ b/apify-api/openapi/code_samples/curl/keyValueStore_record_delete.sh @@ -0,0 +1 @@ +apify key-value-stores delete-value INPUT diff --git a/apify-api/openapi/code_samples/curl/keyValueStore_record_get.sh b/apify-api/openapi/code_samples/curl/keyValueStore_record_get.sh new file mode 100644 index 000000000..4fb50c663 --- /dev/null +++ b/apify-api/openapi/code_samples/curl/keyValueStore_record_get.sh @@ -0,0 +1 @@ +apify key-value-stores get-value INPUT diff --git a/apify-api/openapi/code_samples/curl/keyValueStore_record_put.sh b/apify-api/openapi/code_samples/curl/keyValueStore_record_put.sh new file mode 100644 index 000000000..bde502c07 --- /dev/null +++ b/apify-api/openapi/code_samples/curl/keyValueStore_record_put.sh @@ -0,0 +1 @@ +apify key-value-stores set-value INPUT '{"new": "value"}' diff --git a/apify-api/openapi/code_samples/curl/keyValueStores_get.sh b/apify-api/openapi/code_samples/curl/keyValueStores_get.sh new file mode 100644 index 000000000..cb58ccc9a --- /dev/null +++ b/apify-api/openapi/code_samples/curl/keyValueStores_get.sh @@ -0,0 +1 @@ +apify key-value-stores ls diff --git a/apify-api/openapi/code_samples/curl/keyValueStores_post.sh b/apify-api/openapi/code_samples/curl/keyValueStores_post.sh new file mode 100644 index 000000000..21498d75a --- /dev/null +++ b/apify-api/openapi/code_samples/curl/keyValueStores_post.sh @@ -0,0 +1 @@ +apify key-value-stores create diff --git a/apify-api/openapi/code_samples/curl/users_me_get.sh b/apify-api/openapi/code_samples/curl/users_me_get.sh new file mode 100644 index 000000000..2e45ebbf8 --- /dev/null +++ b/apify-api/openapi/code_samples/curl/users_me_get.sh @@ -0,0 +1 @@ +apify info diff --git a/apify-api/plugins/decorators/code-samples-decorator.js b/apify-api/plugins/decorators/code-samples-decorator.js index 6b839d078..f61a676c5 100644 --- a/apify-api/plugins/decorators/code-samples-decorator.js +++ b/apify-api/plugins/decorators/code-samples-decorator.js @@ -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' }, ]; /** @@ -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; } diff --git a/docusaurus.config.js b/docusaurus.config.js index 2922ef0d6..f745216e4 100644 --- a/docusaurus.config.js +++ b/docusaurus.config.js @@ -322,6 +322,12 @@ module.exports = { ], }, languageTabs: [ + { + highlight: 'bash', + label: 'CLI', + language: 'curl', + logoClass: 'curl', + }, { highlight: 'javascript', label: 'JavaScript', @@ -334,12 +340,6 @@ module.exports = { language: 'python', logoClass: 'python', }, - { - highlight: 'bash', - label: 'cURL', - language: 'curl', - logoClass: 'curl', - }, { highlight: 'php', label: 'PHP', diff --git a/package-lock.json b/package-lock.json index 604e130da..34726e9ee 100644 --- a/package-lock.json +++ b/package-lock.json @@ -73,7 +73,7 @@ }, "apify-docs-theme": { "name": "@apify/docs-theme", - "version": "1.0.157", + "version": "1.0.161", "license": "ISC", "dependencies": { "@apify/docs-search-modal": "^1.2.0",