Skip to content

Commit a556608

Browse files
authored
Merging pull request #18886
* create-campaign action * pnpm-lock.yaml
1 parent bdf4926 commit a556608

File tree

4 files changed

+138
-16
lines changed

4 files changed

+138
-16
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import grabpenny from "../../grabpenny.app.mjs";
2+
3+
export default {
4+
key: "grabpenny-create-campaign",
5+
name: "Create Campaign",
6+
description: "Creates a new campaign in GrabPenny. [See the documentation](https://grabpenny.com/api-docs/)",
7+
version: "0.0.1",
8+
type: "action",
9+
annotations: {
10+
destructiveHint: false,
11+
openWorldHint: true,
12+
readOnlyHint: false,
13+
},
14+
props: {
15+
grabpenny,
16+
taskTypeId: {
17+
propDefinition: [
18+
grabpenny,
19+
"taskTypeId",
20+
],
21+
},
22+
name: {
23+
type: "string",
24+
label: "Name",
25+
description: "Name of the campaign",
26+
},
27+
link: {
28+
type: "string",
29+
label: "Link",
30+
description: "URL to the social media profile/content",
31+
},
32+
requiredExecutions: {
33+
type: "integer",
34+
label: "Required Executions",
35+
description: "Number of engagements required (min: 10)",
36+
min: 10,
37+
},
38+
maxPerDay: {
39+
type: "integer",
40+
label: "Max Per Day",
41+
description: "Maximum engagements per day (0 = unlimited)",
42+
optional: true,
43+
},
44+
miscData: {
45+
type: "object",
46+
label: "Misc Data",
47+
description: "Additional campaign data",
48+
optional: true,
49+
},
50+
},
51+
async run({ $ }) {
52+
const response = await this.grabpenny.createCampaign({
53+
$,
54+
data: {
55+
task_type_id: this.taskTypeId,
56+
name: this.name,
57+
link: this.link,
58+
required_executions: this.requiredExecutions,
59+
max_per_day: this.maxPerDay,
60+
misc_data: this.miscData
61+
? typeof this.miscData === "string"
62+
? JSON.parse(this.miscData)
63+
: this.miscData
64+
: undefined,
65+
},
66+
});
67+
if (response?.campaign?.id) {
68+
$.export("$summary", `Successfully created campaign with ID \`${response.campaign.id}\`.`);
69+
}
70+
return response;
71+
},
72+
};
Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,56 @@
1+
import { axios } from "@pipedream/platform";
2+
13
export default {
24
type: "app",
35
app: "grabpenny",
4-
propDefinitions: {},
6+
propDefinitions: {
7+
taskTypeId: {
8+
type: "integer",
9+
label: "Task Type ID",
10+
description: "ID of the task type",
11+
async options() {
12+
const { tasks } = await this.listTaskTypes();
13+
return tasks.map((task) => ({
14+
label: task.name,
15+
value: task.id,
16+
}));
17+
},
18+
},
19+
},
520
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
21+
_baseUrl() {
22+
return "https://grabpenny.com/api/v1";
23+
},
24+
async _makeRequest({
25+
$ = this, path, ...opts
26+
}) {
27+
try {
28+
return await axios($, {
29+
url: `${this._baseUrl()}${path}`,
30+
headers: {
31+
Authorization: `Bearer ${this.$auth.api_key}`,
32+
},
33+
...opts,
34+
});
35+
} catch (e) {
36+
if (e.response.status === 500) {
37+
throw new Error("Error occurred. Please verify that your account balance is sufficient to perform this action.");
38+
}
39+
throw e;
40+
}
41+
},
42+
listTaskTypes(args = {}) {
43+
return this._makeRequest({
44+
path: "/client/tasks/",
45+
...args,
46+
});
47+
},
48+
createCampaign(args = {}) {
49+
return this._makeRequest({
50+
path: "/client/campaigns/create/",
51+
method: "POST",
52+
...args,
53+
});
954
},
1055
},
11-
};
56+
};

components/grabpenny/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/grabpenny",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Pipedream GrabPenny Components",
55
"main": "grabpenny.app.mjs",
66
"keywords": [
@@ -11,5 +11,8 @@
1111
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
1212
"publishConfig": {
1313
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "^3.1.0"
1417
}
15-
}
18+
}

pnpm-lock.yaml

Lines changed: 11 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)