diff --git a/components/grabpenny/actions/create-campaign/create-campaign.mjs b/components/grabpenny/actions/create-campaign/create-campaign.mjs new file mode 100644 index 0000000000000..e0c7f5b470219 --- /dev/null +++ b/components/grabpenny/actions/create-campaign/create-campaign.mjs @@ -0,0 +1,72 @@ +import grabpenny from "../../grabpenny.app.mjs"; + +export default { + key: "grabpenny-create-campaign", + name: "Create Campaign", + description: "Creates a new campaign in GrabPenny. [See the documentation](https://grabpenny.com/api-docs/)", + version: "0.0.1", + type: "action", + annotations: { + destructiveHint: false, + openWorldHint: true, + readOnlyHint: false, + }, + props: { + grabpenny, + taskTypeId: { + propDefinition: [ + grabpenny, + "taskTypeId", + ], + }, + name: { + type: "string", + label: "Name", + description: "Name of the campaign", + }, + link: { + type: "string", + label: "Link", + description: "URL to the social media profile/content", + }, + requiredExecutions: { + type: "integer", + label: "Required Executions", + description: "Number of engagements required (min: 10)", + min: 10, + }, + maxPerDay: { + type: "integer", + label: "Max Per Day", + description: "Maximum engagements per day (0 = unlimited)", + optional: true, + }, + miscData: { + type: "object", + label: "Misc Data", + description: "Additional campaign data", + optional: true, + }, + }, + async run({ $ }) { + const response = await this.grabpenny.createCampaign({ + $, + data: { + task_type_id: this.taskTypeId, + name: this.name, + link: this.link, + required_executions: this.requiredExecutions, + max_per_day: this.maxPerDay, + misc_data: this.miscData + ? typeof this.miscData === "string" + ? JSON.parse(this.miscData) + : this.miscData + : undefined, + }, + }); + if (response?.campaign?.id) { + $.export("$summary", `Successfully created campaign with ID \`${response.campaign.id}\`.`); + } + return response; + }, +}; diff --git a/components/grabpenny/grabpenny.app.mjs b/components/grabpenny/grabpenny.app.mjs index 3d3ce73e8a427..29d54095e323a 100644 --- a/components/grabpenny/grabpenny.app.mjs +++ b/components/grabpenny/grabpenny.app.mjs @@ -1,11 +1,56 @@ +import { axios } from "@pipedream/platform"; + export default { type: "app", app: "grabpenny", - propDefinitions: {}, + propDefinitions: { + taskTypeId: { + type: "integer", + label: "Task Type ID", + description: "ID of the task type", + async options() { + const { tasks } = await this.listTaskTypes(); + return tasks.map((task) => ({ + label: task.name, + value: task.id, + })); + }, + }, + }, methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); + _baseUrl() { + return "https://grabpenny.com/api/v1"; + }, + async _makeRequest({ + $ = this, path, ...opts + }) { + try { + return await axios($, { + url: `${this._baseUrl()}${path}`, + headers: { + Authorization: `Bearer ${this.$auth.api_key}`, + }, + ...opts, + }); + } catch (e) { + if (e.response.status === 500) { + throw new Error("Error occurred. Please verify that your account balance is sufficient to perform this action."); + } + throw e; + } + }, + listTaskTypes(args = {}) { + return this._makeRequest({ + path: "/client/tasks/", + ...args, + }); + }, + createCampaign(args = {}) { + return this._makeRequest({ + path: "/client/campaigns/create/", + method: "POST", + ...args, + }); }, }, -}; \ No newline at end of file +}; diff --git a/components/grabpenny/package.json b/components/grabpenny/package.json index 0ec7ef79abac5..9a578a303cf7b 100644 --- a/components/grabpenny/package.json +++ b/components/grabpenny/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/grabpenny", - "version": "0.0.1", + "version": "0.1.0", "description": "Pipedream GrabPenny Components", "main": "grabpenny.app.mjs", "keywords": [ @@ -11,5 +11,8 @@ "author": "Pipedream (https://pipedream.com/)", "publishConfig": { "access": "public" + }, + "dependencies": { + "@pipedream/platform": "^3.1.0" } -} \ No newline at end of file +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 23ef95bb3a95d..3b66b9cc48e4a 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -2270,8 +2270,7 @@ importers: specifier: ^3.0.3 version: 3.0.3 - components/callhippo: - specifiers: {} + components/callhippo: {} components/callhub: dependencies: @@ -5194,8 +5193,7 @@ importers: components/florm: {} - components/flotiq: - specifiers: {} + components/flotiq: {} components/flowiseai: dependencies: @@ -6318,7 +6316,11 @@ importers: components/grab_your_reviews: {} - components/grabpenny: {} + components/grabpenny: + dependencies: + '@pipedream/platform': + specifier: ^3.1.0 + version: 3.1.0 components/graceblocks: {} @@ -31470,22 +31472,22 @@ packages: superagent@3.8.1: resolution: {integrity: sha512-VMBFLYgFuRdfeNQSMLbxGSLfmXL/xc+OO+BZp41Za/NRDBet/BNbkRJrYzCUu0u4GU0i/ml2dtT8b9qgkw9z6Q==} engines: {node: '>= 4.0'} - deprecated: Please upgrade to v9.0.0+ as we have fixed a public vulnerability with formidable dependency. Note that v9.0.0+ requires Node.js v14.18.0+. See https://github.com/ladjs/superagent/pull/1800 for insight. This project is supported and maintained by the team at Forward Email @ https://forwardemail.net + deprecated: Please upgrade to superagent v10.2.2+, see release notes at https://github.com/forwardemail/superagent/releases/tag/v10.2.2 - maintenance is supported by Forward Email @ https://forwardemail.net superagent@4.1.0: resolution: {integrity: sha512-FT3QLMasz0YyCd4uIi5HNe+3t/onxMyEho7C3PSqmti3Twgy2rXT4fmkTz6wRL6bTF4uzPcfkUCa8u4JWHw8Ag==} engines: {node: '>= 6.0'} - deprecated: Please upgrade to v9.0.0+ as we have fixed a public vulnerability with formidable dependency. Note that v9.0.0+ requires Node.js v14.18.0+. See https://github.com/ladjs/superagent/pull/1800 for insight. This project is supported and maintained by the team at Forward Email @ https://forwardemail.net + deprecated: Please upgrade to superagent v10.2.2+, see release notes at https://github.com/forwardemail/superagent/releases/tag/v10.2.2 - maintenance is supported by Forward Email @ https://forwardemail.net superagent@5.3.1: resolution: {integrity: sha512-wjJ/MoTid2/RuGCOFtlacyGNxN9QLMgcpYLDQlWFIhhdJ93kNscFonGvrpAHSCVjRVj++DGCglocF7Aej1KHvQ==} engines: {node: '>= 7.0.0'} - deprecated: Please upgrade to v9.0.0+ as we have fixed a public vulnerability with formidable dependency. Note that v9.0.0+ requires Node.js v14.18.0+. See https://github.com/ladjs/superagent/pull/1800 for insight. This project is supported and maintained by the team at Forward Email @ https://forwardemail.net + deprecated: Please upgrade to superagent v10.2.2+, see release notes at https://github.com/forwardemail/superagent/releases/tag/v10.2.2 - maintenance is supported by Forward Email @ https://forwardemail.net superagent@7.1.6: resolution: {integrity: sha512-gZkVCQR1gy/oUXr+kxJMLDjla434KmSOKbx5iGD30Ql+AkJQ/YlPKECJy2nhqOsHLjGHzoDTXNSjhnvWhzKk7g==} engines: {node: '>=6.4.0 <13 || >=14'} - deprecated: Please upgrade to v9.0.0+ as we have fixed a public vulnerability with formidable dependency. Note that v9.0.0+ requires Node.js v14.18.0+. See https://github.com/ladjs/superagent/pull/1800 for insight. This project is supported and maintained by the team at Forward Email @ https://forwardemail.net + deprecated: Please upgrade to superagent v10.2.2+, see release notes at https://github.com/forwardemail/superagent/releases/tag/v10.2.2 - maintenance is supported by Forward Email @ https://forwardemail.net supports-color@10.0.0: resolution: {integrity: sha512-HRVVSbCCMbj7/kdWF9Q+bbckjBHLtHMEoJWlkmYzzdwhYMkjkOwubLM6t7NbWKjgKamGDrWL1++KrjUO1t9oAQ==}