diff --git a/components/sproutgigs/actions/get-categories/get-categories.mjs b/components/sproutgigs/actions/get-categories/get-categories.mjs new file mode 100644 index 0000000000000..c443d2cbc91c9 --- /dev/null +++ b/components/sproutgigs/actions/get-categories/get-categories.mjs @@ -0,0 +1,20 @@ +import app from "../../sproutgigs.app.mjs"; + +export default { + key: "sproutgigs-get-categories", + name: "Get Categories", + description: "Get a list of categories from Sproutgigs. [See the documentation](https://sproutgigs.com/api/documentation.php#gigs-categories)", + version: "0.0.1", + type: "action", + props: { + app, + }, + async run({ $ }) { + const response = await this.app.getCategories({ + $, + data: {}, + }); + $.export("$summary", "Successfully sent the request. " + response.length + " results retrieved"); + return response; + }, +}; diff --git a/components/sproutgigs/actions/get-zones/get-zones.mjs b/components/sproutgigs/actions/get-zones/get-zones.mjs new file mode 100644 index 0000000000000..fdd3dfb343e13 --- /dev/null +++ b/components/sproutgigs/actions/get-zones/get-zones.mjs @@ -0,0 +1,19 @@ +import app from "../../sproutgigs.app.mjs"; + +export default { + key: "sproutgigs-get-zones", + name: "Get Zones", + description: "Get the available zones. [See the documentation](https://sproutgigs.com/api/documentation.php#jobs-zones)", + version: "0.0.1", + type: "action", + props: { + app, + }, + async run({ $ }) { + const response = await this.app.getZones({ + $, + }); + $.export("$summary", "Successfully sent the request. " + response.length + " results retrieved"); + return response; + }, +}; diff --git a/components/sproutgigs/actions/post-job/post-job.mjs b/components/sproutgigs/actions/post-job/post-job.mjs new file mode 100644 index 0000000000000..741bf1b85f959 --- /dev/null +++ b/components/sproutgigs/actions/post-job/post-job.mjs @@ -0,0 +1,84 @@ +import app from "../../sproutgigs.app.mjs"; + +export default { + key: "sproutgigs-post-job", + name: "Post Job", + description: "Post a new job to Sproutgigs. [See the documentation](https://sproutgigs.com/api/documentation.php#jobs-post)", + version: "0.0.1", + type: "action", + props: { + app, + test: { + propDefinition: [ + app, + "test", + ], + }, + zoneId: { + propDefinition: [ + app, + "zoneId", + ], + }, + categoryId: { + propDefinition: [ + app, + "categoryId", + ], + }, + title: { + propDefinition: [ + app, + "title", + ], + }, + instructions: { + propDefinition: [ + app, + "instructions", + ], + }, + proofs: { + propDefinition: [ + app, + "proofs", + ], + }, + numTasks: { + propDefinition: [ + app, + "numTasks", + ], + }, + taskValue: { + propDefinition: [ + app, + "taskValue", + ], + }, + }, + async run({ $ }) { + const response = await this.app.postJob({ + $, + data: { + test: this.test + ? 1 + : 0, + zone_id: this.zoneId, + category_id: this.categoryId, + title: this.title, + instructions: this.instructions, + proofs: JSON.parse(this.proofs), + num_tasks: this.numTasks, + task_value: this.taskValue, + }, + }); + + if (response.ok === false) { + throw new Error(`Job creation failed: ${response.message}`); + } + + $.export("$summary", "Successfully sent the request. Result message: " + response.message); + return response; + }, +}; diff --git a/components/sproutgigs/package.json b/components/sproutgigs/package.json index 05acb878ce262..c268367ea673d 100644 --- a/components/sproutgigs/package.json +++ b/components/sproutgigs/package.json @@ -1,15 +1,18 @@ { "name": "@pipedream/sproutgigs", - "version": "0.0.1", + "version": "0.1.0", "description": "Pipedream SproutGigs Components", "main": "sproutgigs.app.mjs", "keywords": [ "pipedream", "sproutgigs" ], - "homepage": "https://pipedream.com/apps/sproutgigs", "author": "Pipedream (https://pipedream.com/)", + "homepage": "https://pipedream.com/apps/sproutgigs", "publishConfig": { "access": "public" + }, + "dependencies": { + "@pipedream/platform": "^3.1.0" } } diff --git a/components/sproutgigs/sproutgigs.app.mjs b/components/sproutgigs/sproutgigs.app.mjs index aececcb59ce0c..ff81807149567 100644 --- a/components/sproutgigs/sproutgigs.app.mjs +++ b/components/sproutgigs/sproutgigs.app.mjs @@ -1,11 +1,108 @@ +import { axios } from "@pipedream/platform"; + export default { type: "app", app: "sproutgigs", - propDefinitions: {}, + propDefinitions: { + test: { + type: "boolean", + label: "Test", + description: "Enable development mode, the job will not be created", + optional: true, + }, + zoneId: { + type: "string", + label: "Zone ID", + description: "Zone ID for the job", + async options() { + const response = await this.getZones(); + return response.map(({ + id, zone, + }) => ({ + value: id, + label: zone, + })); + }, + }, + categoryId: { + type: "string", + label: "Category ID", + description: "Category ID for the job", + async options() { + const response = await this.getCategories(); + return response.map(({ + id, subcategory, + }) => ({ + value: id, + label: subcategory, + })); + }, + }, + title: { + type: "string", + label: "Title", + description: "Job title", + }, + instructions: { + type: "string[]", + label: "Instructions", + description: "List of expected work steps", + }, + proofs: { + type: "string", + label: "Proofs", + description: "Array of up to 4 proofs, each with description and type (text or screenshot), i.e.: `[{\"description\":\"Profile screenshot\",\"type\":\"screenshot\"}]`", + }, + numTasks: { + type: "integer", + label: "Number of Tasks", + description: "Number of tasks to be performed", + }, + taskValue: { + type: "string", + label: "Task Value", + description: "Amount paid per task", + }, + }, methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); + _baseUrl() { + return "https://sproutgigs.com/api"; + }, + async _makeRequest(opts = {}) { + const { + $ = this, + path, + auth, + ...otherOpts + } = opts; + return axios($, { + ...otherOpts, + url: this._baseUrl() + path, + auth: { + username: `${this.$auth.user_id}`, + password: `${this.$auth.api_secret}`, + ...auth, + }, + }); + }, + async postJob(args = {}) { + return this._makeRequest({ + path: "/jobs/post-job.php", + method: "post", + ...args, + }); + }, + async getCategories(args = {}) { + return this._makeRequest({ + path: "/jobs/get-categories.php", + ...args, + }); + }, + async getZones(args = {}) { + return this._makeRequest({ + path: "/jobs/get-zones.php", + ...args, + }); }, }, -}; \ No newline at end of file +}; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 48fcea4d2c2ca..d8bf66f3775fa 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -13589,7 +13589,11 @@ importers: specifier: ^2.29.4 version: 2.30.1 - components/sproutgigs: {} + components/sproutgigs: + dependencies: + '@pipedream/platform': + specifier: ^3.1.0 + version: 3.1.0 components/spydra: {} @@ -15944,8 +15948,7 @@ importers: specifier: ^3.0.3 version: 3.0.3 - components/xano_metadata_api: - specifiers: {} + components/xano_metadata_api: {} components/xata: dependencies: @@ -38581,6 +38584,8 @@ snapshots: '@putout/operator-filesystem': 5.0.0(putout@36.13.1(eslint@8.57.1)(typescript@5.6.3)) '@putout/operator-json': 2.2.0 putout: 36.13.1(eslint@8.57.1)(typescript@5.6.3) + transitivePeerDependencies: + - supports-color '@putout/operator-regexp@1.0.0(putout@36.13.1(eslint@8.57.1)(typescript@5.6.3))': dependencies: