Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions components/grabpenny/actions/create-campaign/create-campaign.mjs
Original file line number Diff line number Diff line change
@@ -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;
},
};
55 changes: 50 additions & 5 deletions components/grabpenny/grabpenny.app.mjs
Original file line number Diff line number Diff line change
@@ -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,
});
},
},
};
};
7 changes: 5 additions & 2 deletions components/grabpenny/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/grabpenny",
"version": "0.0.1",
"version": "0.1.0",
"description": "Pipedream GrabPenny Components",
"main": "grabpenny.app.mjs",
"keywords": [
Expand All @@ -11,5 +11,8 @@
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^3.1.0"
}
}
}
20 changes: 11 additions & 9 deletions pnpm-lock.yaml

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

Loading